chore(config): move Sanitize and Force check to boot process

Make Load function just load parameters. So etcd instance could
use Config struct to start service.
This commit is contained in:
Yicheng Qin 2014-03-30 21:13:28 -07:00
parent b56aa62bcc
commit b0ffb4fd10
4 changed files with 13 additions and 17 deletions

View File

@ -142,16 +142,6 @@ func (c *Config) Load(arguments []string) error {
return err
}
// Sanitize all the input fields.
if err := c.Sanitize(); err != nil {
return fmt.Errorf("sanitize: %v", err)
}
// Force remove server configuration if specified.
if c.Force {
c.Reset()
}
return nil
}

View File

@ -479,7 +479,7 @@ func TestConfigCustomConfigOverrideSystemConfig(t *testing.T) {
c := New()
c.SystemPath = p1
assert.Nil(t, c.Load([]string{"-config", p2}), "")
assert.Equal(t, c.Addr, "http://127.0.0.1:6000", "")
assert.Equal(t, c.Addr, "127.0.0.1:6000", "")
})
})
}
@ -494,7 +494,7 @@ func TestConfigEnvVarOverrideCustomConfig(t *testing.T) {
c := New()
c.SystemPath = ""
assert.Nil(t, c.Load([]string{"-config", path}), "")
assert.Equal(t, c.Peer.Addr, "http://127.0.0.1:8000", "")
assert.Equal(t, c.Peer.Addr, "127.0.0.1:8000", "")
})
}
@ -506,7 +506,7 @@ func TestConfigCLIArgsOverrideEnvVar(t *testing.T) {
c := New()
c.SystemPath = ""
assert.Nil(t, c.Load([]string{"-addr", "127.0.0.1:2000"}), "")
assert.Equal(t, c.Addr, "http://127.0.0.1:2000", "")
assert.Equal(t, c.Addr, "127.0.0.1:2000", "")
}
//--------------------------------------

View File

@ -61,6 +61,16 @@ func New(c *config.Config) *Etcd {
// Run the etcd instance.
func (e *Etcd) Run() {
// Sanitize all the input fields.
if err := e.Config.Sanitize(); err != nil {
log.Fatalf("failed sanitizing configuration: %v", err)
}
// Force remove server configuration if specified.
if e.Config.Force {
e.Config.Reset()
}
// Enable options.
if e.Config.VeryVeryVerbose {
log.Verbose = true

View File

@ -34,10 +34,6 @@ func TestRunStop(t *testing.T) {
config.Addr = "localhost:0"
config.Peer.Addr = "localhost:0"
if err := config.Sanitize(); err != nil {
t.Fatal(err)
}
etcd := New(config)
go etcd.Run()
<-etcd.ReadyNotify()