Skip to content

Commit 782da3a

Browse files
committed
add sao paulo tz test (invalid interval times)
1 parent db6ae5a commit 782da3a

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

coderd/insights_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,11 @@ func TestTemplateInsights_Golden(t *testing.T) {
10371037
lastNight := time.Now().UTC().Truncate(24 * time.Hour)
10381038
weekAgo := lastNight.AddDate(0, 0, -7)
10391039

1040+
saoPaulo, err := time.LoadLocation("America/Sao_Paulo")
1041+
require.NoError(t, err)
1042+
weekAgoSaoPaulo, err := time.ParseInLocation(time.DateTime, weekAgo.Format(time.DateTime), saoPaulo)
1043+
require.NoError(t, err)
1044+
10401045
makeBaseTestData := func(templates []*testTemplate, users []*testUser) map[*testWorkspace]testDataGen {
10411046
return map[*testWorkspace]testDataGen{
10421047
users[0].workspaces[0]: {
@@ -1187,6 +1192,18 @@ func TestTemplateInsights_Golden(t *testing.T) {
11871192
}
11881193
},
11891194
},
1195+
{
1196+
// São Paulo is three hours behind UTC, so we should not see
1197+
// any data between weekAgo and weekAgo.Add(3 * time.Hour).
1198+
name: "week other timezone (São Paulo)",
1199+
makeRequest: func(templates []*testTemplate) codersdk.TemplateInsightsRequest {
1200+
return codersdk.TemplateInsightsRequest{
1201+
StartTime: weekAgoSaoPaulo,
1202+
EndTime: weekAgoSaoPaulo.AddDate(0, 0, 7),
1203+
Interval: codersdk.InsightsReportIntervalDay,
1204+
}
1205+
},
1206+
},
11901207
},
11911208
},
11921209
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
{
2+
"report": {
3+
"start_time": "2023-08-15T00:00:00-03:00",
4+
"end_time": "2023-08-22T00:00:00-03:00",
5+
"template_ids": [
6+
"00000000-0000-0000-0000-000000000001",
7+
"00000000-0000-0000-0000-000000000002"
8+
],
9+
"active_users": 1,
10+
"apps_usage": [
11+
{
12+
"template_ids": [
13+
"00000000-0000-0000-0000-000000000001"
14+
],
15+
"type": "builtin",
16+
"display_name": "Visual Studio Code",
17+
"slug": "vscode",
18+
"icon": "/icon/code.svg",
19+
"seconds": 0
20+
},
21+
{
22+
"template_ids": [
23+
"00000000-0000-0000-0000-000000000001"
24+
],
25+
"type": "builtin",
26+
"display_name": "JetBrains",
27+
"slug": "jetbrains",
28+
"icon": "/icon/intellij.svg",
29+
"seconds": 600
30+
},
31+
{
32+
"template_ids": [
33+
"00000000-0000-0000-0000-000000000001"
34+
],
35+
"type": "builtin",
36+
"display_name": "Web Terminal",
37+
"slug": "reconnecting-pty",
38+
"icon": "/icon/terminal.svg",
39+
"seconds": 0
40+
},
41+
{
42+
"template_ids": [
43+
"00000000-0000-0000-0000-000000000001"
44+
],
45+
"type": "builtin",
46+
"display_name": "SSH",
47+
"slug": "ssh",
48+
"icon": "/icon/terminal.svg",
49+
"seconds": 900
50+
},
51+
{
52+
"template_ids": [
53+
"00000000-0000-0000-0000-000000000002"
54+
],
55+
"type": "app",
56+
"display_name": "app1",
57+
"slug": "app1",
58+
"icon": "/icon1.png",
59+
"seconds": 21600
60+
},
61+
{
62+
"template_ids": [
63+
"00000000-0000-0000-0000-000000000001"
64+
],
65+
"type": "app",
66+
"display_name": "app3",
67+
"slug": "app3",
68+
"icon": "/icon2.png",
69+
"seconds": 900
70+
}
71+
],
72+
"parameters_usage": []
73+
},
74+
"interval_reports": [
75+
{
76+
"start_time": "2023-08-15T03:00:00Z",
77+
"end_time": "2023-08-16T03:00:00Z",
78+
"template_ids": [
79+
"00000000-0000-0000-0000-000000000001"
80+
],
81+
"interval": "day",
82+
"active_users": 1
83+
},
84+
{
85+
"start_time": "2023-08-16T03:00:00Z",
86+
"end_time": "2023-08-17T03:00:00Z",
87+
"template_ids": [
88+
"00000000-0000-0000-0000-000000000001",
89+
"00000000-0000-0000-0000-000000000002"
90+
],
91+
"interval": "day",
92+
"active_users": 1
93+
},
94+
{
95+
"start_time": "2023-08-17T03:00:00Z",
96+
"end_time": "2023-08-18T03:00:00Z",
97+
"template_ids": [
98+
"00000000-0000-0000-0000-000000000002"
99+
],
100+
"interval": "day",
101+
"active_users": 1
102+
},
103+
{
104+
"start_time": "2023-08-18T03:00:00Z",
105+
"end_time": "2023-08-19T03:00:00Z",
106+
"template_ids": [],
107+
"interval": "day",
108+
"active_users": 0
109+
},
110+
{
111+
"start_time": "2023-08-19T03:00:00Z",
112+
"end_time": "2023-08-20T03:00:00Z",
113+
"template_ids": [],
114+
"interval": "day",
115+
"active_users": 0
116+
},
117+
{
118+
"start_time": "2023-08-20T03:00:00Z",
119+
"end_time": "2023-08-21T03:00:00Z",
120+
"template_ids": [
121+
"00000000-0000-0000-0000-000000000001"
122+
],
123+
"interval": "day",
124+
"active_users": 1
125+
},
126+
{
127+
"start_time": "2023-08-21T03:00:00Z",
128+
"end_time": "2023-08-22T03:00:00Z",
129+
"template_ids": [],
130+
"interval": "day",
131+
"active_users": 0
132+
}
133+
]
134+
}

0 commit comments

Comments
 (0)