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
1=== added file '.precommit'
2--- .precommit 1970-01-01 00:00:00 +0000
3+++ .precommit 2014-01-23 14:29:00 +0000
4@@ -0,0 +1,29 @@
5+#!/bin/sh
6+set -e
7+echo "$@"
8+# put me in the project root, call me ".precommit".
9+# And put this here-document in ~/.bazaar/plugins/precommit_script.py:
10+<<EOF
11+import os
12+import subprocess
13+from bzrlib.mutabletree import MutableTree
14+from bzrlib import errors
15+
16+def start_commit_hook(*_):
17+ """This hook will execute '.precommit' script from root path of the bazaar
18+ branch. Commit will be canceled if precommit fails."""
19+
20+ # this hook only makes sense if a precommit file exist.
21+ if not os.path.exists(".precommit"):
22+ return
23+ try:
24+ subprocess.check_call(os.path.abspath(".precommit"))
25+ # if precommit fails (process return not zero) cancel commit.
26+ except subprocess.CalledProcessError:
27+ raise errors.BzrError("pre commit check failed.")
28+
29+MutableTree.hooks.install_named_hook('start_commit', start_commit_hook,
30+ 'Run "precommit" script on start_commit')
31+EOF
32+
33+make check-format # or whatever
34
35=== renamed directory 'connectivity' => 'bus/connectivity'
36=== modified file 'bus/connectivity/connectivity.go'
37--- connectivity/connectivity.go 2014-01-20 17:44:24 +0000
38+++ bus/connectivity/connectivity.go 2014-01-23 14:29:00 +0000
39@@ -25,10 +25,9 @@
40 import (
41 "errors"
42 "launchpad.net/ubuntu-push/bus"
43+ "launchpad.net/ubuntu-push/bus/networkmanager"
44 "launchpad.net/ubuntu-push/config"
45- "launchpad.net/ubuntu-push/connectivity/webchecker"
46 "launchpad.net/ubuntu-push/logger"
47- "launchpad.net/ubuntu-push/networkmanager"
48 "time"
49 )
50
51@@ -163,7 +162,7 @@
52 // over the "out" channel. Sends "false" as soon as it detects trouble, "true"
53 // after checking actual connectivity.
54 func ConnectedState(busType bus.Bus, config Config, log logger.Logger, out chan<- bool) {
55- wg := webchecker.New(config.ConnectivityCheckURL, config.ConnectivityCheckMD5, log)
56+ wg := NewWebchecker(config.ConnectivityCheckURL, config.ConnectivityCheckMD5, log)
57 cs := &connectedState{
58 config: config,
59 log: log,
60
61=== modified file 'bus/connectivity/connectivity_test.go'
62--- connectivity/connectivity_test.go 2014-01-22 12:27:35 +0000
63+++ bus/connectivity/connectivity_test.go 2014-01-23 14:29:00 +0000
64@@ -19,12 +19,11 @@
65 import (
66 "io/ioutil"
67 . "launchpad.net/gocheck"
68+ "launchpad.net/ubuntu-push/bus/networkmanager"
69 testingbus "launchpad.net/ubuntu-push/bus/testing"
70 "launchpad.net/ubuntu-push/config"
71 "launchpad.net/ubuntu-push/logger"
72- "launchpad.net/ubuntu-push/networkmanager"
73 "launchpad.net/ubuntu-push/testing/condition"
74- "net/http"
75 "net/http/httptest"
76 "testing"
77 "time"
78@@ -201,24 +200,6 @@
79 tests for ConnectedState()
80 */
81
82-// Todo: get rid of duplication between this and webchecker_test
83-const (
84- staticText = "something ipsum dolor something"
85- staticHash = "6155f83b471583f47c99998a472a178f"
86-)
87-
88-// mkHandler makes an http.HandlerFunc that returns the provided text
89-// for whatever request it's given.
90-func mkHandler(text string) http.HandlerFunc {
91- return func(w http.ResponseWriter, r *http.Request) {
92- w.(http.Flusher).Flush()
93- w.Write([]byte(text))
94- w.(http.Flusher).Flush()
95- }
96-}
97-
98-// :oboT
99-
100 // yes, this is an integration test
101 func (s *ConnSuite) TestRun(c *C) {
102 ts := httptest.NewServer(mkHandler(staticText))
103
104=== modified file 'bus/connectivity/example/main.go'
105--- connectivity/example/main.go 2014-01-20 06:27:39 +0000
106+++ bus/connectivity/example/main.go 2014-01-23 14:29:00 +0000
107@@ -20,8 +20,8 @@
108 import (
109 "fmt"
110 "launchpad.net/ubuntu-push/bus"
111+ "launchpad.net/ubuntu-push/bus/connectivity"
112 "launchpad.net/ubuntu-push/config"
113- "launchpad.net/ubuntu-push/connectivity"
114 "launchpad.net/ubuntu-push/logger"
115 "os"
116 "strings"
117@@ -30,7 +30,7 @@
118 func main() {
119 log := logger.NewSimpleLogger(os.Stderr, "error")
120
121- paths := []string{"thing.json", "connectivity/example/thing.json"}
122+ paths := []string{"thing.json", "bus/connectivity/example/thing.json"}
123 for _, path := range paths {
124 cff, err := os.Open(path)
125 if err == nil {
126
127=== renamed file 'connectivity/webchecker/webchecker.go' => 'bus/connectivity/webchecker.go'
128--- connectivity/webchecker/webchecker.go 2014-01-20 14:58:59 +0000
129+++ bus/connectivity/webchecker.go 2014-01-23 14:29:00 +0000
130@@ -14,13 +14,13 @@
131 with this program. If not, see <http://www.gnu.org/licenses/>.
132 */
133
134-// Package webchecker checks whether we're actually connected by doing an http
135+// webchecker checks whether we're actually connected by doing an http
136 // GET to the Ubuntu connectivity check URL,
137 // http://start.ubuntu.com/connectivity-check.html
138 //
139 // We could make it be https to make extra doubly sure, but it's expensive
140 // overkill for the majority of cases.
141-package webchecker
142+package connectivity
143
144 import (
145 "crypto/md5"
146@@ -46,7 +46,7 @@
147 }
148
149 // Build a webchecker for the given URL, that should match the target MD5.
150-func New(url string, target string, log logger.Logger) Webchecker {
151+func NewWebchecker(url string, target string, log logger.Logger) Webchecker {
152 return &webchecker{log, url, target}
153 }
154
155
156=== renamed file 'connectivity/webchecker/webchecker_test.go' => 'bus/connectivity/webchecker_test.go'
157--- connectivity/webchecker/webchecker_test.go 2014-01-20 06:27:39 +0000
158+++ bus/connectivity/webchecker_test.go 2014-01-23 14:29:00 +0000
159@@ -14,26 +14,22 @@
160 with this program. If not, see <http://www.gnu.org/licenses/>.
161 */
162
163-package webchecker
164+package connectivity
165
166 import (
167- "io/ioutil"
168 . "launchpad.net/gocheck"
169- "launchpad.net/ubuntu-push/logger"
170 "net/http"
171 "net/http/httptest"
172 "testing"
173 )
174
175 // hook up gocheck
176-func Test(t *testing.T) { TestingT(t) }
177+func TestWebcheck(t *testing.T) { TestingT(t) }
178
179 type WebcheckerSuite struct{}
180
181 var _ = Suite(&WebcheckerSuite{})
182
183-var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
184-
185 const (
186 staticText = "something ipsum dolor something"
187 staticHash = "6155f83b471583f47c99998a472a178f"
188@@ -69,7 +65,7 @@
189 ts := httptest.NewServer(mkHandler(staticText))
190 defer ts.Close()
191
192- ck := New(ts.URL, staticHash, nullog)
193+ ck := NewWebchecker(ts.URL, staticHash, nullog)
194 ch := make(chan bool, 1)
195 ck.Webcheck(ch)
196 c.Check(<-ch, Equals, true)
197@@ -77,7 +73,7 @@
198
199 // Webchecker sends false if the download fails.
200 func (s *WebcheckerSuite) TestActualFails(c *C) {
201- ck := New("garbage://", "", nullog)
202+ ck := NewWebchecker("garbage://", "", nullog)
203 ch := make(chan bool, 1)
204 ck.Webcheck(ch)
205 c.Check(<-ch, Equals, false)
206@@ -88,7 +84,7 @@
207 ts := httptest.NewServer(mkHandler(""))
208 defer ts.Close()
209
210- ck := New(ts.URL, staticHash, nullog)
211+ ck := NewWebchecker(ts.URL, staticHash, nullog)
212 ch := make(chan bool, 1)
213 ck.Webcheck(ch)
214 c.Check(<-ch, Equals, false)
215@@ -99,7 +95,7 @@
216 ts := httptest.NewServer(mkHandler(bigText))
217 defer ts.Close()
218
219- ck := New(ts.URL, bigHash, nullog)
220+ ck := NewWebchecker(ts.URL, bigHash, nullog)
221 ch := make(chan bool, 1)
222 ck.Webcheck(ch)
223 c.Check(<-ch, Equals, false)
224
225=== modified file 'bus/endpoint.go'
226--- bus/endpoint.go 2014-01-22 10:48:52 +0000
227+++ bus/endpoint.go 2014-01-23 14:29:00 +0000
228@@ -31,7 +31,7 @@
229 // bus.Endpoint represents the DBus connection itself.
230 type Endpoint interface {
231 WatchSignal(member string, f func(...interface{}), d func()) error
232- Call(member string, args ...interface{}) (interface{}, error)
233+ Call(member string, args ...interface{}) ([]interface{}, error)
234 GetProperty(property string) (interface{}, error)
235 Close()
236 }
237@@ -81,20 +81,13 @@
238 // Call() invokes the provided member method (on the name, path and interface
239 // provided when creating the endpoint). The return value is unpacked before
240 // being returned.
241-func (endp *endpoint) Call(member string, args ...interface{}) (interface{}, error) {
242+func (endp *endpoint) Call(member string, args ...interface{}) ([]interface{}, error) {
243 msg, err := endp.proxy.Call(endp.iface, member, args...)
244 if err != nil {
245- return 0, err
246+ return nil, err
247 }
248 rvs := endp.unpackOneMsg(msg, member)
249- switch len(rvs) {
250- default:
251- return 0, fmt.Errorf("Too many values in %s response: %d", member, len(rvs))
252- case 0:
253- return 0, fmt.Errorf("Not enough values in %s response: %d", member, len(rvs))
254- case 1:
255- return rvs[0], nil
256- }
257+ return rvs, nil
258 }
259
260 // GetProperty uses the org.freedesktop.DBus.Properties interface's Get method
261
262=== renamed directory 'networkmanager' => 'bus/networkmanager'
263=== modified file 'bus/networkmanager/networkmanager_test.go'
264--- networkmanager/networkmanager_test.go 2014-01-20 13:44:58 +0000
265+++ bus/networkmanager/networkmanager_test.go 2014-01-23 14:29:00 +0000
266@@ -65,13 +65,20 @@
267 c.Check(state, Equals, Unknown)
268 }
269
270-// GetState returns the right state when dbus works but delivers rubbish
271-func (s *NMSuite) TestGetStateRubbish(c *C) {
272+// GetState returns the right state when dbus works but delivers rubbish values
273+func (s *NMSuite) TestGetStateRubbishValues(c *C) {
274 nm := New(testingbus.NewTestingEndpoint(condition.Work(false), 42), nullog)
275 state := nm.GetState()
276 c.Check(state, Equals, Unknown)
277 }
278
279+// GetState returns the right state when dbus works but delivers a rubbish structure
280+func (s *NMSuite) TestGetStateRubbishStructure(c *C) {
281+ nm := New(testingbus.NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{}), nullog)
282+ state := nm.GetState()
283+ c.Check(state, Equals, Unknown)
284+}
285+
286 // WatchState sends a stream of States over the channel
287 func (s *NMSuite) TestWatchState(c *C) {
288 tc := testingbus.NewTestingEndpoint(condition.Work(true), uint32(Unknown), uint32(Asleep), uint32(ConnectedGlobal))
289
290=== renamed directory 'notifications' => 'bus/notifications'
291=== modified file 'bus/notifications/raw.go'
292--- notifications/raw.go 2014-01-22 12:15:12 +0000
293+++ bus/notifications/raw.go 2014-01-23 14:29:00 +0000
294@@ -22,6 +22,7 @@
295 // this is the lower-level api
296
297 import (
298+ "errors"
299 "launchpad.net/go-dbus/v1"
300 "launchpad.net/ubuntu-push/bus"
301 "launchpad.net/ubuntu-push/logger"
302@@ -51,14 +52,9 @@
303 log logger.Logger
304 }
305
306-// Raw returns a new RawNotifications connected to the provided bus.Bus
307-func Raw(bt bus.Bus, log logger.Logger) (*RawNotifications, error) {
308- endp, err := bt.Connect(BusAddress, log)
309- if err != nil {
310- return nil, err
311- }
312-
313- return &RawNotifications{endp, log}, nil
314+// Raw returns a new RawNotifications that'll use the provided bus.Endpoint
315+func Raw(endp bus.Endpoint, log logger.Logger) *RawNotifications {
316+ return &RawNotifications{endp, log}
317 }
318
319 /*
320@@ -73,12 +69,15 @@
321 timeout int32) (uint32, error) {
322 // that's a long argument list! Take a breather.
323 //
324- rv, err := raw.bus.Call("Notify", app_name, reuse_id, icon,
325+ rvs, err := raw.bus.Call("Notify", app_name, reuse_id, icon,
326 summary, body, actions, hints, timeout)
327 if err != nil {
328 return 0, err
329 }
330- return rv.(uint32), nil
331+ if len(rvs) != 1 {
332+ return 0, errors.New("Wrong number of arguments in reply from Notify")
333+ }
334+ return rvs[0].(uint32), nil
335 }
336
337 // WatchActions listens for ActionInvoked signals from the notification daemon
338
339=== modified file 'bus/notifications/raw_test.go'
340--- notifications/raw_test.go 2014-01-21 14:58:28 +0000
341+++ bus/notifications/raw_test.go 2014-01-23 14:29:00 +0000
342@@ -38,38 +38,32 @@
343
344 var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
345
346-func (s *RawSuite) TestConnects(c *C) {
347- bus := testibus.NewTestingBus(condition.Work(false), condition.Work(false))
348- _, err := Raw(bus, nullog)
349- c.Check(err, NotNil)
350- bus = testibus.NewTestingBus(condition.Work(true), condition.Work(false))
351- _, err = Raw(bus, nullog)
352- c.Check(err, IsNil)
353-}
354-
355 func (s *RawSuite) TestNotifies(c *C) {
356- bus := testibus.NewTestingBus(condition.Work(true), condition.Work(true),
357- uint32(1))
358- raw, err := Raw(bus, nullog)
359- c.Assert(err, IsNil)
360+ endp := testibus.NewTestingEndpoint(condition.Work(true), uint32(1))
361+ raw := Raw(endp, nullog)
362 nid, err := raw.Notify("", 0, "", "", "", nil, nil, 0)
363 c.Check(err, IsNil)
364 c.Check(nid, Equals, uint32(1))
365 }
366
367 func (s *RawSuite) TestNotifiesFails(c *C) {
368- bus := testibus.NewTestingBus(condition.Work(true), condition.Work(false))
369- raw, err := Raw(bus, nullog)
370- c.Assert(err, IsNil)
371- _, err = raw.Notify("", 0, "", "", "", nil, nil, 0)
372+ endp := testibus.NewTestingEndpoint(condition.Work(false))
373+ raw := Raw(endp, nullog)
374+ _, err := raw.Notify("", 0, "", "", "", nil, nil, 0)
375+ c.Check(err, NotNil)
376+}
377+
378+func (s *RawSuite) TestNotifiesFailsWeirdly(c *C) {
379+ endp := testibus.NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{1, 2})
380+ raw := Raw(endp, nullog)
381+ _, err := raw.Notify("", 0, "", "", "", nil, nil, 0)
382 c.Check(err, NotNil)
383 }
384
385 func (s *RawSuite) TestWatchActions(c *C) {
386- bus := testibus.NewMultiValuedTestingBus(condition.Work(true), condition.Work(true),
387+ endp := testibus.NewMultiValuedTestingEndpoint(condition.Work(true),
388 []interface{}{uint32(1), "hello"})
389- raw, err := Raw(bus, nullog)
390- c.Assert(err, IsNil)
391+ raw := Raw(endp, nullog)
392 ch, err := raw.WatchActions()
393 c.Assert(err, IsNil)
394 // check we get the right action reply
395@@ -86,9 +80,8 @@
396 }
397
398 func (s *RawSuite) TestWatchActionsFails(c *C) {
399- bus := testibus.NewTestingBus(condition.Work(true), condition.Work(false))
400- raw, err := Raw(bus, nullog)
401- c.Assert(err, IsNil)
402- _, err = raw.WatchActions()
403+ endp := testibus.NewTestingEndpoint(condition.Work(false))
404+ raw := Raw(endp, nullog)
405+ _, err := raw.WatchActions()
406 c.Check(err, NotNil)
407 }
408
409=== modified file 'bus/testing/testing_endpoint.go'
410--- bus/testing/testing_endpoint.go 2014-01-22 10:48:52 +0000
411+++ bus/testing/testing_endpoint.go 2014-01-23 14:29:00 +0000
412@@ -66,23 +66,27 @@
413
414 // See Endpoint's Call. This Call will check its condition to decide whether
415 // to return an error, or the first of its return values
416-func (tc *testingEndpoint) Call(member string, args ...interface{}) (interface{}, error) {
417+func (tc *testingEndpoint) Call(member string, args ...interface{}) ([]interface{}, error) {
418 if tc.cond.OK() {
419 if len(tc.retvals) == 0 {
420 panic("No return values provided!")
421 }
422- if len(tc.retvals[0]) != 1 {
423- panic("Wrong number of values provided -- Call only returns a single value for now!")
424- }
425- return tc.retvals[0][0], nil
426+ return tc.retvals[0], nil
427 } else {
428- return 0, errors.New("no way")
429+ return nil, errors.New("no way")
430 }
431 }
432
433 // See Endpoint's GetProperty. This one is just another name for Call.
434 func (tc *testingEndpoint) GetProperty(property string) (interface{}, error) {
435- return tc.Call(property)
436+ rvs, err := tc.Call(property)
437+ if err != nil {
438+ return nil, err
439+ }
440+ if len(rvs) != 1 {
441+ return nil, errors.New("Wrong number of arguments in reply to GetProperty")
442+ }
443+ return rvs[0], err
444 }
445
446 // see Endpoint's Close. This one does nothing.
447
448=== modified file 'bus/testing/testing_endpoint_test.go'
449--- bus/testing/testing_endpoint_test.go 2014-01-21 13:38:03 +0000
450+++ bus/testing/testing_endpoint_test.go 2014-01-23 14:29:00 +0000
451@@ -34,18 +34,20 @@
452 func (s *TestingEndpointSuite) TestCallReturnsFirstRetval(c *C) {
453 var m, n uint32 = 42, 17
454 endp := NewTestingEndpoint(condition.Work(true), m, n)
455- v, e := endp.Call("what")
456+ vs, e := endp.Call("what")
457 c.Check(e, IsNil)
458- c.Check(v, Equals, m)
459+ c.Check(vs, HasLen, 1)
460+ c.Check(vs[0], Equals, m)
461 }
462
463 // Test the same Call() but with multi-valued endpoint
464 func (s *TestingEndpointSuite) TestMultiValuedCall(c *C) {
465 var m, n uint32 = 42, 17
466 endp := NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{m}, []interface{}{n})
467- v, e := endp.Call("what")
468+ vs, e := endp.Call("what")
469 c.Check(e, IsNil)
470- c.Check(v, Equals, m)
471+ c.Check(vs, HasLen, 1)
472+ c.Check(vs[0], Equals, m)
473 }
474
475 // Test that Call() with a negative condition returns an error.
476@@ -62,21 +64,6 @@
477 c.Check(func() { endp.Call("") }, PanicMatches, "No return values provided.*")
478 }
479
480-// Test that Call() with a positive condition and an empty return value panics
481-// with a helpful message.
482-func (s *TestingEndpointSuite) TestCallPanicsWithNiceMessage2(c *C) {
483- endp := NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{})
484- c.Check(func() { endp.Call("") }, PanicMatches, "Wrong number of values provided.*")
485-}
486-
487-// Test Call() with positive condition and the wrong number of arguments also
488-// fails with a helpful message
489-func (s *TestingEndpointSuite) TestMultiValuedCallPanicsWhenWrongNumberOfValues(c *C) {
490- var m, n uint32 = 42, 17
491- endp := NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{m, n})
492- c.Check(func() { endp.Call("") }, PanicMatches, "Wrong number of values provided.*")
493-}
494-
495 // Test that WatchSignal() with a positive condition sends the provided return
496 // values over the channel.
497 func (s *TestingEndpointSuite) TestWatch(c *C) {
498
499=== added directory 'bus/urldispatcher'
500=== added file 'bus/urldispatcher/urldispatcher.go'
501--- bus/urldispatcher/urldispatcher.go 1970-01-01 00:00:00 +0000
502+++ bus/urldispatcher/urldispatcher.go 2014-01-23 14:29:00 +0000
503@@ -0,0 +1,57 @@
504+/*
505+ Copyright 2013-2014 Canonical Ltd.
506+
507+ This program is free software: you can redistribute it and/or modify it
508+ under the terms of the GNU General Public License version 3, as published
509+ by the Free Software Foundation.
510+
511+ This program is distributed in the hope that it will be useful, but
512+ WITHOUT ANY WARRANTY; without even the implied warranties of
513+ MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
514+ PURPOSE. See the GNU General Public License for more details.
515+
516+ You should have received a copy of the GNU General Public License along
517+ with this program. If not, see <http://www.gnu.org/licenses/>.
518+*/
519+
520+// Package urldispatcher wraps the url dispatcher's dbus api point
521+package urldispatcher
522+
523+import (
524+ "launchpad.net/ubuntu-push/bus"
525+ "launchpad.net/ubuntu-push/logger"
526+)
527+
528+// UrlDispatcher lives on a well-known bus.Address
529+var BusAddress bus.Address = bus.Address{
530+ Interface: "com.canonical.URLDispatcher",
531+ Path: "/com/canonical/URLDispatcher",
532+ Name: "com.canonical.URLDispatcher",
533+}
534+
535+// A URLDispatcher is a simple beast, with a single method that does what it
536+// says on the box.
537+type URLDispatcher interface {
538+ DispatchURL(string) error
539+}
540+
541+type urlDispatcher struct {
542+ endp bus.Endpoint
543+ log logger.Logger
544+}
545+
546+// New builds a new URL dispatcher that uses the provided bus.Endpoint
547+func New(endp bus.Endpoint, log logger.Logger) URLDispatcher {
548+ return &urlDispatcher{endp, log}
549+}
550+
551+var _ URLDispatcher = &urlDispatcher{} // ensures it conforms
552+
553+func (ud *urlDispatcher) DispatchURL(url string) error {
554+ ud.log.Debugf("Dispatching %s", url)
555+ _, err := ud.endp.Call("DispatchURL", url)
556+ if err != nil {
557+ ud.log.Errorf("Dispatch to %s failed with %s", url, err)
558+ }
559+ return err
560+}
561
562=== added file 'bus/urldispatcher/urldispatcher_test.go'
563--- bus/urldispatcher/urldispatcher_test.go 1970-01-01 00:00:00 +0000
564+++ bus/urldispatcher/urldispatcher_test.go 2014-01-23 14:29:00 +0000
565@@ -0,0 +1,49 @@
566+/*
567+ Copyright 2013-2014 Canonical Ltd.
568+
569+ This program is free software: you can redistribute it and/or modify it
570+ under the terms of the GNU General Public License version 3, as published
571+ by the Free Software Foundation.
572+
573+ This program is distributed in the hope that it will be useful, but
574+ WITHOUT ANY WARRANTY; without even the implied warranties of
575+ MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
576+ PURPOSE. See the GNU General Public License for more details.
577+
578+ You should have received a copy of the GNU General Public License along
579+ with this program. If not, see <http://www.gnu.org/licenses/>.
580+*/
581+
582+package urldispatcher
583+
584+import (
585+ "io/ioutil"
586+ . "launchpad.net/gocheck"
587+ testibus "launchpad.net/ubuntu-push/bus/testing"
588+ "launchpad.net/ubuntu-push/logger"
589+ "launchpad.net/ubuntu-push/testing/condition"
590+ "testing"
591+)
592+
593+// hook up gocheck
594+func TestUrldispatcher(t *testing.T) { TestingT(t) }
595+
596+type UDSuite struct{}
597+
598+var _ = Suite(&UDSuite{})
599+
600+var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
601+
602+func (s *UDSuite) TestWorks(c *C) {
603+ endp := testibus.NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{})
604+ ud := New(endp, nullog)
605+ err := ud.DispatchURL("this")
606+ c.Check(err, IsNil)
607+}
608+
609+func (s *UDSuite) TestFailsIfCallFails(c *C) {
610+ endp := testibus.NewTestingEndpoint(condition.Work(false))
611+ ud := New(endp, nullog)
612+ err := ud.DispatchURL("this")
613+ c.Check(err, NotNil)
614+}
615
616=== removed directory 'connectivity/webchecker'

Subscribers

People subscribed via source and target branches