From ad24a811395888482d1eb9a961baf2815510aa1e Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Thu, 4 Jun 2015 21:36:16 -0700 Subject: [PATCH] Unit-test retention config --- services/retention/config.go | 8 +++++--- services/retention/config_test.go | 27 +++++++++++++++++++++++++++ services/retention/service.go | 2 +- 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 services/retention/config_test.go diff --git a/services/retention/config.go b/services/retention/config.go index a8a29ef8580..6bdbf26036a 100644 --- a/services/retention/config.go +++ b/services/retention/config.go @@ -1,8 +1,10 @@ package retention -import "time" +import ( + "github.com/influxdb/influxdb/toml" +) type Config struct { - Enabled bool - CheckInterval time.Duration + Enabled bool `toml:"enabled"` + CheckInterval toml.Duration `toml:"check-interval"` } diff --git a/services/retention/config_test.go b/services/retention/config_test.go new file mode 100644 index 00000000000..c1bbca90dc5 --- /dev/null +++ b/services/retention/config_test.go @@ -0,0 +1,27 @@ +package retention_test + +import ( + "testing" + "time" + + "github.com/BurntSushi/toml" + "github.com/influxdb/influxdb/services/retention" +) + +func TestConfig_Parse(t *testing.T) { + // Parse configuration. + var c retention.Config + if _, err := toml.Decode(` +enabled = true +check-interval = "1s" +`, &c); err != nil { + t.Fatal(err) + } + + // Validate configuration. + if c.Enabled != true { + t.Fatalf("unexpected enabled state: %v", c.Enabled) + } else if time.Duration(c.CheckInterval) != time.Second { + t.Fatalf("unexpected check interval: %v", c.CheckInterval) + } +} diff --git a/services/retention/service.go b/services/retention/service.go index 883c6069808..103fdfb847c 100644 --- a/services/retention/service.go +++ b/services/retention/service.go @@ -35,7 +35,7 @@ type Service struct { func NewService(c Config) *Service { return &Service{ enabled: c.Enabled, - checkInterval: c.CheckInterval, + checkInterval: time.Duration(c.CheckInterval), done: make(chan struct{}), logger: log.New(os.Stderr, "[retention] ", log.LstdFlags), }