47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/samcharles93/archipelago/sdk/guard"
|
|
)
|
|
|
|
// TestJudgeHoldsChangesOutsideBusinessHours guards the guard's one job: a
|
|
// change outside the configured hours is held, a read never is.
|
|
func TestJudgeHoldsChangesOutsideBusinessHours(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
settings map[string]string
|
|
at time.Time
|
|
readOnly bool
|
|
want guard.Ceiling
|
|
}{
|
|
{name: "a weekday morning acts quietly", at: time.Date(2026, 11, 16, 10, 0, 0, 0, time.UTC), want: guard.ActQuietly},
|
|
{name: "a weekday night is held", at: time.Date(2026, 11, 16, 22, 0, 0, 0, time.UTC), want: guard.ProposeAndWait},
|
|
{name: "a weekend is held", at: time.Date(2026, 11, 15, 10, 0, 0, 0, time.UTC), want: guard.ProposeAndWait},
|
|
{name: "a read is never held", at: time.Date(2026, 11, 15, 3, 0, 0, 0, time.UTC), readOnly: true, want: guard.ActQuietly},
|
|
{
|
|
name: "the timezone decides the hour",
|
|
settings: map[string]string{"timezone": "Australia/Sydney"},
|
|
at: time.Date(2026, 11, 16, 10, 0, 0, 0, time.UTC),
|
|
want: guard.ProposeAndWait,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
g, err := build(guard.Config{Settings: tt.settings})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
v, err := g.Judge(t.Context(), guard.Action{At: tt.at, Effect: guard.Effect{ReadOnly: tt.readOnly}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v.Ceiling != tt.want {
|
|
t.Fatalf("ceiling = %d, want %d", v.Ceiling, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|