Skip to content

feat(coderd): support weekly aggregated insights #9684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Sep 19, 2023
Prev Previous commit
test: dst vs. 6 days
  • Loading branch information
mtojek committed Sep 19, 2023
commit 7e14a1ffd5f9dd05bb380bec6409849a7d971f0e
50 changes: 50 additions & 0 deletions coderd/insights_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,53 @@ func Test_parseInsightsInterval_week(t *testing.T) {
})
}
}

func TestLastReportIntervalHasAtLeastSixDays(t *testing.T) {
t.Parallel()

loc, err := time.LoadLocation("Europe/Warsaw")
require.NoError(t, err)

testCases := []struct {
name string
startTime time.Time
endTime time.Time
expected bool
}{
{
name: "perfectly full week",
startTime: time.Date(2023, time.September, 11, 12, 0, 0, 0, loc),
endTime: time.Date(2023, time.September, 18, 12, 0, 0, 0, loc),
expected: true,
},
{
name: "exactly 6 days apart",
startTime: time.Date(2023, time.September, 11, 12, 0, 0, 0, loc),
endTime: time.Date(2023, time.September, 17, 12, 0, 0, 0, loc),
expected: true,
},
{
name: "less than 6 days apart",
startTime: time.Date(2023, time.September, 11, 12, 0, 0, 0, time.UTC),
endTime: time.Date(2023, time.September, 17, 11, 0, 0, 0, time.UTC),
expected: false,
},
{
name: "forward DST change, 5 days and 23 hours apart",
startTime: time.Date(2023, time.March, 22, 12, 0, 0, 0, loc), // A day before DST starts
endTime: time.Date(2023, time.March, 28, 12, 0, 0, 0, loc), // Exactly 6 "days" apart
expected: true,
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
result := lastReportIntervalHasAtLeastSixDays(tc.startTime, tc.endTime)
if result != tc.expected {
t.Errorf("Expected %v, but got %v for start time %v and end time %v", tc.expected, result, tc.startTime, tc.endTime)
}
})
}
}