Skip to content

Commit bd15af7

Browse files
committed
add parameter test
1 parent 6d60f76 commit bd15af7

File tree

2 files changed

+172
-0
lines changed

2 files changed

+172
-0
lines changed

coderd/insights_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,29 @@ func TestTemplateInsights_Golden(t *testing.T) {
12021202
},
12031203
},
12041204
},
1205+
{
1206+
name: "parameters",
1207+
makeTestData: func(templates []*testTemplate, users []*testUser) map[*testWorkspace]testDataGen {
1208+
return map[*testWorkspace]testDataGen{}
1209+
},
1210+
requests: []testRequest{
1211+
{
1212+
// Since workspaces are created "now", we can only get
1213+
// parameters using a time range that includes "now".
1214+
// We check yesterday and today for stability just in case
1215+
// the test runs at UTC midnight.
1216+
name: "yesterday and today deployment wide",
1217+
ignoreTimes: true,
1218+
makeRequest: func(_ []*testTemplate) codersdk.TemplateInsightsRequest {
1219+
now := time.Now().UTC()
1220+
return codersdk.TemplateInsightsRequest{
1221+
StartTime: now.Truncate(24*time.Hour).AddDate(0, 0, -1),
1222+
EndTime: now.Truncate(time.Hour).Add(time.Hour),
1223+
}
1224+
},
1225+
},
1226+
},
1227+
},
12051228
}
12061229

12071230
for _, tt := range tests {
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"report": {
3+
"start_time": "0001-01-01T00:00:00Z",
4+
"end_time": "0001-01-01T00:00:00Z",
5+
"template_ids": [],
6+
"active_users": 0,
7+
"apps_usage": [
8+
{
9+
"template_ids": [],
10+
"type": "builtin",
11+
"display_name": "Visual Studio Code",
12+
"slug": "vscode",
13+
"icon": "/icon/code.svg",
14+
"seconds": 0
15+
},
16+
{
17+
"template_ids": [],
18+
"type": "builtin",
19+
"display_name": "JetBrains",
20+
"slug": "jetbrains",
21+
"icon": "/icon/intellij.svg",
22+
"seconds": 0
23+
},
24+
{
25+
"template_ids": [],
26+
"type": "builtin",
27+
"display_name": "Web Terminal",
28+
"slug": "reconnecting-pty",
29+
"icon": "/icon/terminal.svg",
30+
"seconds": 0
31+
},
32+
{
33+
"template_ids": [],
34+
"type": "builtin",
35+
"display_name": "SSH",
36+
"slug": "ssh",
37+
"icon": "/icon/terminal.svg",
38+
"seconds": 0
39+
}
40+
],
41+
"parameters_usage": [
42+
{
43+
"template_ids": [
44+
"00000000-0000-0000-0000-000000000003"
45+
],
46+
"display_name": "otherparam1",
47+
"name": "otherparam1",
48+
"type": "string",
49+
"description": "This is another parameter",
50+
"values": [
51+
{
52+
"value": "",
53+
"count": 1
54+
},
55+
{
56+
"value": "xyz",
57+
"count": 1
58+
}
59+
]
60+
},
61+
{
62+
"template_ids": [
63+
"00000000-0000-0000-0000-000000000001",
64+
"00000000-0000-0000-0000-000000000002"
65+
],
66+
"display_name": "param1",
67+
"name": "param1",
68+
"type": "string",
69+
"description": "This is first parameter",
70+
"values": [
71+
{
72+
"value": "abc",
73+
"count": 2
74+
},
75+
{
76+
"value": "ABC",
77+
"count": 1
78+
}
79+
]
80+
},
81+
{
82+
"template_ids": [
83+
"00000000-0000-0000-0000-000000000001",
84+
"00000000-0000-0000-0000-000000000002"
85+
],
86+
"display_name": "param2",
87+
"name": "param2",
88+
"type": "string",
89+
"description": "This is second parameter",
90+
"values": [
91+
{
92+
"value": "123",
93+
"count": 3
94+
}
95+
]
96+
},
97+
{
98+
"template_ids": [
99+
"00000000-0000-0000-0000-000000000001",
100+
"00000000-0000-0000-0000-000000000002"
101+
],
102+
"display_name": "param3",
103+
"name": "param3",
104+
"type": "string",
105+
"description": "This is third parameter",
106+
"values": [
107+
{
108+
"value": "bbb",
109+
"count": 1
110+
},
111+
{
112+
"value": "BBB",
113+
"count": 2
114+
}
115+
]
116+
},
117+
{
118+
"template_ids": [
119+
"00000000-0000-0000-0000-000000000001"
120+
],
121+
"display_name": "param4",
122+
"name": "param4",
123+
"type": "string",
124+
"description": "This is fourth parameter",
125+
"options": [
126+
{
127+
"name": "option1",
128+
"description": "",
129+
"value": "option1",
130+
"icon": ""
131+
},
132+
{
133+
"name": "option2",
134+
"description": "",
135+
"value": "option2",
136+
"icon": ""
137+
}
138+
],
139+
"values": [
140+
{
141+
"value": "option1",
142+
"count": 2
143+
}
144+
]
145+
}
146+
]
147+
},
148+
"interval_reports": []
149+
}

0 commit comments

Comments
 (0)