Merge pull request #7789 from influxdata/mr-monitor-config-validation

Require database name on monitor config
pull/7781/head^2
Mark Rushakoff 2017-01-04 13:16:49 -08:00 committed by GitHub
commit bbbf9d9711
2 changed files with 25 additions and 0 deletions

View File

@ -40,5 +40,8 @@ func (c Config) Validate() error {
if c.StoreInterval <= 0 {
return errors.New("monitor store interval must be positive")
}
if c.StoreDatabase == "" {
return errors.New("monitor store database name must not be empty")
}
return nil
}

View File

@ -28,3 +28,25 @@ store-interval="10m"
t.Fatalf("unexpected store-interval: %s", c.StoreInterval)
}
}
func TestConfig_Validate(t *testing.T) {
// NewConfig must validate correctly.
c := monitor.NewConfig()
if err := c.Validate(); err != nil {
t.Fatalf("unexpected validation error: %s", err)
}
// Non-positive duration is invalid.
c = monitor.NewConfig()
c.StoreInterval *= 0
if err := c.Validate(); err == nil {
t.Fatalf("unexpected successful validation for %#v", c)
}
// Empty database is invalid.
c = monitor.NewConfig()
c.StoreDatabase = ""
if err := c.Validate(); err == nil {
t.Fatalf("unexpected successful validation for %#v", c)
}
}