MCPcopy Index your code
hub / github.com/coder/coder / Test_parseInsightsInterval_week

Function Test_parseInsightsInterval_week

coderd/insights_internal_test.go:177–282  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

175}
176
177func Test_parseInsightsInterval_week(t *testing.T) {
178 t.Parallel()
179
180 layout := insightsTimeLayout
181 losAngelesLoc, err := time.LoadLocation("America/Los_Angeles") // Random location
182 require.NoError(t, err)
183
184 now := time.Now().In(losAngelesLoc)
185 t.Logf("now: %s", now)
186
187 y, m, d := now.Date()
188 today := time.Date(y, m, d, 0, 0, 0, 0, losAngelesLoc)
189 t.Logf("today: %s", today)
190
191 thisHour := time.Date(y, m, d, now.Hour(), 0, 0, 0, losAngelesLoc)
192 t.Logf("thisHour: %s", thisHour)
193 twoHoursAgo := thisHour.Add(-2 * time.Hour)
194 t.Logf("twoHoursAgo: %s", twoHoursAgo)
195 thirteenDaysAgo := today.AddDate(0, 0, -13)
196 t.Logf("thirteenDaysAgo: %s", thirteenDaysAgo)
197
198 sixDaysAgo := today.AddDate(0, 0, -6)
199 t.Logf("sixDaysAgo: %s", sixDaysAgo)
200 nineDaysAgo := today.AddDate(0, 0, -9)
201 t.Logf("nineDaysAgo: %s", nineDaysAgo)
202
203 type args struct {
204 startTime string
205 endTime string
206 }
207 tests := []struct {
208 name string
209 args args
210 wantOk bool
211 }{
212 {
213 name: "Two full weeks",
214 args: args{
215 startTime: "2023-08-10T00:00:00+02:00",
216 endTime: "2023-08-24T00:00:00+02:00",
217 },
218 wantOk: true,
219 },
220 {
221 name: "One full week",
222 args: args{
223 startTime: "2023-09-06T00:00:00+02:00",
224 endTime: "2023-09-13T00:00:00+02:00",
225 },
226 wantOk: true,
227 },
228 /* FIXME: daylight savings issue
229 {
230 name: "6 days are acceptable",
231 args: args{
232 startTime: sixDaysAgo.Format(layout),
233 endTime: stripTime(thisHour).Format(layout),
234 },

Callers

nothing calls this directly

Calls 11

stripTimeFunction · 0.85
parseInsightsIntervalFunction · 0.85
LogMethod · 0.80
LogfMethod · 0.65
AddMethod · 0.65
FormatMethod · 0.65
RunMethod · 0.65
ResultMethod · 0.45
StringMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected