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
1=== modified file 'client/client.go'
2--- client/client.go 2014-02-03 14:20:12 +0000
3+++ client/client.go 2014-02-03 14:20:12 +0000
4@@ -25,6 +25,7 @@
5 "launchpad.net/ubuntu-push/bus/connectivity"
6 "launchpad.net/ubuntu-push/config"
7 "launchpad.net/ubuntu-push/logger"
8+ "launchpad.net/ubuntu-push/whoopsie/identifier"
9 "os"
10 )
11
12@@ -38,9 +39,11 @@
13 }
14
15 type Client struct {
16- config ClientConfig
17- log logger.Logger
18- pem []byte
19+ config ClientConfig
20+ log logger.Logger
21+ pem []byte
22+ idder identifier.Id
23+ deviceId string
24 }
25
26 // Configure loads the configuration specified in configPath, and sets it up.
27@@ -56,6 +59,9 @@
28 // later, we'll be specifying logging options in the config file
29 client.log = logger.NewSimpleLogger(os.Stderr, "error")
30
31+ // overridden for testing
32+ client.idder = identifier.New()
33+
34 if client.config.CertPEMFile != "" {
35 client.pem, err = ioutil.ReadFile(client.config.CertPEMFile)
36 if err != nil {
37@@ -70,3 +76,13 @@
38
39 return nil
40 }
41+
42+// getDeviceId gets the whoopsie identifier for the device
43+func (client *Client) getDeviceId() error {
44+ err := client.idder.Generate()
45+ if err != nil {
46+ return err
47+ }
48+ client.deviceId = client.idder.String()
49+ return nil
50+}
51
52=== modified file 'client/client_test.go'
53--- client/client_test.go 2014-02-03 14:20:12 +0000
54+++ client/client_test.go 2014-02-03 14:20:12 +0000
55@@ -22,6 +22,8 @@
56 . "launchpad.net/gocheck"
57 "launchpad.net/ubuntu-push/logger"
58 helpers "launchpad.net/ubuntu-push/testing"
59+ "launchpad.net/ubuntu-push/whoopsie/identifier"
60+ idtesting "launchpad.net/ubuntu-push/whoopsie/identifier/testing"
61 "os"
62 "path/filepath"
63 "testing"
64@@ -83,6 +85,14 @@
65 c.Assert(cli.pem, NotNil)
66 }
67
68+func (cs *clientSuite) TestConfigureSetsUpIdder(c *C) {
69+ cli := new(Client)
70+ c.Check(cli.idder, IsNil)
71+ err := cli.Configure(cs.configPath)
72+ c.Assert(err, IsNil)
73+ c.Assert(cli.idder, DeepEquals, identifier.New())
74+}
75+
76 func (cs *clientSuite) TestConfigureBailsOnBadFilename(c *C) {
77 cli := new(Client)
78 err := cli.Configure("/does/not/exist")
79@@ -128,3 +138,22 @@
80 err := cli.Configure(cs.configPath)
81 c.Assert(err, NotNil)
82 }
83+
84+/*****************************************************************
85+ getDeviceId tests
86+******************************************************************/
87+
88+func (cs *clientSuite) TestGetDeviceIdWorks(c *C) {
89+ cli := new(Client)
90+ cli.idder = identifier.New()
91+ c.Check(cli.deviceId, Equals, "")
92+ c.Check(cli.getDeviceId(), IsNil)
93+ c.Check(cli.deviceId, HasLen, 128)
94+}
95+
96+func (cs *clientSuite) TestGetDeviceIdCanFail(c *C) {
97+ cli := new(Client)
98+ cli.idder = idtesting.Failing()
99+ c.Check(cli.deviceId, Equals, "")
100+ c.Check(cli.getDeviceId(), NotNil)
101+}
102
103=== modified file 'whoopsie/identifier/identifier.go'
104--- whoopsie/identifier/identifier.go 2014-01-15 15:51:50 +0000
105+++ whoopsie/identifier/identifier.go 2014-02-03 14:20:12 +0000
106@@ -40,7 +40,7 @@
107 }
108
109 // New creates an Identifier, but does not call Generate() on it.
110-func New() *Identifier {
111+func New() Id {
112 return &Identifier{}
113 }
114

Subscribers

People subscribed via source and target branches