config test and validate

This commit is contained in:
Michael Baird 2017-07-11 11:31:27 -05:00
parent 9c561f4e4b
commit baff53ae3d
3 changed files with 43 additions and 1 deletions

View file

@ -89,6 +89,26 @@ func NewConfig() *Config {
return c
}
// Validate that all configuration permutations are compatible with each other.
func (c *Config) Validate() error {
if !foundItem(c.Cluster.Hosts, c.Bind) {
return ErrConfigHosts
}
// Validate cluster types
// TODO cluster types
// TODO validate len hosts
// TODO vaidate replica num and host len
// TODO internal-hosts and hosts len must match
if c.Cluster.Type == "http" || c.Cluster.Type == "gossip" {
if !ContainsSubstring(c.Cluster.InternalPort, c.Cluster.InternalHosts) {
return ErrConfigBroadcastPort
}
}
return nil
}
// Duration is a TOML wrapper type for time.Duration.
type Duration time.Duration

18
config_test.go Normal file
View file

@ -0,0 +1,18 @@
package pilosa_test
import (
"testing"
"github.com/pilosa/pilosa"
)
func Test_NewConfig(t *testing.T) {
x := pilosa.NewConfig()
// Check for bind addres in cluster hosts
if err := x.Validate(); err != pilosa.ErrConfigHosts {
t.Fatal(err)
}
x.Cluster.Type = "http"
}

View file

@ -107,7 +107,11 @@ func (m *Command) Run(args ...string) (err error) {
// SetupServer use the cluster configuration to setup this server
func (m *Command) SetupServer() error {
var err error
err := m.Config.Validate()
if err != nil {
return err
}
cluster := pilosa.NewCluster()
cluster.ReplicaN = m.Config.Cluster.ReplicaN