1
0
镜像自地址 https://github.com/tuna/tunasync.git 已同步 2025-12-06 06:26:46 +00:00

refactor(manager): let manager export LoadConfig

这个提交包含在:
bigeagle
2016-04-28 21:09:21 +08:00
父节点 72d9f87711
当前提交 3874d41afc
共有 2 个文件被更改,包括 9 次插入5 次删除

查看文件

@@ -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")
}

查看文件

@@ -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)