Merge lp:~chipaca/ubuntu-push/client-constructor into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 60
Merged at revision: 62
Proposed branch: lp:~chipaca/ubuntu-push/client-constructor
Merge into: lp:ubuntu-push
Diff against target: 472 lines (+77/-65)
2 files modified
client/client.go (+28/-18)
client/client_test.go (+49/-47)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/client-constructor
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+205469@code.launchpad.net

Commit message

Gave client a constructor, moved setting config file to there.

Description of the change

This gives the push client a constructor, and moves any parameters to
it. This is because I'm going to have to specify the path to the
levels database shortly, and passing it to Start() (and from there
into configure) doesn't make much sense.

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

The other way of doing it would be to leave the client interface as is, and add the ability to config to do substitutions (so that the database path can be specified as "$xdg_data_dir/u-p-c/levels.db" or somesuch), or have a special value such as "default". I don't like these alternatives much, but maybe there's one I'm missing; the con of this is that it'll lead to more mixing private and public attributes in the session config.

60. By John Lenton

merged unborking of pem checks

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

20 +type pushClient struct {

so go let's you keep it pacakge private but use the result of NewClient:

https://groups.google.com/forum/#!topic/golang-nuts/UpxU4rwM0OQ

I don't think it's a case where that makes a lot of sense though, I would make it PushClient with unexported fields

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'client/client.go'
--- client/client.go 2014-02-05 16:56:09 +0000
+++ client/client.go 2014-02-08 18:19:14 +0000
@@ -39,7 +39,7 @@
39// ClientConfig holds the client configuration39// ClientConfig holds the client configuration
40type ClientConfig struct {40type ClientConfig struct {
41 connectivity.ConnectivityConfig // q.v.41 connectivity.ConnectivityConfig // q.v.
42 // A reasonably larg timeout for receive/answer pairs42 // A reasonably large timeout for receive/answer pairs
43 ExchangeTimeout config.ConfigTimeDuration `json:"exchange_timeout"`43 ExchangeTimeout config.ConfigTimeDuration `json:"exchange_timeout"`
44 // The server to connect to44 // The server to connect to
45 Addr config.ConfigHostPort45 Addr config.ConfigHostPort
@@ -49,8 +49,9 @@
49 LogLevel string `json:"log_level"`49 LogLevel string `json:"log_level"`
50}50}
5151
52// Client is the Ubuntu Push Notifications client-side daemon.52// pushClient is the Ubuntu Push Notifications client-side daemon.
53type Client struct {53type pushClient struct {
54 configPath string
54 config ClientConfig55 config ClientConfig
55 log logger.Logger56 log logger.Logger
56 pem []byte57 pem []byte
@@ -66,9 +67,18 @@
66 sessionConnectedCh chan uint3267 sessionConnectedCh chan uint32
67}68}
6869
69// configure loads the configuration specified in configPath, and sets it up.70// Creates a new Ubuntu Push Notifications client-side daemon that will use
70func (client *Client) configure(configPath string) error {71// the given configuration file.
71 f, err := os.Open(configPath)72func NewPushClient(configPath string) *pushClient {
73 client := new(pushClient)
74 client.configPath = configPath
75
76 return client
77}
78
79// configure loads its configuration, and sets it up.
80func (client *pushClient) configure() error {
81 f, err := os.Open(client.configPath)
72 if err != nil {82 if err != nil {
73 return fmt.Errorf("opening config: %v", err)83 return fmt.Errorf("opening config: %v", err)
74 }84 }
@@ -104,7 +114,7 @@
104}114}
105115
106// getDeviceId gets the whoopsie identifier for the device116// getDeviceId gets the whoopsie identifier for the device
107func (client *Client) getDeviceId() error {117func (client *pushClient) getDeviceId() error {
108 err := client.idder.Generate()118 err := client.idder.Generate()
109 if err != nil {119 if err != nil {
110 return err120 return err
@@ -114,7 +124,7 @@
114}124}
115125
116// takeTheBus starts the connection(s) to D-Bus and sets up associated event channels126// takeTheBus starts the connection(s) to D-Bus and sets up associated event channels
117func (client *Client) takeTheBus() error {127func (client *pushClient) takeTheBus() error {
118 go connectivity.ConnectedState(client.connectivityEndp,128 go connectivity.ConnectedState(client.connectivityEndp,
119 client.config.ConnectivityConfig, client.log, client.connCh)129 client.config.ConnectivityConfig, client.log, client.connCh)
120 iniCh := make(chan uint32)130 iniCh := make(chan uint32)
@@ -129,7 +139,7 @@
129}139}
130140
131// initSession creates the session object141// initSession creates the session object
132func (client *Client) initSession() error {142func (client *pushClient) initSession() error {
133 sess, err := session.NewSession(string(client.config.Addr), client.pem,143 sess, err := session.NewSession(string(client.config.Addr), client.pem,
134 client.config.ExchangeTimeout.Duration, client.deviceId, client.log)144 client.config.ExchangeTimeout.Duration, client.deviceId, client.log)
135 if err != nil {145 if err != nil {
@@ -140,7 +150,7 @@
140}150}
141151
142// handleConnState deals with connectivity events152// handleConnState deals with connectivity events
143func (client *Client) handleConnState(hasConnectivity bool) {153func (client *pushClient) handleConnState(hasConnectivity bool) {
144 if client.hasConnectivity == hasConnectivity {154 if client.hasConnectivity == hasConnectivity {
145 // nothing to do!155 // nothing to do!
146 return156 return
@@ -154,7 +164,7 @@
154}164}
155165
156// handleErr deals with the session erroring out of its loop166// handleErr deals with the session erroring out of its loop
157func (client *Client) handleErr(err error) {167func (client *pushClient) handleErr(err error) {
158 // if we're not connected, we don't really care168 // if we're not connected, we don't really care
159 client.log.Errorf("session exited: %s", err)169 client.log.Errorf("session exited: %s", err)
160 if client.hasConnectivity {170 if client.hasConnectivity {
@@ -163,7 +173,7 @@
163}173}
164174
165// handleNotification deals with receiving a notification175// handleNotification deals with receiving a notification
166func (client *Client) handleNotification() error {176func (client *pushClient) handleNotification() error {
167 action_id := "dummy_id"177 action_id := "dummy_id"
168 a := []string{action_id, "Go get it!"} // action value not visible on the phone178 a := []string{action_id, "Go get it!"} // action value not visible on the phone
169 h := map[string]*dbus.Variant{"x-canonical-switch-to-application": &dbus.Variant{true}}179 h := map[string]*dbus.Variant{"x-canonical-switch-to-application": &dbus.Variant{true}}
@@ -187,14 +197,14 @@
187}197}
188198
189// handleClick deals with the user clicking a notification199// handleClick deals with the user clicking a notification
190func (client *Client) handleClick() error {200func (client *pushClient) handleClick() error {
191 // it doesn't get much simpler...201 // it doesn't get much simpler...
192 urld := urldispatcher.New(client.urlDispatcherEndp, client.log)202 urld := urldispatcher.New(client.urlDispatcherEndp, client.log)
193 return urld.DispatchURL("settings:///system/system-update")203 return urld.DispatchURL("settings:///system/system-update")
194}204}
195205
196// doLoop connects events with their handlers206// doLoop connects events with their handlers
197func (client *Client) doLoop(connhandler func(bool), clickhandler, notifhandler func() error, errhandler func(error)) {207func (client *pushClient) doLoop(connhandler func(bool), clickhandler, notifhandler func() error, errhandler func(error)) {
198 for {208 for {
199 select {209 select {
200 case state := <-client.connCh:210 case state := <-client.connCh:
@@ -213,7 +223,7 @@
213223
214// doStart calls each of its arguments in order, returning the first non-nil224// doStart calls each of its arguments in order, returning the first non-nil
215// error (or nil at the end)225// error (or nil at the end)
216func (client *Client) doStart(fs ...func() error) error {226func (client *pushClient) doStart(fs ...func() error) error {
217 for _, f := range fs {227 for _, f := range fs {
218 if err := f(); err != nil {228 if err := f(); err != nil {
219 return err229 return err
@@ -223,15 +233,15 @@
223}233}
224234
225// Loop calls doLoop with the "real" handlers235// Loop calls doLoop with the "real" handlers
226func (client *Client) Loop() {236func (client *pushClient) Loop() {
227 client.doLoop(client.handleConnState, client.handleClick,237 client.doLoop(client.handleConnState, client.handleClick,
228 client.handleNotification, client.handleErr)238 client.handleNotification, client.handleErr)
229}239}
230240
231// Start calls doStart with the "real" starters241// Start calls doStart with the "real" starters
232func (client *Client) Start(configPath string) error {242func (client *pushClient) Start() error {
233 return client.doStart(243 return client.doStart(
234 func() error { return client.configure(configPath) },244 client.configure,
235 client.getDeviceId,245 client.getDeviceId,
236 client.initSession,246 client.initSession,
237 client.takeTheBus,247 client.takeTheBus,
238248
=== modified file 'client/client_test.go'
--- client/client_test.go 2014-02-06 13:11:32 +0000
+++ client/client_test.go 2014-02-08 18:19:14 +0000
@@ -103,43 +103,43 @@
103******************************************************************/103******************************************************************/
104104
105func (cs *clientSuite) TestConfigureWorks(c *C) {105func (cs *clientSuite) TestConfigureWorks(c *C) {
106 cli := new(Client)106 cli := NewPushClient(cs.configPath)
107 err := cli.configure(cs.configPath)107 err := cli.configure()
108 c.Assert(err, IsNil)108 c.Assert(err, IsNil)
109 c.Assert(cli.config, NotNil)109 c.Assert(cli.config, NotNil)
110 c.Check(cli.config.ExchangeTimeout.Duration, Equals, time.Duration(10*time.Millisecond))110 c.Check(cli.config.ExchangeTimeout.Duration, Equals, time.Duration(10*time.Millisecond))
111}111}
112112
113func (cs *clientSuite) TestConfigureSetsUpLog(c *C) {113func (cs *clientSuite) TestConfigureSetsUpLog(c *C) {
114 cli := new(Client)114 cli := NewPushClient(cs.configPath)
115 c.Check(cli.log, IsNil)115 c.Check(cli.log, IsNil)
116 err := cli.configure(cs.configPath)116 err := cli.configure()
117 c.Assert(err, IsNil)117 c.Assert(err, IsNil)
118 c.Assert(cli.log, NotNil)118 c.Assert(cli.log, NotNil)
119}119}
120120
121func (cs *clientSuite) TestConfigureSetsUpPEM(c *C) {121func (cs *clientSuite) TestConfigureSetsUpPEM(c *C) {
122 cli := new(Client)122 cli := NewPushClient(cs.configPath)
123 c.Check(cli.pem, IsNil)123 c.Check(cli.pem, IsNil)
124 err := cli.configure(cs.configPath)124 err := cli.configure()
125 c.Assert(err, IsNil)125 c.Assert(err, IsNil)
126 c.Assert(cli.pem, NotNil)126 c.Assert(cli.pem, NotNil)
127}127}
128128
129func (cs *clientSuite) TestConfigureSetsUpIdder(c *C) {129func (cs *clientSuite) TestConfigureSetsUpIdder(c *C) {
130 cli := new(Client)130 cli := NewPushClient(cs.configPath)
131 c.Check(cli.idder, IsNil)131 c.Check(cli.idder, IsNil)
132 err := cli.configure(cs.configPath)132 err := cli.configure()
133 c.Assert(err, IsNil)133 c.Assert(err, IsNil)
134 c.Assert(cli.idder, DeepEquals, identifier.New())134 c.Assert(cli.idder, DeepEquals, identifier.New())
135}135}
136136
137func (cs *clientSuite) TestConfigureSetsUpEndpoints(c *C) {137func (cs *clientSuite) TestConfigureSetsUpEndpoints(c *C) {
138 cli := new(Client)138 cli := NewPushClient(cs.configPath)
139 c.Check(cli.notificationsEndp, IsNil)139 c.Check(cli.notificationsEndp, IsNil)
140 c.Check(cli.urlDispatcherEndp, IsNil)140 c.Check(cli.urlDispatcherEndp, IsNil)
141 c.Check(cli.connectivityEndp, IsNil)141 c.Check(cli.connectivityEndp, IsNil)
142 err := cli.configure(cs.configPath)142 err := cli.configure()
143 c.Assert(err, IsNil)143 c.Assert(err, IsNil)
144 c.Assert(cli.notificationsEndp, NotNil)144 c.Assert(cli.notificationsEndp, NotNil)
145 c.Assert(cli.urlDispatcherEndp, NotNil)145 c.Assert(cli.urlDispatcherEndp, NotNil)
@@ -147,22 +147,22 @@
147}147}
148148
149func (cs *clientSuite) TestConfigureSetsUpConnCh(c *C) {149func (cs *clientSuite) TestConfigureSetsUpConnCh(c *C) {
150 cli := new(Client)150 cli := NewPushClient(cs.configPath)
151 c.Check(cli.connCh, IsNil)151 c.Check(cli.connCh, IsNil)
152 err := cli.configure(cs.configPath)152 err := cli.configure()
153 c.Assert(err, IsNil)153 c.Assert(err, IsNil)
154 c.Assert(cli.connCh, NotNil)154 c.Assert(cli.connCh, NotNil)
155}155}
156156
157func (cs *clientSuite) TestConfigureBailsOnBadFilename(c *C) {157func (cs *clientSuite) TestConfigureBailsOnBadFilename(c *C) {
158 cli := new(Client)158 cli := NewPushClient("/does/not/exist")
159 err := cli.configure("/does/not/exist")159 err := cli.configure()
160 c.Assert(err, NotNil)160 c.Assert(err, NotNil)
161}161}
162162
163func (cs *clientSuite) TestConfigureBailsOnBadConfig(c *C) {163func (cs *clientSuite) TestConfigureBailsOnBadConfig(c *C) {
164 cli := new(Client)164 cli := NewPushClient("/etc/passwd")
165 err := cli.configure("/etc/passwd")165 err := cli.configure()
166 c.Assert(err, NotNil)166 c.Assert(err, NotNil)
167}167}
168168
@@ -175,12 +175,13 @@
175 "connectivity_check_md5": "",175 "connectivity_check_md5": "",
176 "addr": ":0",176 "addr": ":0",
177 "cert_pem_file": "/a/b/c",177 "cert_pem_file": "/a/b/c",
178 "log_level": "debug",
178 "recheck_timeout": "3h"179 "recheck_timeout": "3h"
179}`), 0600)180}`), 0600)
180181
181 cli := new(Client)182 cli := NewPushClient(cs.configPath)
182 err := cli.configure(cs.configPath)183 err := cli.configure()
183 c.Assert(err, NotNil)184 c.Assert(err, ErrorMatches, "reading PEM file: .*")
184}185}
185186
186func (cs *clientSuite) TestConfigureBailsOnBadPEM(c *C) {187func (cs *clientSuite) TestConfigureBailsOnBadPEM(c *C) {
@@ -192,12 +193,13 @@
192 "connectivity_check_md5": "",193 "connectivity_check_md5": "",
193 "addr": ":0",194 "addr": ":0",
194 "cert_pem_file": "/etc/passwd",195 "cert_pem_file": "/etc/passwd",
196 "log_level": "debug",
195 "recheck_timeout": "3h"197 "recheck_timeout": "3h"
196}`), 0600)198}`), 0600)
197199
198 cli := new(Client)200 cli := NewPushClient(cs.configPath)
199 err := cli.configure(cs.configPath)201 err := cli.configure()
200 c.Assert(err, NotNil)202 c.Assert(err, ErrorMatches, "no PEM found.*")
201}203}
202204
203/*****************************************************************205/*****************************************************************
@@ -205,7 +207,7 @@
205******************************************************************/207******************************************************************/
206208
207func (cs *clientSuite) TestGetDeviceIdWorks(c *C) {209func (cs *clientSuite) TestGetDeviceIdWorks(c *C) {
208 cli := new(Client)210 cli := NewPushClient(cs.configPath)
209 cli.log = cs.log211 cli.log = cs.log
210 cli.idder = identifier.New()212 cli.idder = identifier.New()
211 c.Check(cli.deviceId, Equals, "")213 c.Check(cli.deviceId, Equals, "")
@@ -214,7 +216,7 @@
214}216}
215217
216func (cs *clientSuite) TestGetDeviceIdCanFail(c *C) {218func (cs *clientSuite) TestGetDeviceIdCanFail(c *C) {
217 cli := new(Client)219 cli := NewPushClient(cs.configPath)
218 cli.log = cs.log220 cli.log = cs.log
219 cli.idder = idtesting.Failing()221 cli.idder = idtesting.Failing()
220 c.Check(cli.deviceId, Equals, "")222 c.Check(cli.deviceId, Equals, "")
@@ -242,9 +244,9 @@
242 )244 )
243 testibus.SetWatchTicker(cEndp, make(chan bool))245 testibus.SetWatchTicker(cEndp, make(chan bool))
244 // ok, create the thing246 // ok, create the thing
245 cli := new(Client)247 cli := NewPushClient(cs.configPath)
246 cli.log = cs.log248 cli.log = cs.log
247 err := cli.configure(cs.configPath)249 err := cli.configure()
248 c.Assert(err, IsNil)250 c.Assert(err, IsNil)
249 // the user actions channel has not been set up251 // the user actions channel has not been set up
250 c.Check(cli.actionsCh, IsNil)252 c.Check(cli.actionsCh, IsNil)
@@ -270,8 +272,8 @@
270272
271// takeTheBus can, in fact, fail273// takeTheBus can, in fact, fail
272func (cs *clientSuite) TestTakeTheBusCanFail(c *C) {274func (cs *clientSuite) TestTakeTheBusCanFail(c *C) {
273 cli := new(Client)275 cli := NewPushClient(cs.configPath)
274 err := cli.configure(cs.configPath)276 err := cli.configure()
275 cli.log = cs.log277 cli.log = cs.log
276 c.Assert(err, IsNil)278 c.Assert(err, IsNil)
277 // the user actions channel has not been set up279 // the user actions channel has not been set up
@@ -291,7 +293,7 @@
291******************************************************************/293******************************************************************/
292294
293func (cs *clientSuite) TestHandleErr(c *C) {295func (cs *clientSuite) TestHandleErr(c *C) {
294 cli := new(Client)296 cli := NewPushClient(cs.configPath)
295 cli.log = cs.log297 cli.log = cs.log
296 c.Assert(cli.initSession(), IsNil)298 c.Assert(cli.initSession(), IsNil)
297 cli.hasConnectivity = true299 cli.hasConnectivity = true
@@ -304,7 +306,7 @@
304******************************************************************/306******************************************************************/
305307
306func (cs *clientSuite) TestHandleConnStateD2C(c *C) {308func (cs *clientSuite) TestHandleConnStateD2C(c *C) {
307 cli := new(Client)309 cli := NewPushClient(cs.configPath)
308 cli.log = cs.log310 cli.log = cs.log
309 c.Assert(cli.initSession(), IsNil)311 c.Assert(cli.initSession(), IsNil)
310312
@@ -315,7 +317,7 @@
315}317}
316318
317func (cs *clientSuite) TestHandleConnStateSame(c *C) {319func (cs *clientSuite) TestHandleConnStateSame(c *C) {
318 cli := new(Client)320 cli := NewPushClient(cs.configPath)
319 cli.log = cs.log321 cli.log = cs.log
320 // here we want to check that we don't do anything322 // here we want to check that we don't do anything
321 c.Assert(cli.session, IsNil)323 c.Assert(cli.session, IsNil)
@@ -329,7 +331,7 @@
329}331}
330332
331func (cs *clientSuite) TestHandleConnStateC2D(c *C) {333func (cs *clientSuite) TestHandleConnStateC2D(c *C) {
332 cli := new(Client)334 cli := NewPushClient(cs.configPath)
333 cli.log = cs.log335 cli.log = cs.log
334 cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, cs.log)336 cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, cs.log)
335 cli.session.Dial()337 cli.session.Dial()
@@ -342,7 +344,7 @@
342}344}
343345
344func (cs *clientSuite) TestHandleConnStateC2DPending(c *C) {346func (cs *clientSuite) TestHandleConnStateC2DPending(c *C) {
345 cli := new(Client)347 cli := NewPushClient(cs.configPath)
346 cli.log = cs.log348 cli.log = cs.log
347 cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, cs.log)349 cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, cs.log)
348 cli.hasConnectivity = true350 cli.hasConnectivity = true
@@ -356,7 +358,7 @@
356******************************************************************/358******************************************************************/
357359
358func (cs *clientSuite) TestHandleNotification(c *C) {360func (cs *clientSuite) TestHandleNotification(c *C) {
359 cli := new(Client)361 cli := NewPushClient(cs.configPath)
360 endp := testibus.NewTestingEndpoint(nil, condition.Work(true), uint32(1))362 endp := testibus.NewTestingEndpoint(nil, condition.Work(true), uint32(1))
361 cli.notificationsEndp = endp363 cli.notificationsEndp = endp
362 cli.log = cs.log364 cli.log = cs.log
@@ -369,7 +371,7 @@
369}371}
370372
371func (cs *clientSuite) TestHandleNotificationFail(c *C) {373func (cs *clientSuite) TestHandleNotificationFail(c *C) {
372 cli := new(Client)374 cli := NewPushClient(cs.configPath)
373 cli.log = cs.log375 cli.log = cs.log
374 endp := testibus.NewTestingEndpoint(nil, condition.Work(false))376 endp := testibus.NewTestingEndpoint(nil, condition.Work(false))
375 cli.notificationsEndp = endp377 cli.notificationsEndp = endp
@@ -381,7 +383,7 @@
381******************************************************************/383******************************************************************/
382384
383func (cs *clientSuite) TestHandleClick(c *C) {385func (cs *clientSuite) TestHandleClick(c *C) {
384 cli := new(Client)386 cli := NewPushClient(cs.configPath)
385 cli.log = cs.log387 cli.log = cs.log
386 endp := testibus.NewTestingEndpoint(nil, condition.Work(true), nil)388 endp := testibus.NewTestingEndpoint(nil, condition.Work(true), nil)
387 cli.urlDispatcherEndp = endp389 cli.urlDispatcherEndp = endp
@@ -398,7 +400,7 @@
398******************************************************************/400******************************************************************/
399401
400func (cs *clientSuite) TestDoLoopConn(c *C) {402func (cs *clientSuite) TestDoLoopConn(c *C) {
401 cli := new(Client)403 cli := NewPushClient(cs.configPath)
402 cli.log = cs.log404 cli.log = cs.log
403 cli.connCh = make(chan bool, 1)405 cli.connCh = make(chan bool, 1)
404 cli.connCh <- true406 cli.connCh <- true
@@ -410,7 +412,7 @@
410}412}
411413
412func (cs *clientSuite) TestDoLoopClick(c *C) {414func (cs *clientSuite) TestDoLoopClick(c *C) {
413 cli := new(Client)415 cli := NewPushClient(cs.configPath)
414 cli.log = cs.log416 cli.log = cs.log
415 c.Assert(cli.initSession(), IsNil)417 c.Assert(cli.initSession(), IsNil)
416 aCh := make(chan notifications.RawActionReply, 1)418 aCh := make(chan notifications.RawActionReply, 1)
@@ -423,7 +425,7 @@
423}425}
424426
425func (cs *clientSuite) TestDoLoopNotif(c *C) {427func (cs *clientSuite) TestDoLoopNotif(c *C) {
426 cli := new(Client)428 cli := NewPushClient(cs.configPath)
427 cli.log = cs.log429 cli.log = cs.log
428 c.Assert(cli.initSession(), IsNil)430 c.Assert(cli.initSession(), IsNil)
429 cli.session.MsgCh = make(chan *session.Notification, 1)431 cli.session.MsgCh = make(chan *session.Notification, 1)
@@ -435,7 +437,7 @@
435}437}
436438
437func (cs *clientSuite) TestDoLoopErr(c *C) {439func (cs *clientSuite) TestDoLoopErr(c *C) {
438 cli := new(Client)440 cli := NewPushClient(cs.configPath)
439 cli.log = cs.log441 cli.log = cs.log
440 c.Assert(cli.initSession(), IsNil)442 c.Assert(cli.initSession(), IsNil)
441 cli.session.ErrCh = make(chan error, 1)443 cli.session.ErrCh = make(chan error, 1)
@@ -451,7 +453,7 @@
451******************************************************************/453******************************************************************/
452454
453func (cs *clientSuite) TestDoStartWorks(c *C) {455func (cs *clientSuite) TestDoStartWorks(c *C) {
454 cli := new(Client)456 cli := NewPushClient(cs.configPath)
455 one_called := false457 one_called := false
456 two_called := false458 two_called := false
457 one := func() error { one_called = true; return nil }459 one := func() error { one_called = true; return nil }
@@ -462,7 +464,7 @@
462}464}
463465
464func (cs *clientSuite) TestDoStartFailsAsExpected(c *C) {466func (cs *clientSuite) TestDoStartFailsAsExpected(c *C) {
465 cli := new(Client)467 cli := NewPushClient(cs.configPath)
466 one_called := false468 one_called := false
467 two_called := false469 two_called := false
468 failure := errors.New("Failure")470 failure := errors.New("Failure")
@@ -478,7 +480,7 @@
478******************************************************************/480******************************************************************/
479481
480func (cs *clientSuite) TestLoop(c *C) {482func (cs *clientSuite) TestLoop(c *C) {
481 cli := new(Client)483 cli := NewPushClient(cs.configPath)
482 cli.connCh = make(chan bool)484 cli.connCh = make(chan bool)
483 cli.sessionConnectedCh = make(chan uint32)485 cli.sessionConnectedCh = make(chan uint32)
484 aCh := make(chan notifications.RawActionReply, 1)486 aCh := make(chan notifications.RawActionReply, 1)
@@ -556,7 +558,7 @@
556 c.Skip("no dbus")558 c.Skip("no dbus")
557 }559 }
558560
559 cli := new(Client)561 cli := NewPushClient(cs.configPath)
560 // before start, everything sucks:562 // before start, everything sucks:
561 // no config,563 // no config,
562 c.Check(string(cli.config.Addr), Equals, "")564 c.Check(string(cli.config.Addr), Equals, "")
@@ -569,7 +571,7 @@
569 // no nuthin'.571 // no nuthin'.
570572
571 // so we start,573 // so we start,
572 err := cli.Start(cs.configPath)574 err := cli.Start()
573 // and it works575 // and it works
574 c.Check(err, IsNil)576 c.Check(err, IsNil)
575577
@@ -585,9 +587,9 @@
585}587}
586588
587func (cs *clientSuite) TestStartCanFail(c *C) {589func (cs *clientSuite) TestStartCanFail(c *C) {
588 cli := new(Client)590 cli := NewPushClient("/does/not/exist")
589 // easiest way for it to fail is to feed it a bad config591 // easiest way for it to fail is to feed it a bad config
590 err := cli.Start("/does/not/exist")592 err := cli.Start()
591 // and it works. Err. Doesn't.593 // and it works. Err. Doesn't.
592 c.Check(err, NotNil)594 c.Check(err, NotNil)
593}595}

Subscribers

People subscribed via source and target branches