Merge lp:~chipaca/ubuntu-push/endpoint-not-bus into lp:ubuntu-push

Proposed by John Lenton
Status: Superseded
Proposed branch: lp:~chipaca/ubuntu-push/endpoint-not-bus
Merge into: lp:ubuntu-push
Diff against target: 616 lines (+205/-111)
14 files modified
.precommit (+29/-0)
bus/connectivity/connectivity.go (+2/-3)
bus/connectivity/connectivity_test.go (+1/-20)
bus/connectivity/example/main.go (+2/-2)
bus/connectivity/webchecker.go (+3/-3)
bus/connectivity/webchecker_test.go (+6/-10)
bus/endpoint.go (+4/-11)
bus/networkmanager/networkmanager_test.go (+9/-2)
bus/notifications/raw.go (+9/-10)
bus/notifications/raw_test.go (+17/-24)
bus/testing/testing_endpoint.go (+11/-7)
bus/testing/testing_endpoint_test.go (+6/-19)
bus/urldispatcher/urldispatcher.go (+57/-0)
bus/urldispatcher/urldispatcher_test.go (+49/-0)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/endpoint-not-bus
Reviewer Review Type Date Requested Status
Ubuntu Push Hackers Pending
Review via email: mp+202869@code.launchpad.net

This proposal has been superseded by a proposal from 2014-01-24.

Commit message

change a few of the bus/* services to take a bus.Endpoint instead of a bus.Bus

Description of the change

change a few of the bus/* services to take a bus.Endpoint instead of a bus.Bus

To post a comment you must log in.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file '.precommit'
--- .precommit 1970-01-01 00:00:00 +0000
+++ .precommit 2014-01-23 14:29:00 +0000
@@ -0,0 +1,29 @@
1#!/bin/sh
2set -e
3echo "$@"
4# put me in the project root, call me ".precommit".
5# And put this here-document in ~/.bazaar/plugins/precommit_script.py:
6<<EOF
7import os
8import subprocess
9from bzrlib.mutabletree import MutableTree
10from bzrlib import errors
11
12def start_commit_hook(*_):
13 """This hook will execute '.precommit' script from root path of the bazaar
14 branch. Commit will be canceled if precommit fails."""
15
16 # this hook only makes sense if a precommit file exist.
17 if not os.path.exists(".precommit"):
18 return
19 try:
20 subprocess.check_call(os.path.abspath(".precommit"))
21 # if precommit fails (process return not zero) cancel commit.
22 except subprocess.CalledProcessError:
23 raise errors.BzrError("pre commit check failed.")
24
25MutableTree.hooks.install_named_hook('start_commit', start_commit_hook,
26 'Run "precommit" script on start_commit')
27EOF
28
29make check-format # or whatever
030
=== renamed directory 'connectivity' => 'bus/connectivity'
=== modified file 'bus/connectivity/connectivity.go'
--- connectivity/connectivity.go 2014-01-20 17:44:24 +0000
+++ bus/connectivity/connectivity.go 2014-01-23 14:29:00 +0000
@@ -25,10 +25,9 @@
25import (25import (
26 "errors"26 "errors"
27 "launchpad.net/ubuntu-push/bus"27 "launchpad.net/ubuntu-push/bus"
28 "launchpad.net/ubuntu-push/bus/networkmanager"
28 "launchpad.net/ubuntu-push/config"29 "launchpad.net/ubuntu-push/config"
29 "launchpad.net/ubuntu-push/connectivity/webchecker"
30 "launchpad.net/ubuntu-push/logger"30 "launchpad.net/ubuntu-push/logger"
31 "launchpad.net/ubuntu-push/networkmanager"
32 "time"31 "time"
33)32)
3433
@@ -163,7 +162,7 @@
163// over the "out" channel. Sends "false" as soon as it detects trouble, "true"162// over the "out" channel. Sends "false" as soon as it detects trouble, "true"
164// after checking actual connectivity.163// after checking actual connectivity.
165func ConnectedState(busType bus.Bus, config Config, log logger.Logger, out chan<- bool) {164func ConnectedState(busType bus.Bus, config Config, log logger.Logger, out chan<- bool) {
166 wg := webchecker.New(config.ConnectivityCheckURL, config.ConnectivityCheckMD5, log)165 wg := NewWebchecker(config.ConnectivityCheckURL, config.ConnectivityCheckMD5, log)
167 cs := &connectedState{166 cs := &connectedState{
168 config: config,167 config: config,
169 log: log,168 log: log,
170169
=== modified file 'bus/connectivity/connectivity_test.go'
--- connectivity/connectivity_test.go 2014-01-22 12:27:35 +0000
+++ bus/connectivity/connectivity_test.go 2014-01-23 14:29:00 +0000
@@ -19,12 +19,11 @@
19import (19import (
20 "io/ioutil"20 "io/ioutil"
21 . "launchpad.net/gocheck"21 . "launchpad.net/gocheck"
22 "launchpad.net/ubuntu-push/bus/networkmanager"
22 testingbus "launchpad.net/ubuntu-push/bus/testing"23 testingbus "launchpad.net/ubuntu-push/bus/testing"
23 "launchpad.net/ubuntu-push/config"24 "launchpad.net/ubuntu-push/config"
24 "launchpad.net/ubuntu-push/logger"25 "launchpad.net/ubuntu-push/logger"
25 "launchpad.net/ubuntu-push/networkmanager"
26 "launchpad.net/ubuntu-push/testing/condition"26 "launchpad.net/ubuntu-push/testing/condition"
27 "net/http"
28 "net/http/httptest"27 "net/http/httptest"
29 "testing"28 "testing"
30 "time"29 "time"
@@ -201,24 +200,6 @@
201 tests for ConnectedState()200 tests for ConnectedState()
202*/201*/
203202
204// Todo: get rid of duplication between this and webchecker_test
205const (
206 staticText = "something ipsum dolor something"
207 staticHash = "6155f83b471583f47c99998a472a178f"
208)
209
210// mkHandler makes an http.HandlerFunc that returns the provided text
211// for whatever request it's given.
212func mkHandler(text string) http.HandlerFunc {
213 return func(w http.ResponseWriter, r *http.Request) {
214 w.(http.Flusher).Flush()
215 w.Write([]byte(text))
216 w.(http.Flusher).Flush()
217 }
218}
219
220// :oboT
221
222// yes, this is an integration test203// yes, this is an integration test
223func (s *ConnSuite) TestRun(c *C) {204func (s *ConnSuite) TestRun(c *C) {
224 ts := httptest.NewServer(mkHandler(staticText))205 ts := httptest.NewServer(mkHandler(staticText))
225206
=== modified file 'bus/connectivity/example/main.go'
--- connectivity/example/main.go 2014-01-20 06:27:39 +0000
+++ bus/connectivity/example/main.go 2014-01-23 14:29:00 +0000
@@ -20,8 +20,8 @@
20import (20import (
21 "fmt"21 "fmt"
22 "launchpad.net/ubuntu-push/bus"22 "launchpad.net/ubuntu-push/bus"
23 "launchpad.net/ubuntu-push/bus/connectivity"
23 "launchpad.net/ubuntu-push/config"24 "launchpad.net/ubuntu-push/config"
24 "launchpad.net/ubuntu-push/connectivity"
25 "launchpad.net/ubuntu-push/logger"25 "launchpad.net/ubuntu-push/logger"
26 "os"26 "os"
27 "strings"27 "strings"
@@ -30,7 +30,7 @@
30func main() {30func main() {
31 log := logger.NewSimpleLogger(os.Stderr, "error")31 log := logger.NewSimpleLogger(os.Stderr, "error")
3232
33 paths := []string{"thing.json", "connectivity/example/thing.json"}33 paths := []string{"thing.json", "bus/connectivity/example/thing.json"}
34 for _, path := range paths {34 for _, path := range paths {
35 cff, err := os.Open(path)35 cff, err := os.Open(path)
36 if err == nil {36 if err == nil {
3737
=== renamed file 'connectivity/webchecker/webchecker.go' => 'bus/connectivity/webchecker.go'
--- connectivity/webchecker/webchecker.go 2014-01-20 14:58:59 +0000
+++ bus/connectivity/webchecker.go 2014-01-23 14:29:00 +0000
@@ -14,13 +14,13 @@
14 with this program. If not, see <http://www.gnu.org/licenses/>.14 with this program. If not, see <http://www.gnu.org/licenses/>.
15*/15*/
1616
17// Package webchecker checks whether we're actually connected by doing an http17// webchecker checks whether we're actually connected by doing an http
18// GET to the Ubuntu connectivity check URL,18// GET to the Ubuntu connectivity check URL,
19// http://start.ubuntu.com/connectivity-check.html19// http://start.ubuntu.com/connectivity-check.html
20//20//
21// We could make it be https to make extra doubly sure, but it's expensive21// We could make it be https to make extra doubly sure, but it's expensive
22// overkill for the majority of cases.22// overkill for the majority of cases.
23package webchecker23package connectivity
2424
25import (25import (
26 "crypto/md5"26 "crypto/md5"
@@ -46,7 +46,7 @@
46}46}
4747
48// Build a webchecker for the given URL, that should match the target MD5.48// Build a webchecker for the given URL, that should match the target MD5.
49func New(url string, target string, log logger.Logger) Webchecker {49func NewWebchecker(url string, target string, log logger.Logger) Webchecker {
50 return &webchecker{log, url, target}50 return &webchecker{log, url, target}
51}51}
5252
5353
=== renamed file 'connectivity/webchecker/webchecker_test.go' => 'bus/connectivity/webchecker_test.go'
--- connectivity/webchecker/webchecker_test.go 2014-01-20 06:27:39 +0000
+++ bus/connectivity/webchecker_test.go 2014-01-23 14:29:00 +0000
@@ -14,26 +14,22 @@
14 with this program. If not, see <http://www.gnu.org/licenses/>.14 with this program. If not, see <http://www.gnu.org/licenses/>.
15*/15*/
1616
17package webchecker17package connectivity
1818
19import (19import (
20 "io/ioutil"
21 . "launchpad.net/gocheck"20 . "launchpad.net/gocheck"
22 "launchpad.net/ubuntu-push/logger"
23 "net/http"21 "net/http"
24 "net/http/httptest"22 "net/http/httptest"
25 "testing"23 "testing"
26)24)
2725
28// hook up gocheck26// hook up gocheck
29func Test(t *testing.T) { TestingT(t) }27func TestWebcheck(t *testing.T) { TestingT(t) }
3028
31type WebcheckerSuite struct{}29type WebcheckerSuite struct{}
3230
33var _ = Suite(&WebcheckerSuite{})31var _ = Suite(&WebcheckerSuite{})
3432
35var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
36
37const (33const (
38 staticText = "something ipsum dolor something"34 staticText = "something ipsum dolor something"
39 staticHash = "6155f83b471583f47c99998a472a178f"35 staticHash = "6155f83b471583f47c99998a472a178f"
@@ -69,7 +65,7 @@
69 ts := httptest.NewServer(mkHandler(staticText))65 ts := httptest.NewServer(mkHandler(staticText))
70 defer ts.Close()66 defer ts.Close()
7167
72 ck := New(ts.URL, staticHash, nullog)68 ck := NewWebchecker(ts.URL, staticHash, nullog)
73 ch := make(chan bool, 1)69 ch := make(chan bool, 1)
74 ck.Webcheck(ch)70 ck.Webcheck(ch)
75 c.Check(<-ch, Equals, true)71 c.Check(<-ch, Equals, true)
@@ -77,7 +73,7 @@
7773
78// Webchecker sends false if the download fails.74// Webchecker sends false if the download fails.
79func (s *WebcheckerSuite) TestActualFails(c *C) {75func (s *WebcheckerSuite) TestActualFails(c *C) {
80 ck := New("garbage://", "", nullog)76 ck := NewWebchecker("garbage://", "", nullog)
81 ch := make(chan bool, 1)77 ch := make(chan bool, 1)
82 ck.Webcheck(ch)78 ck.Webcheck(ch)
83 c.Check(<-ch, Equals, false)79 c.Check(<-ch, Equals, false)
@@ -88,7 +84,7 @@
88 ts := httptest.NewServer(mkHandler(""))84 ts := httptest.NewServer(mkHandler(""))
89 defer ts.Close()85 defer ts.Close()
9086
91 ck := New(ts.URL, staticHash, nullog)87 ck := NewWebchecker(ts.URL, staticHash, nullog)
92 ch := make(chan bool, 1)88 ch := make(chan bool, 1)
93 ck.Webcheck(ch)89 ck.Webcheck(ch)
94 c.Check(<-ch, Equals, false)90 c.Check(<-ch, Equals, false)
@@ -99,7 +95,7 @@
99 ts := httptest.NewServer(mkHandler(bigText))95 ts := httptest.NewServer(mkHandler(bigText))
100 defer ts.Close()96 defer ts.Close()
10197
102 ck := New(ts.URL, bigHash, nullog)98 ck := NewWebchecker(ts.URL, bigHash, nullog)
103 ch := make(chan bool, 1)99 ch := make(chan bool, 1)
104 ck.Webcheck(ch)100 ck.Webcheck(ch)
105 c.Check(<-ch, Equals, false)101 c.Check(<-ch, Equals, false)
106102
=== modified file 'bus/endpoint.go'
--- bus/endpoint.go 2014-01-22 10:48:52 +0000
+++ bus/endpoint.go 2014-01-23 14:29:00 +0000
@@ -31,7 +31,7 @@
31// bus.Endpoint represents the DBus connection itself.31// bus.Endpoint represents the DBus connection itself.
32type Endpoint interface {32type Endpoint interface {
33 WatchSignal(member string, f func(...interface{}), d func()) error33 WatchSignal(member string, f func(...interface{}), d func()) error
34 Call(member string, args ...interface{}) (interface{}, error)34 Call(member string, args ...interface{}) ([]interface{}, error)
35 GetProperty(property string) (interface{}, error)35 GetProperty(property string) (interface{}, error)
36 Close()36 Close()
37}37}
@@ -81,20 +81,13 @@
81// Call() invokes the provided member method (on the name, path and interface81// Call() invokes the provided member method (on the name, path and interface
82// provided when creating the endpoint). The return value is unpacked before82// provided when creating the endpoint). The return value is unpacked before
83// being returned.83// being returned.
84func (endp *endpoint) Call(member string, args ...interface{}) (interface{}, error) {84func (endp *endpoint) Call(member string, args ...interface{}) ([]interface{}, error) {
85 msg, err := endp.proxy.Call(endp.iface, member, args...)85 msg, err := endp.proxy.Call(endp.iface, member, args...)
86 if err != nil {86 if err != nil {
87 return 0, err87 return nil, err
88 }88 }
89 rvs := endp.unpackOneMsg(msg, member)89 rvs := endp.unpackOneMsg(msg, member)
90 switch len(rvs) {90 return rvs, nil
91 default:
92 return 0, fmt.Errorf("Too many values in %s response: %d", member, len(rvs))
93 case 0:
94 return 0, fmt.Errorf("Not enough values in %s response: %d", member, len(rvs))
95 case 1:
96 return rvs[0], nil
97 }
98}91}
9992
100// GetProperty uses the org.freedesktop.DBus.Properties interface's Get method93// GetProperty uses the org.freedesktop.DBus.Properties interface's Get method
10194
=== renamed directory 'networkmanager' => 'bus/networkmanager'
=== modified file 'bus/networkmanager/networkmanager_test.go'
--- networkmanager/networkmanager_test.go 2014-01-20 13:44:58 +0000
+++ bus/networkmanager/networkmanager_test.go 2014-01-23 14:29:00 +0000
@@ -65,13 +65,20 @@
65 c.Check(state, Equals, Unknown)65 c.Check(state, Equals, Unknown)
66}66}
6767
68// GetState returns the right state when dbus works but delivers rubbish68// GetState returns the right state when dbus works but delivers rubbish values
69func (s *NMSuite) TestGetStateRubbish(c *C) {69func (s *NMSuite) TestGetStateRubbishValues(c *C) {
70 nm := New(testingbus.NewTestingEndpoint(condition.Work(false), 42), nullog)70 nm := New(testingbus.NewTestingEndpoint(condition.Work(false), 42), nullog)
71 state := nm.GetState()71 state := nm.GetState()
72 c.Check(state, Equals, Unknown)72 c.Check(state, Equals, Unknown)
73}73}
7474
75// GetState returns the right state when dbus works but delivers a rubbish structure
76func (s *NMSuite) TestGetStateRubbishStructure(c *C) {
77 nm := New(testingbus.NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{}), nullog)
78 state := nm.GetState()
79 c.Check(state, Equals, Unknown)
80}
81
75// WatchState sends a stream of States over the channel82// WatchState sends a stream of States over the channel
76func (s *NMSuite) TestWatchState(c *C) {83func (s *NMSuite) TestWatchState(c *C) {
77 tc := testingbus.NewTestingEndpoint(condition.Work(true), uint32(Unknown), uint32(Asleep), uint32(ConnectedGlobal))84 tc := testingbus.NewTestingEndpoint(condition.Work(true), uint32(Unknown), uint32(Asleep), uint32(ConnectedGlobal))
7885
=== renamed directory 'notifications' => 'bus/notifications'
=== modified file 'bus/notifications/raw.go'
--- notifications/raw.go 2014-01-22 12:15:12 +0000
+++ bus/notifications/raw.go 2014-01-23 14:29:00 +0000
@@ -22,6 +22,7 @@
22// this is the lower-level api22// this is the lower-level api
2323
24import (24import (
25 "errors"
25 "launchpad.net/go-dbus/v1"26 "launchpad.net/go-dbus/v1"
26 "launchpad.net/ubuntu-push/bus"27 "launchpad.net/ubuntu-push/bus"
27 "launchpad.net/ubuntu-push/logger"28 "launchpad.net/ubuntu-push/logger"
@@ -51,14 +52,9 @@
51 log logger.Logger52 log logger.Logger
52}53}
5354
54// Raw returns a new RawNotifications connected to the provided bus.Bus55// Raw returns a new RawNotifications that'll use the provided bus.Endpoint
55func Raw(bt bus.Bus, log logger.Logger) (*RawNotifications, error) {56func Raw(endp bus.Endpoint, log logger.Logger) *RawNotifications {
56 endp, err := bt.Connect(BusAddress, log)57 return &RawNotifications{endp, log}
57 if err != nil {
58 return nil, err
59 }
60
61 return &RawNotifications{endp, log}, nil
62}58}
6359
64/*60/*
@@ -73,12 +69,15 @@
73 timeout int32) (uint32, error) {69 timeout int32) (uint32, error) {
74 // that's a long argument list! Take a breather.70 // that's a long argument list! Take a breather.
75 //71 //
76 rv, err := raw.bus.Call("Notify", app_name, reuse_id, icon,72 rvs, err := raw.bus.Call("Notify", app_name, reuse_id, icon,
77 summary, body, actions, hints, timeout)73 summary, body, actions, hints, timeout)
78 if err != nil {74 if err != nil {
79 return 0, err75 return 0, err
80 }76 }
81 return rv.(uint32), nil77 if len(rvs) != 1 {
78 return 0, errors.New("Wrong number of arguments in reply from Notify")
79 }
80 return rvs[0].(uint32), nil
82}81}
8382
84// WatchActions listens for ActionInvoked signals from the notification daemon83// WatchActions listens for ActionInvoked signals from the notification daemon
8584
=== modified file 'bus/notifications/raw_test.go'
--- notifications/raw_test.go 2014-01-21 14:58:28 +0000
+++ bus/notifications/raw_test.go 2014-01-23 14:29:00 +0000
@@ -38,38 +38,32 @@
3838
39var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")39var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
4040
41func (s *RawSuite) TestConnects(c *C) {
42 bus := testibus.NewTestingBus(condition.Work(false), condition.Work(false))
43 _, err := Raw(bus, nullog)
44 c.Check(err, NotNil)
45 bus = testibus.NewTestingBus(condition.Work(true), condition.Work(false))
46 _, err = Raw(bus, nullog)
47 c.Check(err, IsNil)
48}
49
50func (s *RawSuite) TestNotifies(c *C) {41func (s *RawSuite) TestNotifies(c *C) {
51 bus := testibus.NewTestingBus(condition.Work(true), condition.Work(true),42 endp := testibus.NewTestingEndpoint(condition.Work(true), uint32(1))
52 uint32(1))43 raw := Raw(endp, nullog)
53 raw, err := Raw(bus, nullog)
54 c.Assert(err, IsNil)
55 nid, err := raw.Notify("", 0, "", "", "", nil, nil, 0)44 nid, err := raw.Notify("", 0, "", "", "", nil, nil, 0)
56 c.Check(err, IsNil)45 c.Check(err, IsNil)
57 c.Check(nid, Equals, uint32(1))46 c.Check(nid, Equals, uint32(1))
58}47}
5948
60func (s *RawSuite) TestNotifiesFails(c *C) {49func (s *RawSuite) TestNotifiesFails(c *C) {
61 bus := testibus.NewTestingBus(condition.Work(true), condition.Work(false))50 endp := testibus.NewTestingEndpoint(condition.Work(false))
62 raw, err := Raw(bus, nullog)51 raw := Raw(endp, nullog)
63 c.Assert(err, IsNil)52 _, err := raw.Notify("", 0, "", "", "", nil, nil, 0)
64 _, err = raw.Notify("", 0, "", "", "", nil, nil, 0)53 c.Check(err, NotNil)
54}
55
56func (s *RawSuite) TestNotifiesFailsWeirdly(c *C) {
57 endp := testibus.NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{1, 2})
58 raw := Raw(endp, nullog)
59 _, err := raw.Notify("", 0, "", "", "", nil, nil, 0)
65 c.Check(err, NotNil)60 c.Check(err, NotNil)
66}61}
6762
68func (s *RawSuite) TestWatchActions(c *C) {63func (s *RawSuite) TestWatchActions(c *C) {
69 bus := testibus.NewMultiValuedTestingBus(condition.Work(true), condition.Work(true),64 endp := testibus.NewMultiValuedTestingEndpoint(condition.Work(true),
70 []interface{}{uint32(1), "hello"})65 []interface{}{uint32(1), "hello"})
71 raw, err := Raw(bus, nullog)66 raw := Raw(endp, nullog)
72 c.Assert(err, IsNil)
73 ch, err := raw.WatchActions()67 ch, err := raw.WatchActions()
74 c.Assert(err, IsNil)68 c.Assert(err, IsNil)
75 // check we get the right action reply69 // check we get the right action reply
@@ -86,9 +80,8 @@
86}80}
8781
88func (s *RawSuite) TestWatchActionsFails(c *C) {82func (s *RawSuite) TestWatchActionsFails(c *C) {
89 bus := testibus.NewTestingBus(condition.Work(true), condition.Work(false))83 endp := testibus.NewTestingEndpoint(condition.Work(false))
90 raw, err := Raw(bus, nullog)84 raw := Raw(endp, nullog)
91 c.Assert(err, IsNil)85 _, err := raw.WatchActions()
92 _, err = raw.WatchActions()
93 c.Check(err, NotNil)86 c.Check(err, NotNil)
94}87}
9588
=== modified file 'bus/testing/testing_endpoint.go'
--- bus/testing/testing_endpoint.go 2014-01-22 10:48:52 +0000
+++ bus/testing/testing_endpoint.go 2014-01-23 14:29:00 +0000
@@ -66,23 +66,27 @@
6666
67// See Endpoint's Call. This Call will check its condition to decide whether67// See Endpoint's Call. This Call will check its condition to decide whether
68// to return an error, or the first of its return values68// to return an error, or the first of its return values
69func (tc *testingEndpoint) Call(member string, args ...interface{}) (interface{}, error) {69func (tc *testingEndpoint) Call(member string, args ...interface{}) ([]interface{}, error) {
70 if tc.cond.OK() {70 if tc.cond.OK() {
71 if len(tc.retvals) == 0 {71 if len(tc.retvals) == 0 {
72 panic("No return values provided!")72 panic("No return values provided!")
73 }73 }
74 if len(tc.retvals[0]) != 1 {74 return tc.retvals[0], nil
75 panic("Wrong number of values provided -- Call only returns a single value for now!")
76 }
77 return tc.retvals[0][0], nil
78 } else {75 } else {
79 return 0, errors.New("no way")76 return nil, errors.New("no way")
80 }77 }
81}78}
8279
83// See Endpoint's GetProperty. This one is just another name for Call.80// See Endpoint's GetProperty. This one is just another name for Call.
84func (tc *testingEndpoint) GetProperty(property string) (interface{}, error) {81func (tc *testingEndpoint) GetProperty(property string) (interface{}, error) {
85 return tc.Call(property)82 rvs, err := tc.Call(property)
83 if err != nil {
84 return nil, err
85 }
86 if len(rvs) != 1 {
87 return nil, errors.New("Wrong number of arguments in reply to GetProperty")
88 }
89 return rvs[0], err
86}90}
8791
88// see Endpoint's Close. This one does nothing.92// see Endpoint's Close. This one does nothing.
8993
=== modified file 'bus/testing/testing_endpoint_test.go'
--- bus/testing/testing_endpoint_test.go 2014-01-21 13:38:03 +0000
+++ bus/testing/testing_endpoint_test.go 2014-01-23 14:29:00 +0000
@@ -34,18 +34,20 @@
34func (s *TestingEndpointSuite) TestCallReturnsFirstRetval(c *C) {34func (s *TestingEndpointSuite) TestCallReturnsFirstRetval(c *C) {
35 var m, n uint32 = 42, 1735 var m, n uint32 = 42, 17
36 endp := NewTestingEndpoint(condition.Work(true), m, n)36 endp := NewTestingEndpoint(condition.Work(true), m, n)
37 v, e := endp.Call("what")37 vs, e := endp.Call("what")
38 c.Check(e, IsNil)38 c.Check(e, IsNil)
39 c.Check(v, Equals, m)39 c.Check(vs, HasLen, 1)
40 c.Check(vs[0], Equals, m)
40}41}
4142
42// Test the same Call() but with multi-valued endpoint43// Test the same Call() but with multi-valued endpoint
43func (s *TestingEndpointSuite) TestMultiValuedCall(c *C) {44func (s *TestingEndpointSuite) TestMultiValuedCall(c *C) {
44 var m, n uint32 = 42, 1745 var m, n uint32 = 42, 17
45 endp := NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{m}, []interface{}{n})46 endp := NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{m}, []interface{}{n})
46 v, e := endp.Call("what")47 vs, e := endp.Call("what")
47 c.Check(e, IsNil)48 c.Check(e, IsNil)
48 c.Check(v, Equals, m)49 c.Check(vs, HasLen, 1)
50 c.Check(vs[0], Equals, m)
49}51}
5052
51// Test that Call() with a negative condition returns an error.53// Test that Call() with a negative condition returns an error.
@@ -62,21 +64,6 @@
62 c.Check(func() { endp.Call("") }, PanicMatches, "No return values provided.*")64 c.Check(func() { endp.Call("") }, PanicMatches, "No return values provided.*")
63}65}
6466
65// Test that Call() with a positive condition and an empty return value panics
66// with a helpful message.
67func (s *TestingEndpointSuite) TestCallPanicsWithNiceMessage2(c *C) {
68 endp := NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{})
69 c.Check(func() { endp.Call("") }, PanicMatches, "Wrong number of values provided.*")
70}
71
72// Test Call() with positive condition and the wrong number of arguments also
73// fails with a helpful message
74func (s *TestingEndpointSuite) TestMultiValuedCallPanicsWhenWrongNumberOfValues(c *C) {
75 var m, n uint32 = 42, 17
76 endp := NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{m, n})
77 c.Check(func() { endp.Call("") }, PanicMatches, "Wrong number of values provided.*")
78}
79
80// Test that WatchSignal() with a positive condition sends the provided return67// Test that WatchSignal() with a positive condition sends the provided return
81// values over the channel.68// values over the channel.
82func (s *TestingEndpointSuite) TestWatch(c *C) {69func (s *TestingEndpointSuite) TestWatch(c *C) {
8370
=== added directory 'bus/urldispatcher'
=== added file 'bus/urldispatcher/urldispatcher.go'
--- bus/urldispatcher/urldispatcher.go 1970-01-01 00:00:00 +0000
+++ bus/urldispatcher/urldispatcher.go 2014-01-23 14:29:00 +0000
@@ -0,0 +1,57 @@
1/*
2 Copyright 2013-2014 Canonical Ltd.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published
6 by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranties of
10 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program. If not, see <http://www.gnu.org/licenses/>.
15*/
16
17// Package urldispatcher wraps the url dispatcher's dbus api point
18package urldispatcher
19
20import (
21 "launchpad.net/ubuntu-push/bus"
22 "launchpad.net/ubuntu-push/logger"
23)
24
25// UrlDispatcher lives on a well-known bus.Address
26var BusAddress bus.Address = bus.Address{
27 Interface: "com.canonical.URLDispatcher",
28 Path: "/com/canonical/URLDispatcher",
29 Name: "com.canonical.URLDispatcher",
30}
31
32// A URLDispatcher is a simple beast, with a single method that does what it
33// says on the box.
34type URLDispatcher interface {
35 DispatchURL(string) error
36}
37
38type urlDispatcher struct {
39 endp bus.Endpoint
40 log logger.Logger
41}
42
43// New builds a new URL dispatcher that uses the provided bus.Endpoint
44func New(endp bus.Endpoint, log logger.Logger) URLDispatcher {
45 return &urlDispatcher{endp, log}
46}
47
48var _ URLDispatcher = &urlDispatcher{} // ensures it conforms
49
50func (ud *urlDispatcher) DispatchURL(url string) error {
51 ud.log.Debugf("Dispatching %s", url)
52 _, err := ud.endp.Call("DispatchURL", url)
53 if err != nil {
54 ud.log.Errorf("Dispatch to %s failed with %s", url, err)
55 }
56 return err
57}
058
=== added file 'bus/urldispatcher/urldispatcher_test.go'
--- bus/urldispatcher/urldispatcher_test.go 1970-01-01 00:00:00 +0000
+++ bus/urldispatcher/urldispatcher_test.go 2014-01-23 14:29:00 +0000
@@ -0,0 +1,49 @@
1/*
2 Copyright 2013-2014 Canonical Ltd.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published
6 by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranties of
10 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program. If not, see <http://www.gnu.org/licenses/>.
15*/
16
17package urldispatcher
18
19import (
20 "io/ioutil"
21 . "launchpad.net/gocheck"
22 testibus "launchpad.net/ubuntu-push/bus/testing"
23 "launchpad.net/ubuntu-push/logger"
24 "launchpad.net/ubuntu-push/testing/condition"
25 "testing"
26)
27
28// hook up gocheck
29func TestUrldispatcher(t *testing.T) { TestingT(t) }
30
31type UDSuite struct{}
32
33var _ = Suite(&UDSuite{})
34
35var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
36
37func (s *UDSuite) TestWorks(c *C) {
38 endp := testibus.NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{})
39 ud := New(endp, nullog)
40 err := ud.DispatchURL("this")
41 c.Check(err, IsNil)
42}
43
44func (s *UDSuite) TestFailsIfCallFails(c *C) {
45 endp := testibus.NewTestingEndpoint(condition.Work(false))
46 ud := New(endp, nullog)
47 err := ud.DispatchURL("this")
48 c.Check(err, NotNil)
49}
050
=== removed directory 'connectivity/webchecker'

Subscribers

People subscribed via source and target branches