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
=== modified file 'client/client.go'
--- client/client.go 2014-04-11 16:37:48 +0000
+++ client/client.go 2014-04-14 08:34:28 +0000
@@ -57,7 +57,7 @@
57 // The PEM-encoded server certificate57 // The PEM-encoded server certificate
58 CertPEMFile string `json:"cert_pem_file"`58 CertPEMFile string `json:"cert_pem_file"`
59 // The logging level (one of "debug", "info", "error")59 // The logging level (one of "debug", "info", "error")
60 LogLevel string `json:"log_level"`60 LogLevel logger.ConfigLogLevel `json:"log_level"`
61}61}
6262
63// PushClient is the Ubuntu Push Notifications client-side daemon.63// PushClient is the Ubuntu Push Notifications client-side daemon.
@@ -95,13 +95,13 @@
9595
96// configure loads its configuration, and sets it up.96// configure loads its configuration, and sets it up.
97func (client *PushClient) configure() error {97func (client *PushClient) configure() error {
98 f, err := os.Open(client.configPath)98 _, err := os.Stat(client.configPath)
99 if err != nil {99 if err != nil {
100 return fmt.Errorf("opening config: %v", err)100 return fmt.Errorf("config: %v", err)
101 }101 }
102 err = config.ReadConfig(f, &client.config)102 err = config.ReadFiles(&client.config, client.configPath, "<flags>")
103 if err != nil {103 if err != nil {
104 return fmt.Errorf("reading config: %v", err)104 return fmt.Errorf("config: %v", err)
105 }105 }
106 // ignore spaces106 // ignore spaces
107 client.config.Addr = strings.Replace(client.config.Addr, " ", "", -1)107 client.config.Addr = strings.Replace(client.config.Addr, " ", "", -1)
@@ -110,7 +110,7 @@
110 }110 }
111111
112 // later, we'll be specifying more logging options in the config file112 // later, we'll be specifying more logging options in the config file
113 client.log = logger.NewSimpleLogger(os.Stderr, client.config.LogLevel)113 client.log = logger.NewSimpleLogger(os.Stderr, client.config.LogLevel.Level())
114114
115 // overridden for testing115 // overridden for testing
116 client.idder = identifier.New()116 client.idder = identifier.New()
117117
=== modified file 'client/client_test.go'
--- client/client_test.go 2014-04-11 16:21:45 +0000
+++ client/client_test.go 2014-04-14 08:34:28 +0000
@@ -19,10 +19,12 @@
19import (19import (
20 "encoding/json"20 "encoding/json"
21 "errors"21 "errors"
22 "flag"
22 "fmt"23 "fmt"
23 "io/ioutil"24 "io/ioutil"
24 "net/http"25 "net/http"
25 "net/http/httptest"26 "net/http/httptest"
27 "os"
26 "path/filepath"28 "path/filepath"
27 "reflect"29 "reflect"
28 "testing"30 "testing"
@@ -37,6 +39,7 @@
37 testibus "launchpad.net/ubuntu-push/bus/testing"39 testibus "launchpad.net/ubuntu-push/bus/testing"
38 "launchpad.net/ubuntu-push/client/session"40 "launchpad.net/ubuntu-push/client/session"
39 "launchpad.net/ubuntu-push/client/session/levelmap"41 "launchpad.net/ubuntu-push/client/session/levelmap"
42 "launchpad.net/ubuntu-push/config"
40 helpers "launchpad.net/ubuntu-push/testing"43 helpers "launchpad.net/ubuntu-push/testing"
41 "launchpad.net/ubuntu-push/testing/condition"44 "launchpad.net/ubuntu-push/testing/condition"
42 "launchpad.net/ubuntu-push/util"45 "launchpad.net/ubuntu-push/util"
@@ -79,6 +82,7 @@
79}82}
8083
81func (cs *clientSuite) SetUpSuite(c *C) {84func (cs *clientSuite) SetUpSuite(c *C) {
85 config.IgnoreParsedFlags = true // because configure() uses <flags>
82 cs.timeouts = util.SwapTimeouts([]time.Duration{0})86 cs.timeouts = util.SwapTimeouts([]time.Duration{0})
83 cs.leveldbPath = ""87 cs.leveldbPath = ""
84}88}
@@ -142,6 +146,16 @@
142 c.Check(cli.config.ExchangeTimeout.TimeDuration(), Equals, time.Duration(10*time.Millisecond))146 c.Check(cli.config.ExchangeTimeout.TimeDuration(), Equals, time.Duration(10*time.Millisecond))
143}147}
144148
149func (cs *clientSuite) TestConfigureWorksWithFlags(c *C) {
150 flag.CommandLine = flag.NewFlagSet("client", flag.ContinueOnError)
151 os.Args = []string{"client", "-addr", "foo:7777"}
152 cli := NewPushClient(cs.configPath, cs.leveldbPath)
153 err := cli.configure()
154 c.Assert(err, IsNil)
155 c.Assert(cli.config, NotNil)
156 c.Check(cli.config.Addr, Equals, "foo:7777")
157}
158
145func (cs *clientSuite) TestConfigureSetsUpLog(c *C) {159func (cs *clientSuite) TestConfigureSetsUpLog(c *C) {
146 cli := NewPushClient(cs.configPath, cs.leveldbPath)160 cli := NewPushClient(cs.configPath, cs.leveldbPath)
147 c.Check(cli.log, IsNil)161 c.Check(cli.log, IsNil)

Subscribers

People subscribed via source and target branches