package governance import ( "testing" "time" ) // TestTimingHoldsChangingActionsOutsideTheSchedule guards the schedule's // reading: business hours in the organisation's zone, an overnight window, and // a blackout that holds inside business hours. func TestTimingHoldsChangingActionsOutsideTheSchedule(t *testing.T) { at := func(s string) time.Time { v, err := time.Parse(time.RFC3339, s) if err != nil { t.Fatal(err) } return v } office := Timing{Start: "09:00", End: "17:00", Days: []string{"mon", "tue", "wed", "thu", "fri"}} night := Timing{Start: "22:00", End: "06:00"} release := Timing{Blackouts: []Blackout{{From: at("2026-11-17T00:00:00Z"), To: at("2026-11-18T00:00:00Z"), Reason: "release"}}} zoned := Timing{Zone: "UTC", Start: "09:00", End: "17:00"} tests := []struct { name string t Timing now string held bool }{ {"nothing set", Timing{}, "2026-11-17T03:00:00Z", false}, {"inside business hours", office, "2026-11-17T10:00:00Z", false}, {"before business hours", office, "2026-11-17T08:59:00Z", true}, {"at close", office, "2026-11-17T17:00:00Z", true}, {"a weekend", office, "2026-11-15T10:00:00Z", true}, {"overnight window, late", night, "2026-11-17T23:00:00Z", false}, {"overnight window, early", night, "2026-11-17T05:00:00Z", false}, {"overnight window, midday", night, "2026-11-17T12:00:00Z", true}, {"inside a blackout", release, "2026-11-17T12:00:00Z", true}, {"after a blackout", release, "2026-11-18T00:00:00Z", false}, {"zone given", zoned, "2026-11-17T18:00:00Z", true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if reason, held := tt.t.Hold(at(tt.now)); held != tt.held { t.Errorf("held = %v (%s), want %v", held, reason, tt.held) } }) } }