@@ -37,8 +37,7 @@ func TestTemplate(t *testing.T) {
37
37
version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
38
38
template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
39
39
40
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
41
- defer cancel ()
40
+ ctx := testutil .Context (t , testutil .WaitLong )
42
41
43
42
_ , err := client .Template (ctx , template .ID )
44
43
require .NoError (t , err )
@@ -63,8 +62,7 @@ func TestPostTemplateByOrganization(t *testing.T) {
63
62
})
64
63
assert .Equal (t , (3 * time .Hour ).Milliseconds (), expected .ActivityBumpMillis )
65
64
66
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
67
- defer cancel ()
65
+ ctx := testutil .Context (t , testutil .WaitLong )
68
66
69
67
got , err := user .Template (ctx , expected .ID )
70
68
require .NoError (t , err )
@@ -86,8 +84,7 @@ func TestPostTemplateByOrganization(t *testing.T) {
86
84
version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
87
85
template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
88
86
89
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
90
- defer cancel ()
87
+ ctx := testutil .Context (t , testutil .WaitLong )
91
88
92
89
_ , err := client .CreateTemplate (ctx , user .OrganizationID , codersdk.CreateTemplateRequest {
93
90
Name : template .Name ,
@@ -98,15 +95,30 @@ func TestPostTemplateByOrganization(t *testing.T) {
98
95
require .Equal (t , http .StatusConflict , apiErr .StatusCode ())
99
96
})
100
97
101
- t .Run ("DefaultTTLTooLow " , func (t * testing.T ) {
98
+ t .Run ("ReservedName " , func (t * testing.T ) {
102
99
t .Parallel ()
103
100
client := coderdtest .New (t , nil )
104
101
user := coderdtest .CreateFirstUser (t , client )
105
102
version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
106
103
107
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
108
- defer cancel ()
104
+ ctx := testutil .Context (t , testutil .WaitShort )
109
105
106
+ _ , err := client .CreateTemplate (ctx , user .OrganizationID , codersdk.CreateTemplateRequest {
107
+ Name : "new" ,
108
+ VersionID : version .ID ,
109
+ })
110
+ var apiErr * codersdk.Error
111
+ require .ErrorAs (t , err , & apiErr )
112
+ require .Equal (t , http .StatusBadRequest , apiErr .StatusCode ())
113
+ })
114
+
115
+ t .Run ("DefaultTTLTooLow" , func (t * testing.T ) {
116
+ t .Parallel ()
117
+ client := coderdtest .New (t , nil )
118
+ user := coderdtest .CreateFirstUser (t , client )
119
+ version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
120
+
121
+ ctx := testutil .Context (t , testutil .WaitLong )
110
122
_ , err := client .CreateTemplate (ctx , user .OrganizationID , codersdk.CreateTemplateRequest {
111
123
Name : "testing" ,
112
124
VersionID : version .ID ,
@@ -124,9 +136,7 @@ func TestPostTemplateByOrganization(t *testing.T) {
124
136
user := coderdtest .CreateFirstUser (t , client )
125
137
version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
126
138
127
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
128
- defer cancel ()
129
-
139
+ ctx := testutil .Context (t , testutil .WaitLong )
130
140
got , err := client .CreateTemplate (ctx , user .OrganizationID , codersdk.CreateTemplateRequest {
131
141
Name : "testing" ,
132
142
VersionID : version .ID ,
@@ -143,15 +153,13 @@ func TestPostTemplateByOrganization(t *testing.T) {
143
153
owner := coderdtest .CreateFirstUser (t , client )
144
154
user , _ := coderdtest .CreateAnotherUser (t , client , owner .OrganizationID )
145
155
version := coderdtest .CreateTemplateVersion (t , client , owner .OrganizationID , nil )
146
-
147
156
expected := coderdtest .CreateTemplate (t , client , owner .OrganizationID , version .ID , func (request * codersdk.CreateTemplateRequest ) {
148
157
request .DisableEveryoneGroupAccess = true
149
158
})
150
159
151
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
152
- defer cancel ()
153
-
160
+ ctx := testutil .Context (t , testutil .WaitLong )
154
161
_ , err := user .Template (ctx , expected .ID )
162
+
155
163
var apiErr * codersdk.Error
156
164
require .ErrorAs (t , err , & apiErr )
157
165
require .Equal (t , http .StatusNotFound , apiErr .StatusCode ())
@@ -161,9 +169,7 @@ func TestPostTemplateByOrganization(t *testing.T) {
161
169
t .Parallel ()
162
170
client := coderdtest .New (t , nil )
163
171
164
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
165
- defer cancel ()
166
-
172
+ ctx := testutil .Context (t , testutil .WaitLong )
167
173
_ , err := client .CreateTemplate (ctx , uuid .New (), codersdk.CreateTemplateRequest {
168
174
Name : "test" ,
169
175
VersionID : uuid .New (),
@@ -241,8 +247,7 @@ func TestPostTemplateByOrganization(t *testing.T) {
241
247
client := coderdtest .New (t , nil )
242
248
user := coderdtest .CreateFirstUser (t , client )
243
249
244
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
245
- defer cancel ()
250
+ ctx := testutil .Context (t , testutil .WaitLong )
246
251
247
252
_ , err := client .CreateTemplate (ctx , user .OrganizationID , codersdk.CreateTemplateRequest {
248
253
Name : "test" ,
@@ -398,8 +403,7 @@ func TestTemplatesByOrganization(t *testing.T) {
398
403
client := coderdtest .New (t , nil )
399
404
user := coderdtest .CreateFirstUser (t , client )
400
405
401
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
402
- defer cancel ()
406
+ ctx := testutil .Context (t , testutil .WaitLong )
403
407
404
408
templates , err := client .TemplatesByOrganization (ctx , user .OrganizationID )
405
409
require .NoError (t , err )
@@ -414,8 +418,7 @@ func TestTemplatesByOrganization(t *testing.T) {
414
418
version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
415
419
coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
416
420
417
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
418
- defer cancel ()
421
+ ctx := testutil .Context (t , testutil .WaitLong )
419
422
420
423
templates , err := client .TemplatesByOrganization (ctx , user .OrganizationID )
421
424
require .NoError (t , err )
@@ -430,8 +433,7 @@ func TestTemplatesByOrganization(t *testing.T) {
430
433
coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
431
434
coderdtest .CreateTemplate (t , client , user .OrganizationID , version2 .ID )
432
435
433
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
434
- defer cancel ()
436
+ ctx := testutil .Context (t , testutil .WaitLong )
435
437
436
438
templates , err := client .TemplatesByOrganization (ctx , user .OrganizationID )
437
439
require .NoError (t , err )
@@ -446,8 +448,7 @@ func TestTemplateByOrganizationAndName(t *testing.T) {
446
448
client := coderdtest .New (t , nil )
447
449
user := coderdtest .CreateFirstUser (t , client )
448
450
449
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
450
- defer cancel ()
451
+ ctx := testutil .Context (t , testutil .WaitLong )
451
452
452
453
_ , err := client .TemplateByName (ctx , user .OrganizationID , "something" )
453
454
var apiErr * codersdk.Error
@@ -462,8 +463,7 @@ func TestTemplateByOrganizationAndName(t *testing.T) {
462
463
version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
463
464
template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
464
465
465
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
466
- defer cancel ()
466
+ ctx := testutil .Context (t , testutil .WaitLong )
467
467
468
468
_ , err := client .TemplateByName (ctx , user .OrganizationID , template .Name )
469
469
require .NoError (t , err )
@@ -497,8 +497,7 @@ func TestPatchTemplateMeta(t *testing.T) {
497
497
// updatedAt is too close together.
498
498
time .Sleep (time .Millisecond * 5 )
499
499
500
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
501
- defer cancel ()
500
+ ctx := testutil .Context (t , testutil .WaitLong )
502
501
503
502
updated , err := client .UpdateTemplateMeta (ctx , template .ID , req )
504
503
require .NoError (t , err )
@@ -542,8 +541,7 @@ func TestPatchTemplateMeta(t *testing.T) {
542
541
DeprecationMessage : ptr .Ref ("APGL cannot deprecate" ),
543
542
}
544
543
545
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
546
- defer cancel ()
544
+ ctx := testutil .Context (t , testutil .WaitLong )
547
545
548
546
updated , err := client .UpdateTemplateMeta (ctx , template .ID , req )
549
547
require .NoError (t , err )
@@ -566,8 +564,8 @@ func TestPatchTemplateMeta(t *testing.T) {
566
564
// updatedAt is too close together.
567
565
time .Sleep (time .Millisecond * 5 )
568
566
569
- ctx , cancel := context . WithTimeout ( context . Background () , testutil .WaitLong )
570
- defer cancel ()
567
+ ctx := testutil . Context ( t , testutil .WaitLong )
568
+
571
569
// nolint:gocritic // Setting up unit test data
572
570
err := db .UpdateTemplateAccessControlByID (dbauthz .As (ctx , coderdtest .AuthzUserSubject (tplAdmin , user .OrganizationID )), database.UpdateTemplateAccessControlByIDParams {
573
571
ID : template .ID ,
@@ -607,8 +605,7 @@ func TestPatchTemplateMeta(t *testing.T) {
607
605
MaxPortShareLevel : & level ,
608
606
}
609
607
610
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
611
- defer cancel ()
608
+ ctx := testutil .Context (t , testutil .WaitLong )
612
609
613
610
_ , err := client .UpdateTemplateMeta (ctx , template .ID , req )
614
611
// AGPL cannot change max port sharing level
@@ -643,8 +640,7 @@ func TestPatchTemplateMeta(t *testing.T) {
643
640
// We're too fast! Sleep so we can be sure that updatedAt is greater
644
641
time .Sleep (time .Millisecond * 5 )
645
642
646
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
647
- defer cancel ()
643
+ ctx := testutil .Context (t , testutil .WaitLong )
648
644
649
645
_ , err := client .UpdateTemplateMeta (ctx , template .ID , req )
650
646
require .NoError (t , err )
@@ -675,8 +671,7 @@ func TestPatchTemplateMeta(t *testing.T) {
675
671
DefaultTTLMillis : - 1 ,
676
672
}
677
673
678
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
679
- defer cancel ()
674
+ ctx := testutil .Context (t , testutil .WaitLong )
680
675
681
676
_ , err := client .UpdateTemplateMeta (ctx , template .ID , req )
682
677
require .ErrorContains (t , err , "default_ttl_ms: Must be a positive integer" )
@@ -886,8 +881,7 @@ func TestPatchTemplateMeta(t *testing.T) {
886
881
ctr .DefaultTTLMillis = ptr .Ref (24 * time .Hour .Milliseconds ())
887
882
})
888
883
889
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
890
- defer cancel ()
884
+ ctx := testutil .Context (t , testutil .WaitLong )
891
885
892
886
req := codersdk.UpdateTemplateMeta {
893
887
Name : template .Name ,
@@ -921,8 +915,7 @@ func TestPatchTemplateMeta(t *testing.T) {
921
915
ctr .DefaultTTLMillis = ptr .Ref (24 * time .Hour .Milliseconds ())
922
916
})
923
917
924
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
925
- defer cancel ()
918
+ ctx := testutil .Context (t , testutil .WaitLong )
926
919
927
920
req := codersdk.UpdateTemplateMeta {
928
921
DefaultTTLMillis : - int64 (time .Hour ),
@@ -956,8 +949,7 @@ func TestPatchTemplateMeta(t *testing.T) {
956
949
Icon : "" ,
957
950
}
958
951
959
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
960
- defer cancel ()
952
+ ctx := testutil .Context (t , testutil .WaitLong )
961
953
962
954
updated , err := client .UpdateTemplateMeta (ctx , template .ID , req )
963
955
require .NoError (t , err )
@@ -1164,8 +1156,7 @@ func TestDeleteTemplate(t *testing.T) {
1164
1156
template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
1165
1157
coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
1166
1158
1167
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1168
- defer cancel ()
1159
+ ctx := testutil .Context (t , testutil .WaitLong )
1169
1160
1170
1161
err := client .DeleteTemplate (ctx , template .ID )
1171
1162
require .NoError (t , err )
@@ -1183,8 +1174,7 @@ func TestDeleteTemplate(t *testing.T) {
1183
1174
coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
1184
1175
coderdtest .CreateWorkspace (t , client , user .OrganizationID , template .ID )
1185
1176
1186
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1187
- defer cancel ()
1177
+ ctx := testutil .Context (t , testutil .WaitLong )
1188
1178
1189
1179
err := client .DeleteTemplate (ctx , template .ID )
1190
1180
var apiErr * codersdk.Error
0 commit comments