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