package playlists import ( "testing" ) func TestValidateTimezone_Valid(t *testing.T) { cases := []string{"UTC", "America/New_York", "Europe/London", "Asia/Tokyo"} for _, tz := range cases { t.Run(tz, func(t *testing.T) { loc, err := validateTimezone(tz) if err != nil { t.Fatalf("validateTimezone(%q): %v", tz, err) } if loc == nil { t.Fatalf("validateTimezone(%q): nil location", tz) } }) } } func TestValidateTimezone_Invalid(t *testing.T) { cases := []string{"", "Not/A/Zone", "GMT+5", "EST5EDT-not-iana"} for _, tz := range cases { t.Run(tz, func(t *testing.T) { _, err := validateTimezone(tz) if err == nil { t.Fatalf("validateTimezone(%q): expected error, got nil", tz) } }) } } func TestValidateTimezoneOrUTC_FallbackToUTC(t *testing.T) { // validateTimezoneOrUTC returns UTC for any unparseable input. // Used by the scheduler when reading stored timezones — corrupted // DB values should not crash; they should fall back to UTC. loc := validateTimezoneOrUTC("Not/A/Zone") if loc.String() != "UTC" { t.Errorf("expected UTC fallback for invalid input, got %s", loc) } // Valid input returns the named location, not UTC. loc = validateTimezoneOrUTC("America/New_York") if loc.String() == "UTC" { t.Errorf("valid input incorrectly fell back to UTC") } if loc.String() != "America/New_York" { t.Errorf("expected America/New_York, got %s", loc) } }