- conga: TestOutcome*, TestCancelQueuedNeverRuns, TestCancelRunningCancelsCtx, TestStopJobFromWorker, TestManagerPHPSemantics, principal, delay, registration, worker and queue-setting branches; TestQueueClear and TestQueueWork move to commands_test.go with the batch/state and queue-filter cases (coverage 92.5%) - scheduler: validation, ordering, missing catalog, log writer, dueAt - lagoon: TestQueueMigrationsUpDown (River v7 + summer_jobs, rollback, idempotent rerun), OnDatabase isolation, Transaction edges - bonfire TestCallEdges, pact TestCadence
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
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()}}
|
|
}
|