Skip to content

Commit

Permalink
Unit-test retention config
Browse files Browse the repository at this point in the history
  • Loading branch information
otoolep committed Jun 5, 2015
1 parent 1e62b2b commit ad24a81
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
8 changes: 5 additions & 3 deletions services/retention/config.go
Original file line number Diff line number Diff line change
@@ -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"`
}
27 changes: 27 additions & 0 deletions services/retention/config_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
2 changes: 1 addition & 1 deletion services/retention/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down

0 comments on commit ad24a81

Please sign in to comment.