Merge lp:~chipaca/ubuntu-push/test-logger-client-bits into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: Samuele Pedroni
Approved revision: 60
Merged at revision: 55
Proposed branch: lp:~chipaca/ubuntu-push/test-logger-client-bits
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/client-session-redialer-mash
Diff against target: 954 lines (+133/-111)
11 files modified
bus/bus_test.go (+3/-5)
bus/connectivity/connectivity_test.go (+12/-9)
bus/connectivity/webchecker_test.go (+11/-4)
bus/endpoint.go (+5/-3)
bus/endpoint_test.go (+13/-9)
bus/networkmanager/networkmanager_test.go (+15/-11)
bus/notifications/raw_test.go (+13/-9)
bus/urldispatcher/urldispatcher_test.go (+9/-5)
client/client_test.go (+18/-21)
client/session/session_test.go (+34/-32)
util/redialer_test.go (+0/-3)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/test-logger-client-bits
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+204814@code.launchpad.net

Commit message

TestLogger

Description of the change

TestLogger.

To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) wrote :

Also in this branch: renamed things from FooTest to TestFoo in bus/*.go, so those tests actually run. Fixed one breaking one.

55. By John Lenton

Merged client-session-redialer-mash into test-logger-client-bits.

56. By John Lenton

fixed buglets in the merge

57. By John Lenton

Merged client-session-redialer-mash into test-logger-client-bits.

Revision history for this message
Samuele Pedroni (pedronis) wrote :

the style I had in mind was more to have

s.testlog available in the suite

58. By John Lenton

moved TestLogger creation into SetUpTest

Revision history for this message
Samuele Pedroni (pedronis) wrote :

these separators aren't needed, in -gocheck.vv etc gocheck should give separation:

159 + s.log.Debugf("---")

Revision history for this message
Samuele Pedroni (pedronis) wrote :

913 func (s *clientSessionSuite) TestJitter(c *C) {
914 - sess, err := NewSession("", nil, 0, "wah", helpers.NewTestLogger(c, "debug"))
915 + sess, err := NewSession("", nil, 0, "wah", s.log)

59. By John Lenton

nuked the debug separators

60. By John Lenton

No longer using both s and cs for clientSessionSuite

Revision history for this message
Samuele Pedroni (pedronis) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bus/bus_test.go'
2--- bus/bus_test.go 2014-01-23 14:33:08 +0000
3+++ bus/bus_test.go 2014-02-05 18:24:01 +0000
4@@ -18,19 +18,17 @@
5
6 import (
7 "fmt"
8- "io/ioutil"
9 "launchpad.net/go-dbus/v1"
10 . "launchpad.net/gocheck"
11- "launchpad.net/ubuntu-push/logger"
12+ helpers "launchpad.net/ubuntu-push/testing"
13 "testing"
14 )
15
16 // hook up gocheck
17-func BusTest(t *testing.T) { TestingT(t) }
18+func TestBus(t *testing.T) { TestingT(t) }
19
20 type BusSuite struct{}
21
22-var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
23 var _ = Suite(&BusSuite{})
24
25 // Test we stringify sanely
26@@ -47,6 +45,6 @@
27
28 // Tests that we can get an endpoint back
29 func (s *BusSuite) TestEndpoint(c *C) {
30- endp := SystemBus.Endpoint(Address{"", "", ""}, nullog)
31+ endp := SystemBus.Endpoint(Address{"", "", ""}, helpers.NewTestLogger(c, "debug"))
32 c.Assert(endp, NotNil)
33 }
34
35=== modified file 'bus/connectivity/connectivity_test.go'
36--- bus/connectivity/connectivity_test.go 2014-02-04 13:02:38 +0000
37+++ bus/connectivity/connectivity_test.go 2014-02-05 18:24:01 +0000
38@@ -17,12 +17,12 @@
39 package connectivity
40
41 import (
42- "io/ioutil"
43 . "launchpad.net/gocheck"
44 "launchpad.net/ubuntu-push/bus/networkmanager"
45 testingbus "launchpad.net/ubuntu-push/bus/testing"
46 "launchpad.net/ubuntu-push/config"
47 "launchpad.net/ubuntu-push/logger"
48+ helpers "launchpad.net/ubuntu-push/testing"
49 "launchpad.net/ubuntu-push/testing/condition"
50 "launchpad.net/ubuntu-push/util"
51 "net/http/httptest"
52@@ -35,12 +35,11 @@
53
54 type ConnSuite struct {
55 timeouts []time.Duration
56+ log logger.Logger
57 }
58
59 var _ = Suite(&ConnSuite{})
60
61-var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
62-
63 func (s *ConnSuite) SetUpSuite(c *C) {
64 s.timeouts = util.SwapTimeouts([]time.Duration{0, 0, 0, 0})
65 }
66@@ -50,6 +49,10 @@
67 s.timeouts = nil
68 }
69
70+func (s *ConnSuite) SetUpTest(c *C) {
71+ s.log = helpers.NewTestLogger(c, "debug")
72+}
73+
74 /*
75 tests for connectedState's Start() method
76 */
77@@ -57,7 +60,7 @@
78 // when given a working config and bus, Start() will work
79 func (s *ConnSuite) TestStartWorks(c *C) {
80 endp := testingbus.NewTestingEndpoint(condition.Work(true), condition.Work(true), uint32(networkmanager.Connecting))
81- cs := connectedState{config: ConnectivityConfig{}, log: nullog, endp: endp}
82+ cs := connectedState{config: ConnectivityConfig{}, log: s.log, endp: endp}
83
84 c.Check(cs.start(), Equals, networkmanager.Connecting)
85 }
86@@ -65,7 +68,7 @@
87 // if the bus fails a couple of times, we're still OK
88 func (s *ConnSuite) TestStartRetriesConnect(c *C) {
89 endp := testingbus.NewTestingEndpoint(condition.Fail2Work(2), condition.Work(true), uint32(networkmanager.Connecting))
90- cs := connectedState{config: ConnectivityConfig{}, log: nullog, endp: endp}
91+ cs := connectedState{config: ConnectivityConfig{}, log: s.log, endp: endp}
92
93 c.Check(cs.start(), Equals, networkmanager.Connecting)
94 c.Check(cs.connAttempts, Equals, uint32(3)) // 1 more than the Fail2Work
95@@ -74,7 +77,7 @@
96 // when the calls to NetworkManager fail for a bit, we're still OK
97 func (s *ConnSuite) TestStartRetriesCall(c *C) {
98 endp := testingbus.NewTestingEndpoint(condition.Work(true), condition.Fail2Work(5), uint32(networkmanager.Connecting))
99- cs := connectedState{config: ConnectivityConfig{}, log: nullog, endp: endp}
100+ cs := connectedState{config: ConnectivityConfig{}, log: s.log, endp: endp}
101
102 c.Check(cs.start(), Equals, networkmanager.Connecting)
103
104@@ -92,7 +95,7 @@
105 endp := testingbus.NewTestingEndpoint(condition.Work(true), nmcond,
106 uint32(networkmanager.Connecting),
107 uint32(networkmanager.ConnectedGlobal))
108- cs := connectedState{config: ConnectivityConfig{}, log: nullog, endp: endp}
109+ cs := connectedState{config: ConnectivityConfig{}, log: s.log, endp: endp}
110
111 c.Check(cs.start(), Equals, networkmanager.Connecting)
112 c.Check(cs.connAttempts, Equals, uint32(2))
113@@ -116,7 +119,7 @@
114 config: cfg,
115 networkStateCh: ch,
116 timer: time.NewTimer(time.Second),
117- log: nullog,
118+ log: s.log,
119 webget: func(ch chan<- bool) { ch <- webget_p.OK() },
120 lastSent: false,
121 }
122@@ -201,7 +204,7 @@
123 out := make(chan bool)
124 dt := time.Second / 10
125 timer := time.NewTimer(dt)
126- go ConnectedState(endp, cfg, nullog, out)
127+ go ConnectedState(endp, cfg, s.log, out)
128 var v bool
129 expecteds := []struct {
130 p bool
131
132=== modified file 'bus/connectivity/webchecker_test.go'
133--- bus/connectivity/webchecker_test.go 2014-02-04 13:02:38 +0000
134+++ bus/connectivity/webchecker_test.go 2014-02-05 18:24:01 +0000
135@@ -18,6 +18,8 @@
136
137 import (
138 . "launchpad.net/gocheck"
139+ "launchpad.net/ubuntu-push/logger"
140+ helpers "launchpad.net/ubuntu-push/testing"
141 "launchpad.net/ubuntu-push/util"
142 "net/http"
143 "net/http/httptest"
144@@ -26,6 +28,7 @@
145
146 type WebcheckerSuite struct {
147 timeouts []time.Duration
148+ log logger.Logger
149 }
150
151 var _ = Suite(&WebcheckerSuite{})
152@@ -69,12 +72,16 @@
153 s.timeouts = nil
154 }
155
156+func (s *WebcheckerSuite) SetUpTest(c *C) {
157+ s.log = helpers.NewTestLogger(c, "debug")
158+}
159+
160 // Webchecker sends true when everything works
161 func (s *WebcheckerSuite) TestWorks(c *C) {
162 ts := httptest.NewServer(mkHandler(staticText))
163 defer ts.Close()
164
165- ck := NewWebchecker(ts.URL, staticHash, nullog)
166+ ck := NewWebchecker(ts.URL, staticHash, s.log)
167 ch := make(chan bool, 1)
168 ck.Webcheck(ch)
169 c.Check(<-ch, Equals, true)
170@@ -82,7 +89,7 @@
171
172 // Webchecker sends false if the download fails.
173 func (s *WebcheckerSuite) TestActualFails(c *C) {
174- ck := NewWebchecker("garbage://", "", nullog)
175+ ck := NewWebchecker("garbage://", "", s.log)
176 ch := make(chan bool, 1)
177 ck.Webcheck(ch)
178 c.Check(<-ch, Equals, false)
179@@ -93,7 +100,7 @@
180 ts := httptest.NewServer(mkHandler(""))
181 defer ts.Close()
182
183- ck := NewWebchecker(ts.URL, staticHash, nullog)
184+ ck := NewWebchecker(ts.URL, staticHash, s.log)
185 ch := make(chan bool, 1)
186 ck.Webcheck(ch)
187 c.Check(<-ch, Equals, false)
188@@ -104,7 +111,7 @@
189 ts := httptest.NewServer(mkHandler(bigText))
190 defer ts.Close()
191
192- ck := NewWebchecker(ts.URL, bigHash, nullog)
193+ ck := NewWebchecker(ts.URL, bigHash, s.log)
194 ch := make(chan bool, 1)
195 ck.Webcheck(ch)
196 c.Check(<-ch, Equals, false)
197
198=== modified file 'bus/endpoint.go'
199--- bus/endpoint.go 2014-02-05 18:24:00 +0000
200+++ bus/endpoint.go 2014-02-05 18:24:01 +0000
201@@ -125,9 +125,11 @@
202
203 // Close the connection to dbus.
204 func (endp *endpoint) Close() {
205- endp.bus.Close()
206- endp.bus = nil
207- endp.proxy = nil
208+ if endp.bus != nil {
209+ endp.bus.Close()
210+ endp.bus = nil
211+ endp.proxy = nil
212+ }
213 }
214
215 // String() performs advanced endpoint stringification
216
217=== modified file 'bus/endpoint_test.go'
218--- bus/endpoint_test.go 2014-01-27 11:46:36 +0000
219+++ bus/endpoint_test.go 2014-02-05 18:24:01 +0000
220@@ -18,24 +18,28 @@
221
222 import (
223 . "launchpad.net/gocheck"
224+ "launchpad.net/ubuntu-push/logger"
225+ helpers "launchpad.net/ubuntu-push/testing"
226 "os"
227- "testing"
228 )
229
230-// hook up gocheck
231-func EndpointTest(t *testing.T) { TestingT(t) }
232-
233-type EndpointSuite struct{}
234+type EndpointSuite struct {
235+ log logger.Logger
236+}
237
238 var _ = Suite(&EndpointSuite{})
239
240+func (s *EndpointSuite) SetUpTest(c *C) {
241+ s.log = helpers.NewTestLogger(c, "debug")
242+}
243+
244 // TODO: this is going to remain empty until go-dbus grows some
245 // testing amenities (already talked about it with jamesh)
246
247 // Tests that we can connect to the *actual* system bus.
248 // XXX maybe connect to a mock/fake/etc bus?
249-func (s *BusSuite) TestDial(c *C) {
250- endp := newEndpoint(SystemBus, Address{"", "", ""}, nullog)
251+func (s *EndpointSuite) TestDial(c *C) {
252+ endp := newEndpoint(SystemBus, Address{"", "", ""}, s.log)
253 c.Assert(endp.bus, IsNil)
254 err := endp.Dial()
255 c.Assert(err, IsNil)
256@@ -47,13 +51,13 @@
257
258 // Test that if we try to connect to the session bus when no session
259 // bus is available, we get a reasonable result (i.e., an error).
260-func (s *BusSuite) TestDialCanFail(c *C) {
261+func (s *EndpointSuite) TestDialCanFail(c *C) {
262 db := "DBUS_SESSION_BUS_ADDRESS"
263 odb := os.Getenv(db)
264 defer os.Setenv(db, odb)
265 os.Setenv(db, "")
266
267- endp := newEndpoint(SessionBus, Address{"", "", ""}, nullog)
268+ endp := newEndpoint(SessionBus, Address{"", "", ""}, s.log)
269 err := endp.Dial()
270 c.Check(err, NotNil)
271 }
272
273=== modified file 'bus/networkmanager/networkmanager_test.go'
274--- bus/networkmanager/networkmanager_test.go 2014-01-23 14:33:08 +0000
275+++ bus/networkmanager/networkmanager_test.go 2014-02-05 18:24:01 +0000
276@@ -17,10 +17,10 @@
277 package networkmanager
278
279 import (
280- "io/ioutil"
281 . "launchpad.net/gocheck"
282 testingbus "launchpad.net/ubuntu-push/bus/testing"
283 "launchpad.net/ubuntu-push/logger"
284+ helpers "launchpad.net/ubuntu-push/testing"
285 "launchpad.net/ubuntu-push/testing/condition"
286 "testing"
287 )
288@@ -28,11 +28,15 @@
289 // hook up gocheck
290 func Test(t *testing.T) { TestingT(t) }
291
292-type NMSuite struct{}
293+type NMSuite struct {
294+ log logger.Logger
295+}
296
297 var _ = Suite(&NMSuite{})
298
299-var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
300+func (s *NMSuite) SetUpTest(c *C) {
301+ s.log = helpers.NewTestLogger(c, "debug")
302+}
303
304 // TestNames checks that networkmanager.State objects serialize
305 // correctly, to a point.
306@@ -47,34 +51,34 @@
307
308 // TestNew doesn't test much at all. If this fails, all is wrong in the world.
309 func (s *NMSuite) TestNew(c *C) {
310- nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(true)), nullog)
311+ nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(true)), s.log)
312 c.Check(nm, NotNil)
313 }
314
315 // GetState returns the right state when everything works
316 func (s *NMSuite) TestGetState(c *C) {
317- nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(true), uint32(ConnectedGlobal)), nullog)
318+ nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(true), uint32(ConnectedGlobal)), s.log)
319 state := nm.GetState()
320 c.Check(state, Equals, ConnectedGlobal)
321 }
322
323 // GetState returns the right state when dbus fails
324 func (s *NMSuite) TestGetStateFail(c *C) {
325- nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(false), uint32(ConnectedGlobal)), nullog)
326+ nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(false), uint32(ConnectedGlobal)), s.log)
327 state := nm.GetState()
328 c.Check(state, Equals, Unknown)
329 }
330
331 // GetState returns the right state when dbus works but delivers rubbish values
332 func (s *NMSuite) TestGetStateRubbishValues(c *C) {
333- nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(false), 42), nullog)
334+ nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(false), 42), s.log)
335 state := nm.GetState()
336 c.Check(state, Equals, Unknown)
337 }
338
339 // GetState returns the right state when dbus works but delivers a rubbish structure
340 func (s *NMSuite) TestGetStateRubbishStructure(c *C) {
341- nm := New(testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{}), nullog)
342+ nm := New(testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{}), s.log)
343 state := nm.GetState()
344 c.Check(state, Equals, Unknown)
345 }
346@@ -82,7 +86,7 @@
347 // WatchState sends a stream of States over the channel
348 func (s *NMSuite) TestWatchState(c *C) {
349 tc := testingbus.NewTestingEndpoint(nil, condition.Work(true), uint32(Unknown), uint32(Asleep), uint32(ConnectedGlobal))
350- nm := New(tc, nullog)
351+ nm := New(tc, s.log)
352 ch, err := nm.WatchState()
353 c.Check(err, IsNil)
354 l := []State{<-ch, <-ch, <-ch}
355@@ -91,7 +95,7 @@
356
357 // WatchState returns on error if the dbus call fails
358 func (s *NMSuite) TestWatchStateFails(c *C) {
359- nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), nullog)
360+ nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
361 _, err := nm.WatchState()
362 c.Check(err, NotNil)
363 }
364@@ -99,7 +103,7 @@
365 // WatchState calls close on its channel when the watch bails
366 func (s *NMSuite) TestWatchClosesOnWatchBail(c *C) {
367 tc := testingbus.NewTestingEndpoint(nil, condition.Work(true))
368- nm := New(tc, nullog)
369+ nm := New(tc, s.log)
370 ch, err := nm.WatchState()
371 c.Check(err, IsNil)
372 _, ok := <-ch
373
374=== modified file 'bus/notifications/raw_test.go'
375--- bus/notifications/raw_test.go 2014-01-23 14:33:08 +0000
376+++ bus/notifications/raw_test.go 2014-02-05 18:24:01 +0000
377@@ -20,10 +20,10 @@
378 package notifications
379
380 import (
381- "io/ioutil"
382 . "launchpad.net/gocheck"
383 testibus "launchpad.net/ubuntu-push/bus/testing"
384 "launchpad.net/ubuntu-push/logger"
385+ helpers "launchpad.net/ubuntu-push/testing"
386 "launchpad.net/ubuntu-push/testing/condition"
387 "testing"
388 "time"
389@@ -32,15 +32,19 @@
390 // hook up gocheck
391 func TestRaw(t *testing.T) { TestingT(t) }
392
393-type RawSuite struct{}
394+type RawSuite struct {
395+ log logger.Logger
396+}
397+
398+func (s *RawSuite) SetUpTest(c *C) {
399+ s.log = helpers.NewTestLogger(c, "debug")
400+}
401
402 var _ = Suite(&RawSuite{})
403
404-var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
405-
406 func (s *RawSuite) TestNotifies(c *C) {
407 endp := testibus.NewTestingEndpoint(nil, condition.Work(true), uint32(1))
408- raw := Raw(endp, nullog)
409+ raw := Raw(endp, s.log)
410 nid, err := raw.Notify("", 0, "", "", "", nil, nil, 0)
411 c.Check(err, IsNil)
412 c.Check(nid, Equals, uint32(1))
413@@ -48,14 +52,14 @@
414
415 func (s *RawSuite) TestNotifiesFails(c *C) {
416 endp := testibus.NewTestingEndpoint(nil, condition.Work(false))
417- raw := Raw(endp, nullog)
418+ raw := Raw(endp, s.log)
419 _, err := raw.Notify("", 0, "", "", "", nil, nil, 0)
420 c.Check(err, NotNil)
421 }
422
423 func (s *RawSuite) TestNotifiesFailsWeirdly(c *C) {
424 endp := testibus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{1, 2})
425- raw := Raw(endp, nullog)
426+ raw := Raw(endp, s.log)
427 _, err := raw.Notify("", 0, "", "", "", nil, nil, 0)
428 c.Check(err, NotNil)
429 }
430@@ -63,7 +67,7 @@
431 func (s *RawSuite) TestWatchActions(c *C) {
432 endp := testibus.NewMultiValuedTestingEndpoint(nil, condition.Work(true),
433 []interface{}{uint32(1), "hello"})
434- raw := Raw(endp, nullog)
435+ raw := Raw(endp, s.log)
436 ch, err := raw.WatchActions()
437 c.Assert(err, IsNil)
438 // check we get the right action reply
439@@ -81,7 +85,7 @@
440
441 func (s *RawSuite) TestWatchActionsFails(c *C) {
442 endp := testibus.NewTestingEndpoint(nil, condition.Work(false))
443- raw := Raw(endp, nullog)
444+ raw := Raw(endp, s.log)
445 _, err := raw.WatchActions()
446 c.Check(err, NotNil)
447 }
448
449=== modified file 'bus/urldispatcher/urldispatcher_test.go'
450--- bus/urldispatcher/urldispatcher_test.go 2014-01-23 14:33:08 +0000
451+++ bus/urldispatcher/urldispatcher_test.go 2014-02-05 18:24:01 +0000
452@@ -17,10 +17,10 @@
453 package urldispatcher
454
455 import (
456- "io/ioutil"
457 . "launchpad.net/gocheck"
458 testibus "launchpad.net/ubuntu-push/bus/testing"
459 "launchpad.net/ubuntu-push/logger"
460+ helpers "launchpad.net/ubuntu-push/testing"
461 "launchpad.net/ubuntu-push/testing/condition"
462 "testing"
463 )
464@@ -28,22 +28,26 @@
465 // hook up gocheck
466 func TestUrldispatcher(t *testing.T) { TestingT(t) }
467
468-type UDSuite struct{}
469+type UDSuite struct {
470+ log logger.Logger
471+}
472
473 var _ = Suite(&UDSuite{})
474
475-var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
476+func (s *UDSuite) SetUpTest(c *C) {
477+ s.log = helpers.NewTestLogger(c, "debug")
478+}
479
480 func (s *UDSuite) TestWorks(c *C) {
481 endp := testibus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{})
482- ud := New(endp, nullog)
483+ ud := New(endp, s.log)
484 err := ud.DispatchURL("this")
485 c.Check(err, IsNil)
486 }
487
488 func (s *UDSuite) TestFailsIfCallFails(c *C) {
489 endp := testibus.NewTestingEndpoint(nil, condition.Work(false))
490- ud := New(endp, nullog)
491+ ud := New(endp, s.log)
492 err := ud.DispatchURL("this")
493 c.Check(err, NotNil)
494 }
495
496=== modified file 'client/client_test.go'
497--- client/client_test.go 2014-02-05 18:24:00 +0000
498+++ client/client_test.go 2014-02-05 18:24:01 +0000
499@@ -34,7 +34,6 @@
500 idtesting "launchpad.net/ubuntu-push/whoopsie/identifier/testing"
501 "net/http"
502 "net/http/httptest"
503- "os"
504 "path/filepath"
505 "testing"
506 "time"
507@@ -55,11 +54,9 @@
508 type clientSuite struct {
509 timeouts []time.Duration
510 configPath string
511+ log logger.Logger
512 }
513
514-var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
515-var noisylog = logger.NewSimpleLogger(os.Stderr, "debug")
516-var debuglog = noisylog
517 var _ = Suite(&clientSuite{})
518
519 const (
520@@ -85,7 +82,7 @@
521 }
522
523 func (cs *clientSuite) SetUpTest(c *C) {
524- debuglog.Debugf("---")
525+ cs.log = helpers.NewTestLogger(c, "debug")
526 dir := c.MkDir()
527 cs.configPath = filepath.Join(dir, "config")
528 cfg := fmt.Sprintf(`
529@@ -210,7 +207,7 @@
530
531 func (cs *clientSuite) TestGetDeviceIdWorks(c *C) {
532 cli := new(Client)
533- cli.log = debuglog
534+ cli.log = cs.log
535 cli.idder = identifier.New()
536 c.Check(cli.deviceId, Equals, "")
537 c.Check(cli.getDeviceId(), IsNil)
538@@ -219,7 +216,7 @@
539
540 func (cs *clientSuite) TestGetDeviceIdCanFail(c *C) {
541 cli := new(Client)
542- cli.log = debuglog
543+ cli.log = cs.log
544 cli.idder = idtesting.Failing()
545 c.Check(cli.deviceId, Equals, "")
546 c.Check(cli.getDeviceId(), NotNil)
547@@ -247,7 +244,7 @@
548 testibus.SetWatchTicker(cEndp, make(chan bool))
549 // ok, create the thing
550 cli := new(Client)
551- cli.log = debuglog
552+ cli.log = cs.log
553 err := cli.Configure(cs.configPath)
554 c.Assert(err, IsNil)
555 // the user actions channel has not been set up
556@@ -276,7 +273,7 @@
557 func (cs *clientSuite) TestTakeTheBusCanFail(c *C) {
558 cli := new(Client)
559 err := cli.Configure(cs.configPath)
560- cli.log = debuglog
561+ cli.log = cs.log
562 c.Assert(err, IsNil)
563 // the user actions channel has not been set up
564 c.Check(cli.actionsCh, IsNil)
565@@ -310,7 +307,7 @@
566
567 func (cs *clientSuite) TestHandleConnStateD2C(c *C) {
568 cli := new(Client)
569- cli.log = debuglog
570+ cli.log = cs.log
571 cli.initSession()
572
573 c.Assert(cli.hasConnectivity, Equals, false)
574@@ -321,7 +318,7 @@
575
576 func (cs *clientSuite) TestHandleConnStateSame(c *C) {
577 cli := new(Client)
578- cli.log = debuglog
579+ cli.log = cs.log
580 // here we want to check that we don't do anything
581 c.Assert(cli.session, IsNil)
582 c.Assert(cli.hasConnectivity, Equals, false)
583@@ -335,8 +332,8 @@
584
585 func (cs *clientSuite) TestHandleConnStateC2D(c *C) {
586 cli := new(Client)
587- cli.log = debuglog
588- cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, debuglog)
589+ cli.log = cs.log
590+ cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, cs.log)
591 cli.session.Dial()
592 cli.hasConnectivity = true
593
594@@ -348,8 +345,8 @@
595
596 func (cs *clientSuite) TestHandleConnStateC2DPending(c *C) {
597 cli := new(Client)
598- cli.log = debuglog
599- cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, debuglog)
600+ cli.log = cs.log
601+ cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, cs.log)
602 cli.hasConnectivity = true
603
604 cli.handleConnState(false)
605@@ -376,7 +373,7 @@
606
607 func (cs *clientSuite) TestHandleNotificationFail(c *C) {
608 cli := new(Client)
609- cli.log = debuglog
610+ cli.log = cs.log
611 endp := testibus.NewTestingEndpoint(nil, condition.Work(false))
612 cli.notificationsEndp = endp
613 c.Check(cli.handleNotification(), NotNil)
614@@ -388,7 +385,7 @@
615
616 func (cs *clientSuite) TestHandleClick(c *C) {
617 cli := new(Client)
618- cli.log = debuglog
619+ cli.log = cs.log
620 endp := testibus.NewTestingEndpoint(nil, condition.Work(true), nil)
621 cli.urlDispatcherEndp = endp
622 c.Check(cli.handleClick(), IsNil)
623@@ -405,7 +402,7 @@
624
625 func (cs *clientSuite) TestDoLoopConn(c *C) {
626 cli := new(Client)
627- cli.log = debuglog
628+ cli.log = cs.log
629 cli.connCh = make(chan bool, 1)
630 cli.connCh <- true
631 cli.initSession()
632@@ -417,7 +414,7 @@
633
634 func (cs *clientSuite) TestDoLoopClick(c *C) {
635 cli := new(Client)
636- cli.log = debuglog
637+ cli.log = cs.log
638 cli.initSession()
639 aCh := make(chan notifications.RawActionReply, 1)
640 aCh <- notifications.RawActionReply{}
641@@ -430,7 +427,7 @@
642
643 func (cs *clientSuite) TestDoLoopNotif(c *C) {
644 cli := new(Client)
645- cli.log = debuglog
646+ cli.log = cs.log
647 cli.initSession()
648 cli.session.MsgCh = make(chan *session.Notification, 1)
649 cli.session.MsgCh <- &session.Notification{}
650@@ -442,7 +439,7 @@
651
652 func (cs *clientSuite) TestDoLoopErr(c *C) {
653 cli := new(Client)
654- cli.log = debuglog
655+ cli.log = cs.log
656 cli.initSession()
657 cli.session.ErrCh = make(chan error, 1)
658 cli.session.ErrCh <- nil
659
660=== modified file 'client/session/session_test.go'
661--- client/session/session_test.go 2014-02-05 18:24:00 +0000
662+++ client/session/session_test.go 2014-02-05 18:24:01 +0000
663@@ -29,7 +29,6 @@
664 helpers "launchpad.net/ubuntu-push/testing"
665 "launchpad.net/ubuntu-push/testing/condition"
666 "net"
667- "os"
668 "reflect"
669 "testing"
670 "time"
671@@ -37,11 +36,10 @@
672
673 func TestSession(t *testing.T) { TestingT(t) }
674
675-type clientSessionSuite struct{}
676+type clientSessionSuite struct {
677+ log logger.Logger
678+}
679
680-var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
681-var noisylog = logger.NewSimpleLogger(os.Stderr, "debug")
682-var debuglog = nullog
683 var _ = Suite(&clientSessionSuite{})
684
685 //
686@@ -158,12 +156,16 @@
687 return nil
688 }
689
690+func (cs *clientSessionSuite) SetUpTest(c *C) {
691+ cs.log = helpers.NewTestLogger(c, "debug")
692+}
693+
694 /****************************************************************
695 NewSession() tests
696 ****************************************************************/
697
698 func (cs *clientSessionSuite) TestNewSessionPlainWorks(c *C) {
699- sess, err := NewSession("", nil, 0, "", nullog)
700+ sess, err := NewSession("", nil, 0, "", cs.log)
701 c.Check(sess, NotNil)
702 c.Check(err, IsNil)
703 // but no root CAs set
704@@ -175,7 +177,7 @@
705 var pem, _ = ioutil.ReadFile(certfile)
706
707 func (cs *clientSessionSuite) TestNewSessionPEMWorks(c *C) {
708- sess, err := NewSession("", pem, 0, "wah", nullog)
709+ sess, err := NewSession("", pem, 0, "wah", cs.log)
710 c.Check(sess, NotNil)
711 c.Assert(err, IsNil)
712 c.Check(sess.TLS.RootCAs, NotNil)
713@@ -183,7 +185,7 @@
714
715 func (cs *clientSessionSuite) TestNewSessionBadPEMFileContentFails(c *C) {
716 badpem := []byte("This is not the PEM you're looking for.")
717- sess, err := NewSession("", badpem, 0, "wah", nullog)
718+ sess, err := NewSession("", badpem, 0, "wah", cs.log)
719 c.Check(sess, IsNil)
720 c.Check(err, NotNil)
721 }
722@@ -193,7 +195,7 @@
723 ****************************************************************/
724
725 func (cs *clientSessionSuite) TestConnectFailsWithNoAddress(c *C) {
726- sess, err := NewSession("", nil, 0, "wah", debuglog)
727+ sess, err := NewSession("", nil, 0, "wah", cs.log)
728 c.Assert(err, IsNil)
729 err = sess.connect()
730 c.Check(err, ErrorMatches, ".*connect.*address.*")
731@@ -204,7 +206,7 @@
732 srv, err := net.Listen("tcp", "localhost:0")
733 c.Assert(err, IsNil)
734 defer srv.Close()
735- sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", debuglog)
736+ sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", cs.log)
737 c.Assert(err, IsNil)
738 err = sess.connect()
739 c.Check(err, IsNil)
740@@ -215,7 +217,7 @@
741 func (cs *clientSessionSuite) TestConnectConnectFail(c *C) {
742 srv, err := net.Listen("tcp", "localhost:0")
743 c.Assert(err, IsNil)
744- sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", debuglog)
745+ sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", cs.log)
746 srv.Close()
747 c.Assert(err, IsNil)
748 err = sess.connect()
749@@ -228,7 +230,7 @@
750 ****************************************************************/
751
752 func (cs *clientSessionSuite) TestClose(c *C) {
753- sess, err := NewSession("", nil, 0, "wah", debuglog)
754+ sess, err := NewSession("", nil, 0, "wah", cs.log)
755 c.Assert(err, IsNil)
756 sess.Connection = &testConn{Name: "TestClose"}
757 sess.Close()
758@@ -237,7 +239,7 @@
759 }
760
761 func (cs *clientSessionSuite) TestCloseTwice(c *C) {
762- sess, err := NewSession("", nil, 0, "wah", debuglog)
763+ sess, err := NewSession("", nil, 0, "wah", cs.log)
764 c.Assert(err, IsNil)
765 sess.Connection = &testConn{Name: "TestCloseTwice"}
766 sess.Close()
767@@ -248,7 +250,7 @@
768 }
769
770 func (cs *clientSessionSuite) TestCloseFails(c *C) {
771- sess, err := NewSession("", nil, 0, "wah", debuglog)
772+ sess, err := NewSession("", nil, 0, "wah", cs.log)
773 c.Assert(err, IsNil)
774 sess.Connection = &testConn{Name: "TestCloseFails", CloseCondition: condition.Work(false)}
775 sess.Close()
776@@ -262,7 +264,7 @@
777 func (d *derp) Stop() { d.stopped = true }
778
779 func (cs *clientSessionSuite) TestCloseStopsRetrier(c *C) {
780- sess, err := NewSession("", nil, 0, "wah", debuglog)
781+ sess, err := NewSession("", nil, 0, "wah", cs.log)
782 c.Assert(err, IsNil)
783 ar := new(derp)
784 sess.retrier = ar
785@@ -279,7 +281,7 @@
786
787 func (cs *clientSessionSuite) TestAutoRedialWorks(c *C) {
788 // checks that AutoRedial sets up a retrier and tries redialing it
789- sess, err := NewSession("", nil, 0, "wah", debuglog)
790+ sess, err := NewSession("", nil, 0, "wah", cs.log)
791 c.Assert(err, IsNil)
792 ar := new(derp)
793 sess.retrier = ar
794@@ -290,7 +292,7 @@
795
796 func (cs *clientSessionSuite) TestAutoRedialStopsRetrier(c *C) {
797 // checks that AutoRedial stops the previous retrier
798- sess, err := NewSession("", nil, 0, "wah", debuglog)
799+ sess, err := NewSession("", nil, 0, "wah", cs.log)
800 c.Assert(err, IsNil)
801 ch := make(chan uint32)
802 c.Check(sess.retrier, IsNil)
803@@ -315,7 +317,7 @@
804
805 func (s *msgSuite) SetUpTest(c *C) {
806 var err error
807- s.sess, err = NewSession("", nil, time.Millisecond, "wah", debuglog)
808+ s.sess, err = NewSession("", nil, time.Millisecond, "wah", helpers.NewTestLogger(c, "debug"))
809 c.Assert(err, IsNil)
810 s.sess.Connection = &testConn{Name: "TestHandle*"}
811 s.errCh = make(chan error, 1)
812@@ -467,7 +469,7 @@
813 start() tests
814 ****************************************************************/
815 func (cs *clientSessionSuite) TestStartFailsIfSetDeadlineFails(c *C) {
816- sess, err := NewSession("", nil, 0, "wah", debuglog)
817+ sess, err := NewSession("", nil, 0, "wah", cs.log)
818 c.Assert(err, IsNil)
819 sess.Connection = &testConn{Name: "TestStartFailsIfSetDeadlineFails",
820 DeadlineCondition: condition.Work(false)} // setdeadline will fail
821@@ -477,7 +479,7 @@
822 }
823
824 func (cs *clientSessionSuite) TestStartFailsIfWriteFails(c *C) {
825- sess, err := NewSession("", nil, 0, "wah", debuglog)
826+ sess, err := NewSession("", nil, 0, "wah", cs.log)
827 c.Assert(err, IsNil)
828 sess.Connection = &testConn{Name: "TestStartFailsIfWriteFails",
829 WriteCondition: condition.Work(false)} // write will fail
830@@ -487,7 +489,7 @@
831 }
832
833 func (cs *clientSessionSuite) TestStartConnectMessageFails(c *C) {
834- sess, err := NewSession("", nil, 0, "wah", debuglog)
835+ sess, err := NewSession("", nil, 0, "wah", cs.log)
836 c.Assert(err, IsNil)
837 sess.Connection = &testConn{Name: "TestStartConnectMessageFails"}
838 errCh := make(chan error, 1)
839@@ -513,7 +515,7 @@
840 }
841
842 func (cs *clientSessionSuite) TestStartConnackReadError(c *C) {
843- sess, err := NewSession("", nil, 0, "wah", debuglog)
844+ sess, err := NewSession("", nil, 0, "wah", cs.log)
845 c.Assert(err, IsNil)
846 sess.Connection = &testConn{Name: "TestStartConnackReadError"}
847 errCh := make(chan error, 1)
848@@ -537,7 +539,7 @@
849 }
850
851 func (cs *clientSessionSuite) TestStartBadConnack(c *C) {
852- sess, err := NewSession("", nil, 0, "wah", debuglog)
853+ sess, err := NewSession("", nil, 0, "wah", cs.log)
854 c.Assert(err, IsNil)
855 sess.Connection = &testConn{Name: "TestStartBadConnack"}
856 errCh := make(chan error, 1)
857@@ -561,7 +563,7 @@
858 }
859
860 func (cs *clientSessionSuite) TestStartNotConnack(c *C) {
861- sess, err := NewSession("", nil, 0, "wah", debuglog)
862+ sess, err := NewSession("", nil, 0, "wah", cs.log)
863 c.Assert(err, IsNil)
864 sess.Connection = &testConn{Name: "TestStartBadConnack"}
865 errCh := make(chan error, 1)
866@@ -585,7 +587,7 @@
867 }
868
869 func (cs *clientSessionSuite) TestStartWorks(c *C) {
870- sess, err := NewSession("", nil, 0, "wah", debuglog)
871+ sess, err := NewSession("", nil, 0, "wah", cs.log)
872 c.Assert(err, IsNil)
873 sess.Connection = &testConn{Name: "TestStartWorks"}
874 errCh := make(chan error, 1)
875@@ -617,7 +619,7 @@
876 ****************************************************************/
877
878 func (cs *clientSessionSuite) TestRunBailsIfConnectFails(c *C) {
879- sess, err := NewSession("", nil, 0, "wah", debuglog)
880+ sess, err := NewSession("", nil, 0, "wah", cs.log)
881 c.Assert(err, IsNil)
882 failure := errors.New("TestRunBailsIfConnectFails")
883 has_closed := false
884@@ -631,7 +633,7 @@
885 }
886
887 func (cs *clientSessionSuite) TestRunBailsIfStartFails(c *C) {
888- sess, err := NewSession("", nil, 0, "wah", debuglog)
889+ sess, err := NewSession("", nil, 0, "wah", cs.log)
890 c.Assert(err, IsNil)
891 failure := errors.New("TestRunBailsIfStartFails")
892 err = sess.run(
893@@ -643,7 +645,7 @@
894 }
895
896 func (cs *clientSessionSuite) TestRunRunsEvenIfLoopFails(c *C) {
897- sess, err := NewSession("", nil, 0, "wah", debuglog)
898+ sess, err := NewSession("", nil, 0, "wah", cs.log)
899 c.Assert(err, IsNil)
900 // just to make a point: until here we haven't set ErrCh & MsgCh (no
901 // biggie if this stops being true)
902@@ -671,8 +673,8 @@
903 Jitter() tests
904 ****************************************************************/
905
906-func (s *clientSessionSuite) TestJitter(c *C) {
907- sess, err := NewSession("", nil, 0, "wah", helpers.NewTestLogger(c, "debug"))
908+func (cs *clientSessionSuite) TestJitter(c *C) {
909+ sess, err := NewSession("", nil, 0, "wah", cs.log)
910 c.Assert(err, IsNil)
911 num_tries := 20 // should do the math
912 spread := time.Second //
913@@ -704,7 +706,7 @@
914
915 func (cs *clientSessionSuite) TestDialPanics(c *C) {
916 // one last unhappy test
917- sess, err := NewSession("", nil, 0, "wah", helpers.NewTestLogger(c, "debug"))
918+ sess, err := NewSession("", nil, 0, "wah", cs.log)
919 c.Assert(err, IsNil)
920 sess.Protocolator = nil
921 c.Check(sess.Dial, PanicMatches, ".*protocol constructor.")
922@@ -722,7 +724,7 @@
923 timeout := 100 * time.Millisecond
924 lst, err := tls.Listen("tcp", "localhost:0", tlsCfg)
925 c.Assert(err, IsNil)
926- sess, err := NewSession(lst.Addr().String(), nil, timeout, "wah", debuglog)
927+ sess, err := NewSession(lst.Addr().String(), nil, timeout, "wah", cs.log)
928 c.Assert(err, IsNil)
929 tconn := &testConn{CloseCondition: condition.Fail2Work(10)}
930 sess.Connection = tconn
931
932=== modified file 'util/redialer_test.go'
933--- util/redialer_test.go 2014-02-05 18:24:00 +0000
934+++ util/redialer_test.go 2014-02-05 18:24:01 +0000
935@@ -17,11 +17,9 @@
936 package util
937
938 import (
939- "io/ioutil"
940 . "launchpad.net/gocheck"
941 "launchpad.net/ubuntu-push/bus"
942 testibus "launchpad.net/ubuntu-push/bus/testing"
943- "launchpad.net/ubuntu-push/logger"
944 "launchpad.net/ubuntu-push/testing/condition"
945 "testing"
946 "time"
947@@ -34,7 +32,6 @@
948 timeouts []time.Duration
949 }
950
951-var nullog = logger.NewSimpleLogger(ioutil.Discard, "error")
952 var _ = Suite(&RedialerSuite{})
953
954 func (s *RedialerSuite) SetUpSuite(c *C) {

Subscribers

People subscribed via source and target branches