Ensure config contains valid index

pull/7976/head
Edd Robinson 2017-02-03 11:57:41 +00:00
parent 908959a78a
commit 54193e1131
2 changed files with 27 additions and 0 deletions

View File

@ -119,5 +119,16 @@ func (c *Config) Validate() error {
return fmt.Errorf("unrecognized engine %s", c.Engine)
}
valid = false
for _, e := range RegisteredIndexes() {
if e == c.Index {
valid = true
break
}
}
if !valid {
return fmt.Errorf("unrecognized index %s", c.Index)
}
return nil
}

View File

@ -45,4 +45,20 @@ func TestConfig_Validate_Error(t *testing.T) {
if err := c.Validate(); err == nil || err.Error() != "unrecognized engine fake1" {
t.Errorf("unexpected error: %s", err)
}
c.Engine = "tsm1"
c.Index = "foo"
if err := c.Validate(); err == nil || err.Error() != "unrecognized index foo" {
t.Errorf("unexpected error: %s", err)
}
c.Index = "inmem"
if err := c.Validate(); err != nil {
t.Error(err)
}
c.Index = "tsi1"
if err := c.Validate(); err != nil {
t.Error(err)
}
}