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

Proposed by John Lenton
Status: Merged
Approved by: Samuele Pedroni
Approved revision: 22
Merged at revision: 25
Proposed branch: lp:~chipaca/ubuntu-push/endpoint-not-bus
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/bus-reorg
Diff against target: 151 lines (+25/-58)
4 files modified
bus/notifications/raw.go (+3/-8)
bus/notifications/raw_test.go (+13/-29)
bus/urldispatcher/urldispatcher.go (+3/-7)
bus/urldispatcher/urldispatcher_test.go (+6/-14)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/endpoint-not-bus
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+203060@code.launchpad.net

This proposal supersedes a proposal from 2014-01-23.

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.
Revision history for this message
Samuele Pedroni (pedronis) wrote :

I see where this is going from the other branches,

the interfaces where you have to hand over a nm endpoint to connectivity is a bit strange though

Revision history for this message
Samuele Pedroni (pedronis) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bus/notifications/raw.go'
2--- bus/notifications/raw.go 2014-01-24 13:21:18 +0000
3+++ bus/notifications/raw.go 2014-01-24 13:21:18 +0000
4@@ -52,14 +52,9 @@
5 log logger.Logger
6 }
7
8-// Raw returns a new RawNotifications connected to the provided bus.Bus
9-func Raw(bt bus.Bus, log logger.Logger) (*RawNotifications, error) {
10- endp, err := bt.Connect(BusAddress, log)
11- if err != nil {
12- return nil, err
13- }
14-
15- return &RawNotifications{endp, log}, nil
16+// Raw returns a new RawNotifications that'll use the provided bus.Endpoint
17+func Raw(endp bus.Endpoint, log logger.Logger) *RawNotifications {
18+ return &RawNotifications{endp, log}
19 }
20
21 /*
22
23=== modified file 'bus/notifications/raw_test.go'
24--- bus/notifications/raw_test.go 2014-01-24 13:21:18 +0000
25+++ bus/notifications/raw_test.go 2014-01-24 13:21:18 +0000
26@@ -38,47 +38,32 @@
27
28 var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
29
30-func (s *RawSuite) TestConnects(c *C) {
31- bus := testibus.NewTestingBus(condition.Work(false), condition.Work(false))
32- _, err := Raw(bus, nullog)
33- c.Check(err, NotNil)
34- bus = testibus.NewTestingBus(condition.Work(true), condition.Work(false))
35- _, err = Raw(bus, nullog)
36- c.Check(err, IsNil)
37-}
38-
39 func (s *RawSuite) TestNotifies(c *C) {
40- bus := testibus.NewTestingBus(condition.Work(true), condition.Work(true),
41- uint32(1))
42- raw, err := Raw(bus, nullog)
43- c.Assert(err, IsNil)
44+ endp := testibus.NewTestingEndpoint(condition.Work(true), uint32(1))
45+ raw := Raw(endp, nullog)
46 nid, err := raw.Notify("", 0, "", "", "", nil, nil, 0)
47 c.Check(err, IsNil)
48 c.Check(nid, Equals, uint32(1))
49 }
50
51 func (s *RawSuite) TestNotifiesFails(c *C) {
52- bus := testibus.NewTestingBus(condition.Work(true), condition.Work(false))
53- raw, err := Raw(bus, nullog)
54- c.Assert(err, IsNil)
55- _, err = raw.Notify("", 0, "", "", "", nil, nil, 0)
56+ endp := testibus.NewTestingEndpoint(condition.Work(false))
57+ raw := Raw(endp, nullog)
58+ _, err := raw.Notify("", 0, "", "", "", nil, nil, 0)
59 c.Check(err, NotNil)
60 }
61
62 func (s *RawSuite) TestNotifiesFailsWeirdly(c *C) {
63- bus := testibus.NewMultiValuedTestingBus(condition.Work(true), condition.Work(true),
64- []interface{}{1, 2})
65- raw, err := Raw(bus, nullog)
66- c.Assert(err, IsNil)
67- _, err = raw.Notify("", 0, "", "", "", nil, nil, 0)
68+ endp := testibus.NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{1, 2})
69+ raw := Raw(endp, nullog)
70+ _, err := raw.Notify("", 0, "", "", "", nil, nil, 0)
71 c.Check(err, NotNil)
72 }
73
74 func (s *RawSuite) TestWatchActions(c *C) {
75- bus := testibus.NewMultiValuedTestingBus(condition.Work(true), condition.Work(true),
76+ endp := testibus.NewMultiValuedTestingEndpoint(condition.Work(true),
77 []interface{}{uint32(1), "hello"})
78- raw, err := Raw(bus, nullog)
79- c.Assert(err, IsNil)
80+ raw := Raw(endp, nullog)
81 ch, err := raw.WatchActions()
82 c.Assert(err, IsNil)
83 // check we get the right action reply
84@@ -95,9 +80,8 @@
85 }
86
87 func (s *RawSuite) TestWatchActionsFails(c *C) {
88- bus := testibus.NewTestingBus(condition.Work(true), condition.Work(false))
89- raw, err := Raw(bus, nullog)
90- c.Assert(err, IsNil)
91- _, err = raw.WatchActions()
92+ endp := testibus.NewTestingEndpoint(condition.Work(false))
93+ raw := Raw(endp, nullog)
94+ _, err := raw.WatchActions()
95 c.Check(err, NotNil)
96 }
97
98=== modified file 'bus/urldispatcher/urldispatcher.go'
99--- bus/urldispatcher/urldispatcher.go 2014-01-24 13:21:18 +0000
100+++ bus/urldispatcher/urldispatcher.go 2014-01-24 13:21:18 +0000
101@@ -40,13 +40,9 @@
102 log logger.Logger
103 }
104
105-// New builds a new URL dispatcher by connecting to the provided bus.
106-func New(bus bus.Bus, log logger.Logger) (URLDispatcher, error) {
107- endp, err := bus.Connect(BusAddress, log)
108- if err != nil {
109- return nil, err
110- }
111- return &urlDispatcher{endp, log}, nil
112+// New builds a new URL dispatcher that uses the provided bus.Endpoint
113+func New(endp bus.Endpoint, log logger.Logger) URLDispatcher {
114+ return &urlDispatcher{endp, log}
115 }
116
117 var _ URLDispatcher = &urlDispatcher{} // ensures it conforms
118
119=== modified file 'bus/urldispatcher/urldispatcher_test.go'
120--- bus/urldispatcher/urldispatcher_test.go 2014-01-24 13:21:18 +0000
121+++ bus/urldispatcher/urldispatcher_test.go 2014-01-24 13:21:18 +0000
122@@ -35,23 +35,15 @@
123 var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
124
125 func (s *UDSuite) TestWorks(c *C) {
126- tb := testibus.NewMultiValuedTestingBus(condition.Work(true), condition.Work(true), []interface{}{})
127- ud, err := New(tb, nullog)
128- c.Assert(err, IsNil)
129- err = ud.DispatchURL("this")
130+ endp := testibus.NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{})
131+ ud := New(endp, nullog)
132+ err := ud.DispatchURL("this")
133 c.Check(err, IsNil)
134 }
135
136-func (s *UDSuite) TestFailsIfConnectFails(c *C) {
137- tb := testibus.NewTestingBus(condition.Work(false), condition.Work(true))
138- _, err := New(tb, nullog)
139- c.Check(err, NotNil)
140-}
141-
142 func (s *UDSuite) TestFailsIfCallFails(c *C) {
143- tb := testibus.NewTestingBus(condition.Work(true), condition.Work(false))
144- ud, err := New(tb, nullog)
145- c.Assert(err, IsNil)
146- err = ud.DispatchURL("this")
147+ endp := testibus.NewTestingEndpoint(condition.Work(false))
148+ ud := New(endp, nullog)
149+ err := ud.DispatchURL("this")
150 c.Check(err, NotNil)
151 }

Subscribers

People subscribed via source and target branches