Merge lp:~chipaca/ubuntu-push/client-v0-p2 into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 47
Merged at revision: 45
Proposed branch: lp:~chipaca/ubuntu-push/client-v0-p2
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/client-v0-p1
Diff against target: 113 lines (+49/-4)
3 files modified
client/client.go (+19/-3)
client/client_test.go (+29/-0)
whoopsie/identifier/identifier.go (+1/-1)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/client-v0-p2
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+204474@code.launchpad.net

Commit message

second step of the v0 of the client: getting the device id

Description of the change

Second step of the v0 of the client: getting the device id. Includes a
small fix to whoopsie/identifier where identifier.New wasn't returning
an identifier.Id.

To post a comment you must log in.
Revision history for this message
Samuele Pedroni (pedronis) wrote :

it's intentional that getDeviceId is private?

review: Approve
Revision history for this message
John Lenton (chipaca) wrote :

At least for now yes, the idea being that these will all be orchestrated from within client itself. If that turns out to be unwieldy and the orchestration needs to be done from outside, that (and a number of ones to come) would be public instead.

Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'client/client.go'
--- client/client.go 2014-02-03 14:20:12 +0000
+++ client/client.go 2014-02-03 14:20:12 +0000
@@ -25,6 +25,7 @@
25 "launchpad.net/ubuntu-push/bus/connectivity"25 "launchpad.net/ubuntu-push/bus/connectivity"
26 "launchpad.net/ubuntu-push/config"26 "launchpad.net/ubuntu-push/config"
27 "launchpad.net/ubuntu-push/logger"27 "launchpad.net/ubuntu-push/logger"
28 "launchpad.net/ubuntu-push/whoopsie/identifier"
28 "os"29 "os"
29)30)
3031
@@ -38,9 +39,11 @@
38}39}
3940
40type Client struct {41type Client struct {
41 config ClientConfig42 config ClientConfig
42 log logger.Logger43 log logger.Logger
43 pem []byte44 pem []byte
45 idder identifier.Id
46 deviceId string
44}47}
4548
46// Configure loads the configuration specified in configPath, and sets it up.49// Configure loads the configuration specified in configPath, and sets it up.
@@ -56,6 +59,9 @@
56 // later, we'll be specifying logging options in the config file59 // later, we'll be specifying logging options in the config file
57 client.log = logger.NewSimpleLogger(os.Stderr, "error")60 client.log = logger.NewSimpleLogger(os.Stderr, "error")
5861
62 // overridden for testing
63 client.idder = identifier.New()
64
59 if client.config.CertPEMFile != "" {65 if client.config.CertPEMFile != "" {
60 client.pem, err = ioutil.ReadFile(client.config.CertPEMFile)66 client.pem, err = ioutil.ReadFile(client.config.CertPEMFile)
61 if err != nil {67 if err != nil {
@@ -70,3 +76,13 @@
7076
71 return nil77 return nil
72}78}
79
80// getDeviceId gets the whoopsie identifier for the device
81func (client *Client) getDeviceId() error {
82 err := client.idder.Generate()
83 if err != nil {
84 return err
85 }
86 client.deviceId = client.idder.String()
87 return nil
88}
7389
=== modified file 'client/client_test.go'
--- client/client_test.go 2014-02-03 14:20:12 +0000
+++ client/client_test.go 2014-02-03 14:20:12 +0000
@@ -22,6 +22,8 @@
22 . "launchpad.net/gocheck"22 . "launchpad.net/gocheck"
23 "launchpad.net/ubuntu-push/logger"23 "launchpad.net/ubuntu-push/logger"
24 helpers "launchpad.net/ubuntu-push/testing"24 helpers "launchpad.net/ubuntu-push/testing"
25 "launchpad.net/ubuntu-push/whoopsie/identifier"
26 idtesting "launchpad.net/ubuntu-push/whoopsie/identifier/testing"
25 "os"27 "os"
26 "path/filepath"28 "path/filepath"
27 "testing"29 "testing"
@@ -83,6 +85,14 @@
83 c.Assert(cli.pem, NotNil)85 c.Assert(cli.pem, NotNil)
84}86}
8587
88func (cs *clientSuite) TestConfigureSetsUpIdder(c *C) {
89 cli := new(Client)
90 c.Check(cli.idder, IsNil)
91 err := cli.Configure(cs.configPath)
92 c.Assert(err, IsNil)
93 c.Assert(cli.idder, DeepEquals, identifier.New())
94}
95
86func (cs *clientSuite) TestConfigureBailsOnBadFilename(c *C) {96func (cs *clientSuite) TestConfigureBailsOnBadFilename(c *C) {
87 cli := new(Client)97 cli := new(Client)
88 err := cli.Configure("/does/not/exist")98 err := cli.Configure("/does/not/exist")
@@ -128,3 +138,22 @@
128 err := cli.Configure(cs.configPath)138 err := cli.Configure(cs.configPath)
129 c.Assert(err, NotNil)139 c.Assert(err, NotNil)
130}140}
141
142/*****************************************************************
143 getDeviceId tests
144******************************************************************/
145
146func (cs *clientSuite) TestGetDeviceIdWorks(c *C) {
147 cli := new(Client)
148 cli.idder = identifier.New()
149 c.Check(cli.deviceId, Equals, "")
150 c.Check(cli.getDeviceId(), IsNil)
151 c.Check(cli.deviceId, HasLen, 128)
152}
153
154func (cs *clientSuite) TestGetDeviceIdCanFail(c *C) {
155 cli := new(Client)
156 cli.idder = idtesting.Failing()
157 c.Check(cli.deviceId, Equals, "")
158 c.Check(cli.getDeviceId(), NotNil)
159}
131160
=== modified file 'whoopsie/identifier/identifier.go'
--- whoopsie/identifier/identifier.go 2014-01-15 15:51:50 +0000
+++ whoopsie/identifier/identifier.go 2014-02-03 14:20:12 +0000
@@ -40,7 +40,7 @@
40}40}
4141
42// New creates an Identifier, but does not call Generate() on it.42// New creates an Identifier, but does not call Generate() on it.
43func New() *Identifier {43func New() Id {
44 return &Identifier{}44 return &Identifier{}
45}45}
4646

Subscribers

People subscribed via source and target branches