package pact import ( "testing" "time" ) // TestCadence covers the schedule cadence constructors and accessors. func TestCadence(t *testing.T) { cases := []struct { name string c Cadence zero bool interval time.Duration hour int minute int daily bool }{ {"zero", Cadence{}, true, 0, 0, 0, false}, {"daily", Daily(), false, 24 * time.Hour, 0, 0, true}, {"daily_at", DailyAt(3, 45), false, 24 * time.Hour, 3, 45, true}, {"every", Every(5 * time.Minute), false, 5 * time.Minute, 0, 0, false}, {"every_zero", Every(0), false, 0, 0, 0, false}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { if c.c.IsZero() != c.zero { t.Errorf("IsZero = %v", c.c.IsZero()) } if c.c.Interval() != c.interval { t.Errorf("Interval = %s, want %s", c.c.Interval(), c.interval) } h, m, ok := c.c.At() if ok != c.daily || h != c.hour || m != c.minute { t.Errorf("At = %d:%d %v, want %d:%d %v", h, m, ok, c.hour, c.minute, c.daily) } }) } var _ HasSchedule = scheduleOnly{} if got := (scheduleOnly{}).Schedule(); len(got) != 1 || got[0].Command != "acme:prune" || got[0].Cadence != Daily() { t.Fatalf("Schedule = %+v", got) } } type scheduleOnly struct{} func (scheduleOnly) Schedule() []ScheduledCommand { return []ScheduledCommand{{Command: "acme:prune", Cadence: Daily()}} }