influxdb/cmd/influxd/run/config_test.go

189 lines
3.8 KiB
Go
Raw Normal View History

2015-05-28 21:47:47 +00:00
package run_test
2014-10-21 05:32:47 +00:00
import (
2015-08-09 22:14:10 +00:00
"os"
2014-10-21 05:32:47 +00:00
"testing"
2015-04-02 01:20:04 +00:00
"github.com/BurntSushi/toml"
"github.com/influxdata/influxdb/cmd/influxd/run"
2014-10-21 05:32:47 +00:00
)
2015-05-29 19:50:05 +00:00
// Ensure the configuration can be parsed.
func TestConfig_Parse(t *testing.T) {
// Parse configuration.
var c run.Config
if _, err := toml.Decode(`
join = "foo:123,bar:456"
2015-05-29 19:50:05 +00:00
[meta]
dir = "/tmp/meta"
2015-03-25 21:01:05 +00:00
2015-05-29 19:50:05 +00:00
[data]
dir = "/tmp/data"
2015-03-25 21:01:05 +00:00
2015-05-29 19:50:05 +00:00
[cluster]
2015-03-25 21:01:05 +00:00
[admin]
2015-05-29 19:50:05 +00:00
bind-address = ":8083"
[http]
2015-05-29 19:50:05 +00:00
bind-address = ":8087"
2015-03-25 21:01:05 +00:00
[[graphite]]
2015-05-29 19:50:05 +00:00
protocol = "udp"
2015-03-25 21:01:05 +00:00
[[graphite]]
2015-05-29 19:50:05 +00:00
protocol = "tcp"
2015-03-25 21:01:05 +00:00
[collectd]
2015-05-29 19:50:05 +00:00
bind-address = ":1000"
2015-03-25 21:01:05 +00:00
[opentsdb]
2015-05-29 19:50:05 +00:00
bind-address = ":2000"
2015-03-25 21:01:05 +00:00
[[udp]]
2015-06-03 13:06:36 +00:00
bind-address = ":4444"
2015-05-29 19:50:05 +00:00
[monitoring]
enabled = true
2015-03-25 21:01:05 +00:00
[subscriber]
enabled = true
2015-03-25 21:01:05 +00:00
[continuous_queries]
enabled = true
2015-05-29 19:50:05 +00:00
`, &c); err != nil {
t.Fatal(err)
}
// Validate configuration.
if c.Meta.Dir != "/tmp/meta" {
2015-05-29 19:50:05 +00:00
t.Fatalf("unexpected meta dir: %s", c.Meta.Dir)
} else if c.Data.Dir != "/tmp/data" {
t.Fatalf("unexpected data dir: %s", c.Data.Dir)
} else if c.Admin.BindAddress != ":8083" {
t.Fatalf("unexpected admin bind address: %s", c.Admin.BindAddress)
} else if c.HTTPD.BindAddress != ":8087" {
t.Fatalf("unexpected api bind address: %s", c.HTTPD.BindAddress)
} else if len(c.Graphites) != 2 {
t.Fatalf("unexpected graphites count: %d", len(c.Graphites))
} else if c.Graphites[0].Protocol != "udp" {
t.Fatalf("unexpected graphite protocol(0): %s", c.Graphites[0].Protocol)
} else if c.Graphites[1].Protocol != "tcp" {
t.Fatalf("unexpected graphite protocol(1): %s", c.Graphites[1].Protocol)
} else if c.Collectd.BindAddress != ":1000" {
t.Fatalf("unexpected collectd bind address: %s", c.Collectd.BindAddress)
} else if c.OpenTSDB.BindAddress != ":2000" {
t.Fatalf("unexpected opentsdb bind address: %s", c.OpenTSDB.BindAddress)
} else if c.UDPs[0].BindAddress != ":4444" {
t.Fatalf("unexpected udp bind address: %s", c.UDPs[0].BindAddress)
} else if c.Subscriber.Enabled != true {
t.Fatalf("unexpected subscriber enabled: %v", c.Subscriber.Enabled)
2015-05-29 19:50:05 +00:00
} else if c.ContinuousQuery.Enabled != true {
t.Fatalf("unexpected continuous query enabled: %v", c.ContinuousQuery.Enabled)
} else if exp, got := "foo:123,bar:456", c.Join; exp != got {
2016-02-22 22:05:15 +00:00
t.Fatalf("unexpected join value: got %v, exp %v", got, exp)
2015-01-09 17:44:11 +00:00
}
}
2015-08-09 22:14:10 +00:00
// Ensure the configuration can be parsed.
func TestConfig_Parse_EnvOverride(t *testing.T) {
// Parse configuration.
var c run.Config
if _, err := toml.Decode(`
[meta]
dir = "/tmp/meta"
[data]
dir = "/tmp/data"
[cluster]
[admin]
bind-address = ":8083"
[http]
bind-address = ":8087"
[[graphite]]
protocol = "udp"
[[graphite]]
protocol = "tcp"
[collectd]
bind-address = ":1000"
[opentsdb]
bind-address = ":2000"
2015-08-10 23:23:04 +00:00
[[udp]]
2015-08-09 22:14:10 +00:00
bind-address = ":4444"
[monitoring]
enabled = true
[continuous_queries]
enabled = true
`, &c); err != nil {
t.Fatal(err)
}
if err := os.Setenv("INFLUXDB_UDP_BIND_ADDRESS", ":1234"); err != nil {
t.Fatalf("failed to set env var: %v", err)
}
if err := os.Setenv("INFLUXDB_GRAPHITE_1_PROTOCOL", "udp"); err != nil {
t.Fatalf("failed to set env var: %v", err)
}
if err := c.ApplyEnvOverrides(); err != nil {
t.Fatalf("failed to apply env overrides: %v", err)
}
2015-08-10 23:23:04 +00:00
if c.UDPs[0].BindAddress != ":4444" {
t.Fatalf("unexpected udp bind address: %s", c.UDPs[0].BindAddress)
}
if c.Graphites[1].Protocol != "udp" {
2015-08-09 22:14:10 +00:00
t.Fatalf("unexpected graphite protocol(0): %s", c.Graphites[0].Protocol)
}
}
func TestConfig_ValidateNoServiceConfigured(t *testing.T) {
var c run.Config
if _, err := toml.Decode(`
[meta]
enabled = false
[data]
enabled = false
`, &c); err != nil {
t.Fatal(err)
}
if e := c.Validate(); e == nil {
2016-02-22 22:05:15 +00:00
t.Fatalf("got nil, expected error")
}
}
func TestConfig_ValidateMonitorStore_MetaOnly(t *testing.T) {
c := run.NewConfig()
if _, err := toml.Decode(`
[monitor]
store-enabled = true
[meta]
dir = "foo"
[data]
enabled = false
`, &c); err != nil {
t.Fatal(err)
}
if err := c.Validate(); err == nil {
2016-02-22 22:05:15 +00:00
t.Fatalf("got nil, expected error")
}
}