package qaopsmirror import ( "testing" "time" ) func monthlyTestTime(t *testing.T, value string) time.Time { t.Helper() at, err := time.Parse(time.RFC3339, value) if err != nil { t.Fatal(err) } return at } func TestQualityMonthCrossingWeekIsPreviousMonthReport(t *testing.T) { for _, c := range []struct{ name, start, end, now, wantStart, wantEnd string }{ {"cross-month", "2026-09-28T00:00:00+08:00", "2026-10-05T00:00:00+08:00", "2026-10-21T08:00:00+08:00", "2026-09-01T00:00:00+08:00", "2026-10-01T00:00:00+08:00"}, {"within-month", "2026-10-05T00:00:00+08:00", "2026-10-12T00:00:00+08:00", "2026-10-21T08:00:00+08:00", "2026-10-01T00:00:00+08:00", "2026-10-12T00:00:00+08:00"}, {"current-week-clamps-now", "2026-10-19T00:00:00+08:00", "2026-10-26T00:00:00+08:00", "2026-10-21T08:00:00+08:00", "2026-10-01T00:00:00+08:00", "2026-10-21T08:00:00+08:00"}, {"cross-year", "2025-12-29T00:00:00+08:00", "2026-01-05T00:00:00+08:00", "2026-10-21T08:00:00+08:00", "2025-12-01T00:00:00+08:00", "2026-01-01T00:00:00+08:00"}, {"utc-same-boundary", "2026-09-27T16:00:00Z", "2026-10-04T16:00:00Z", "2026-10-21T00:00:00Z", "2026-09-01T00:00:00+08:00", "2026-10-01T00:00:00+08:00"}, {"crossing-week-before-month-complete", "2026-09-28T00:00:00+08:00", "2026-09-29T08:00:00+08:00", "2026-09-29T08:00:00+08:00", "2026-09-01T00:00:00+08:00", "2026-09-29T08:00:00+08:00"}, } { t.Run(c.name, func(t *testing.T) { begin, end := dashboardQualityMonth(monthlyTestTime(t, c.start), monthlyTestTime(t, c.end), monthlyTestTime(t, c.now)) if !begin.Equal(monthlyTestTime(t, c.wantStart)) || !end.Equal(monthlyTestTime(t, c.wantEnd)) { t.Fatalf("quality month = [%s,%s), want [%s,%s)", begin, end, c.wantStart, c.wantEnd) } }) } }