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

Function Test_parseInsightsStartAndEndTime

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

Source from the content-addressed store, hash-verified

13)
14
15func Test_parseInsightsStartAndEndTime(t *testing.T) {
16 t.Parallel()
17
18 t.Logf("machine location: %s", time.Now().Location())
19 layout := insightsTimeLayout
20 now := time.Now().UTC()
21 t.Logf("now: %s", now)
22 t.Logf("now location: %s", now.Location())
23 y, m, d := now.Date()
24 today := time.Date(y, m, d, 0, 0, 0, 0, time.UTC)
25 t.Logf("today: %s", today)
26 thisHour := time.Date(y, m, d, now.Hour(), 0, 0, 0, time.UTC)
27 t.Logf("thisHour: %s", thisHour)
28 thisHourRoundUp := thisHour.Add(time.Hour)
29 t.Logf("thisHourRoundUp: %s", thisHourRoundUp)
30
31 helsinki, err := time.LoadLocation("Europe/Helsinki")
32 require.NoError(t, err)
33
34 type args struct {
35 startTime string
36 endTime string
37 }
38 tests := []struct {
39 name string
40 args args
41 wantStartTime time.Time
42 wantEndTime time.Time
43 wantOk bool
44 }{
45 {
46 name: "Same",
47 args: args{
48 startTime: "2023-07-10T00:00:00Z",
49 endTime: "2023-07-10T00:00:00Z",
50 },
51 wantStartTime: time.Date(2023, 7, 10, 0, 0, 0, 0, time.UTC),
52 wantEndTime: time.Date(2023, 7, 10, 0, 0, 0, 0, time.UTC),
53 wantOk: true,
54 },
55 {
56 name: "Week",
57 args: args{
58 startTime: "2023-07-10T00:00:00Z",
59 endTime: "2023-07-17T00:00:00Z",
60 },
61 wantStartTime: time.Date(2023, 7, 10, 0, 0, 0, 0, time.UTC),
62 wantEndTime: time.Date(2023, 7, 17, 0, 0, 0, 0, time.UTC),
63 wantOk: true,
64 },
65 {
66 name: "Today",
67 args: args{
68 startTime: today.Format(layout),
69 endTime: thisHour.Format(layout),
70 },
71 wantStartTime: time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, time.UTC),
72 wantEndTime: time.Date(today.Year(), today.Month(), today.Day(), thisHour.Hour(), 0, 0, 0, time.UTC),

Callers

nothing calls this directly

Calls 10

LocationMethod · 0.80
LogMethod · 0.80
LogfMethod · 0.65
AddMethod · 0.65
FormatMethod · 0.65
RunMethod · 0.65
EqualMethod · 0.45
ResultMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected