refactor(manager): let manager export LoadConfig

This commit is contained in:
bigeagle 2016-04-28 21:09:21 +08:00
parent 72d9f87711
commit 3874d41afc
No known key found for this signature in database
GPG Key ID: 9171A4571C27920A
2 changed files with 9 additions and 5 deletions

View File

@ -29,7 +29,7 @@ type FileConfig struct {
CACert string `toml:"ca_cert"`
}
func loadConfig(cfgFile string, c *cli.Context) (*Config, error) {
func LoadConfig(cfgFile string, c *cli.Context) (*Config, error) {
cfg := new(Config)
cfg.Server.Addr = "127.0.0.1"
@ -46,6 +46,10 @@ func loadConfig(cfgFile string, c *cli.Context) (*Config, error) {
}
}
if c == nil {
return cfg, nil
}
if c.String("addr") != "" {
cfg.Server.Addr = c.String("addr")
}

View File

@ -72,7 +72,7 @@ func TestConfig(t *testing.T) {
Convey("when giving no config options", func() {
app.Action = func(c *cli.Context) {
cfgFile := c.String("config")
cfg, err := loadConfig(cfgFile, c)
cfg, err := LoadConfig(cfgFile, c)
So(err, ShouldEqual, nil)
So(cfg.Server.Addr, ShouldEqual, "127.0.0.1")
}
@ -83,7 +83,7 @@ func TestConfig(t *testing.T) {
app.Action = func(c *cli.Context) {
cfgFile := c.String("config")
So(cfgFile, ShouldEqual, tmpfile.Name())
conf, err := loadConfig(cfgFile, c)
conf, err := LoadConfig(cfgFile, c)
So(err, ShouldEqual, nil)
So(conf.Server.Addr, ShouldEqual, "0.0.0.0")
So(conf.Server.Port, ShouldEqual, 5000)
@ -99,7 +99,7 @@ func TestConfig(t *testing.T) {
app.Action = func(c *cli.Context) {
cfgFile := c.String("config")
So(cfgFile, ShouldEqual, "")
conf, err := loadConfig(cfgFile, c)
conf, err := LoadConfig(cfgFile, c)
So(err, ShouldEqual, nil)
So(conf.Server.Addr, ShouldEqual, "0.0.0.0")
So(conf.Server.Port, ShouldEqual, 5001)
@ -119,7 +119,7 @@ func TestConfig(t *testing.T) {
app.Action = func(c *cli.Context) {
cfgFile := c.String("config")
So(cfgFile, ShouldEqual, tmpfile.Name())
conf, err := loadConfig(cfgFile, c)
conf, err := LoadConfig(cfgFile, c)
So(err, ShouldEqual, nil)
So(conf.Server.Addr, ShouldEqual, "0.0.0.0")
So(conf.Server.Port, ShouldEqual, 5000)