mirror of
https://github.com/tuna/tunasync.git
synced 2025-06-14 13:32:43 +00:00
refactor(manager): let manager export LoadConfig
This commit is contained in:
parent
72d9f87711
commit
3874d41afc
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user