From baff53ae3d811bb6053d5ffec363dcb50cdba6dc Mon Sep 17 00:00:00 2001 From: Michael Baird Date: Tue, 11 Jul 2017 11:31:27 -0500 Subject: [PATCH] config test and validate --- config.go | 20 ++++++++++++++++++++ config_test.go | 18 ++++++++++++++++++ server/server.go | 6 +++++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 config_test.go diff --git a/config.go b/config.go index b6961850b..b926a44fa 100644 --- a/config.go +++ b/config.go @@ -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 diff --git a/config_test.go b/config_test.go new file mode 100644 index 000000000..1109f1436 --- /dev/null +++ b/config_test.go @@ -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" +} diff --git a/server/server.go b/server/server.go index fd4462be9..3133dac05 100644 --- a/server/server.go +++ b/server/server.go @@ -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