Merge lp:~pedronis/ubuntu-push/client-takes-cmd-line-flags-as-well into lp:ubuntu-push/automatic

Proposed by Samuele Pedroni
Status: Merged
Approved by: Samuele Pedroni
Approved revision: 131
Merged at revision: 120
Proposed branch: lp:~pedronis/ubuntu-push/client-takes-cmd-line-flags-as-well
Merge into: lp:ubuntu-push/automatic
Prerequisite: lp:~pedronis/ubuntu-push/config-enhancements
Diff against target: 89 lines (+20/-6)
2 files modified
client/client.go (+6/-6)
client/client_test.go (+14/-0)
To merge this branch: bzr merge lp:~pedronis/ubuntu-push/client-takes-cmd-line-flags-as-well
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+215617@code.launchpad.net

Commit message

let ubuntu-push-client get config values also from the command line

Description of the change

let ubuntu-push-client get config values also from the command line

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

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-04-11 16:37:48 +0000
3+++ client/client.go 2014-04-14 08:34:28 +0000
4@@ -57,7 +57,7 @@
5 // The PEM-encoded server certificate
6 CertPEMFile string `json:"cert_pem_file"`
7 // The logging level (one of "debug", "info", "error")
8- LogLevel string `json:"log_level"`
9+ LogLevel logger.ConfigLogLevel `json:"log_level"`
10 }
11
12 // PushClient is the Ubuntu Push Notifications client-side daemon.
13@@ -95,13 +95,13 @@
14
15 // configure loads its configuration, and sets it up.
16 func (client *PushClient) configure() error {
17- f, err := os.Open(client.configPath)
18+ _, err := os.Stat(client.configPath)
19 if err != nil {
20- return fmt.Errorf("opening config: %v", err)
21+ return fmt.Errorf("config: %v", err)
22 }
23- err = config.ReadConfig(f, &client.config)
24+ err = config.ReadFiles(&client.config, client.configPath, "<flags>")
25 if err != nil {
26- return fmt.Errorf("reading config: %v", err)
27+ return fmt.Errorf("config: %v", err)
28 }
29 // ignore spaces
30 client.config.Addr = strings.Replace(client.config.Addr, " ", "", -1)
31@@ -110,7 +110,7 @@
32 }
33
34 // later, we'll be specifying more logging options in the config file
35- client.log = logger.NewSimpleLogger(os.Stderr, client.config.LogLevel)
36+ client.log = logger.NewSimpleLogger(os.Stderr, client.config.LogLevel.Level())
37
38 // overridden for testing
39 client.idder = identifier.New()
40
41=== modified file 'client/client_test.go'
42--- client/client_test.go 2014-04-11 16:21:45 +0000
43+++ client/client_test.go 2014-04-14 08:34:28 +0000
44@@ -19,10 +19,12 @@
45 import (
46 "encoding/json"
47 "errors"
48+ "flag"
49 "fmt"
50 "io/ioutil"
51 "net/http"
52 "net/http/httptest"
53+ "os"
54 "path/filepath"
55 "reflect"
56 "testing"
57@@ -37,6 +39,7 @@
58 testibus "launchpad.net/ubuntu-push/bus/testing"
59 "launchpad.net/ubuntu-push/client/session"
60 "launchpad.net/ubuntu-push/client/session/levelmap"
61+ "launchpad.net/ubuntu-push/config"
62 helpers "launchpad.net/ubuntu-push/testing"
63 "launchpad.net/ubuntu-push/testing/condition"
64 "launchpad.net/ubuntu-push/util"
65@@ -79,6 +82,7 @@
66 }
67
68 func (cs *clientSuite) SetUpSuite(c *C) {
69+ config.IgnoreParsedFlags = true // because configure() uses <flags>
70 cs.timeouts = util.SwapTimeouts([]time.Duration{0})
71 cs.leveldbPath = ""
72 }
73@@ -142,6 +146,16 @@
74 c.Check(cli.config.ExchangeTimeout.TimeDuration(), Equals, time.Duration(10*time.Millisecond))
75 }
76
77+func (cs *clientSuite) TestConfigureWorksWithFlags(c *C) {
78+ flag.CommandLine = flag.NewFlagSet("client", flag.ContinueOnError)
79+ os.Args = []string{"client", "-addr", "foo:7777"}
80+ cli := NewPushClient(cs.configPath, cs.leveldbPath)
81+ err := cli.configure()
82+ c.Assert(err, IsNil)
83+ c.Assert(cli.config, NotNil)
84+ c.Check(cli.config.Addr, Equals, "foo:7777")
85+}
86+
87 func (cs *clientSuite) TestConfigureSetsUpLog(c *C) {
88 cli := NewPushClient(cs.configPath, cs.leveldbPath)
89 c.Check(cli.log, IsNil)

Subscribers

People subscribed via source and target branches