@@ -186,6 +186,31 @@ func TestUserLatencyInsights(t *testing.T) {
186
186
assert .Nil (t , userLatencies .Report .Users [1 ].LatencyMS , "want user 2 to have no latency" )
187
187
}
188
188
189
+ func TestUserLatencyInsights_BadRequest (t * testing.T ) {
190
+ t .Parallel ()
191
+
192
+ client := coderdtest .New (t , & coderdtest.Options {})
193
+ _ = coderdtest .CreateFirstUser (t , client )
194
+
195
+ y , m , d := time .Now ().Date ()
196
+ today := time .Date (y , m , d , 0 , 0 , 0 , 0 , time .UTC )
197
+
198
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
199
+ defer cancel ()
200
+
201
+ _ , err := client .UserLatencyInsights (ctx , codersdk.UserLatencyInsightsRequest {
202
+ StartTime : today ,
203
+ EndTime : today .AddDate (0 , 0 , - 1 ),
204
+ })
205
+ assert .Error (t , err , "want error for end time before start time" )
206
+
207
+ _ , err = client .UserLatencyInsights (ctx , codersdk.UserLatencyInsightsRequest {
208
+ StartTime : today .AddDate (0 , 0 , - 7 ),
209
+ EndTime : today .Add (- time .Hour ),
210
+ })
211
+ assert .Error (t , err , "want error for end time partial day when not today" )
212
+ }
213
+
189
214
func TestTemplateInsights (t * testing.T ) {
190
215
t .Parallel ()
191
216
@@ -303,3 +328,35 @@ func TestTemplateInsights(t *testing.T) {
303
328
assert .WithinDuration (t , req .EndTime , resp .IntervalReports [0 ].EndTime , 0 )
304
329
assert .Equal (t , resp .IntervalReports [0 ].ActiveUsers , int64 (1 ), "want one active user in the interval report" )
305
330
}
331
+
332
+ func TestTemplateInsights_BadRequest (t * testing.T ) {
333
+ t .Parallel ()
334
+
335
+ client := coderdtest .New (t , & coderdtest.Options {})
336
+ _ = coderdtest .CreateFirstUser (t , client )
337
+
338
+ y , m , d := time .Now ().Date ()
339
+ today := time .Date (y , m , d , 0 , 0 , 0 , 0 , time .UTC )
340
+
341
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
342
+ defer cancel ()
343
+
344
+ _ , err := client .TemplateInsights (ctx , codersdk.TemplateInsightsRequest {
345
+ StartTime : today ,
346
+ EndTime : today .AddDate (0 , 0 , - 1 ),
347
+ })
348
+ assert .Error (t , err , "want error for end time before start time" )
349
+
350
+ _ , err = client .TemplateInsights (ctx , codersdk.TemplateInsightsRequest {
351
+ StartTime : today .AddDate (0 , 0 , - 7 ),
352
+ EndTime : today .Add (- time .Hour ),
353
+ })
354
+ assert .Error (t , err , "want error for end time partial day when not today" )
355
+
356
+ _ , err = client .TemplateInsights (ctx , codersdk.TemplateInsightsRequest {
357
+ StartTime : today .AddDate (0 , 0 , - 1 ),
358
+ EndTime : today ,
359
+ Interval : "invalid" ,
360
+ })
361
+ assert .Error (t , err , "want error for bad interval" )
362
+ }
0 commit comments