mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
config test and validate
This commit is contained in:
parent
9c561f4e4b
commit
baff53ae3d
3 changed files with 43 additions and 1 deletions
20
config.go
20
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
|
||||
|
||||
|
|
|
|||
18
config_test.go
Normal file
18
config_test.go
Normal 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"
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue