1package retention_test 2 3import ( 4 "testing" 5 "time" 6 7 "github.com/BurntSushi/toml" 8 "github.com/influxdata/influxdb/services/retention" 9) 10 11func TestConfig_Parse(t *testing.T) { 12 // Parse configuration. 13 var c retention.Config 14 if _, err := toml.Decode(` 15enabled = true 16check-interval = "1s" 17`, &c); err != nil { 18 t.Fatal(err) 19 } 20 21 // Validate configuration. 22 if !c.Enabled { 23 t.Fatalf("unexpected enabled state: %v", c.Enabled) 24 } else if time.Duration(c.CheckInterval) != time.Second { 25 t.Fatalf("unexpected check interval: %v", c.CheckInterval) 26 } 27} 28 29func TestConfig_Validate(t *testing.T) { 30 c := retention.NewConfig() 31 if err := c.Validate(); err != nil { 32 t.Fatalf("unexpected validation fail from NewConfig: %s", err) 33 } 34 35 c = retention.NewConfig() 36 c.CheckInterval = 0 37 if err := c.Validate(); err == nil { 38 t.Fatal("expected error for check-interval = 0, got nil") 39 } 40 41 c = retention.NewConfig() 42 c.CheckInterval *= -1 43 if err := c.Validate(); err == nil { 44 t.Fatal("expected error for negative check-interval, got nil") 45 } 46 47 c.Enabled = false 48 if err := c.Validate(); err != nil { 49 t.Fatalf("unexpected validation fail from disabled config: %s", err) 50 } 51} 52