@@ -299,6 +299,38 @@ func TestPostWorkspacesByOrganization(t *testing.T) {
299
299
require .Equal (t , "time until shutdown must be at least one minute" , apiErr .Validations [0 ].Detail )
300
300
})
301
301
})
302
+
303
+ t .Run ("TemplateDefaultTTL" , func (t * testing.T ) {
304
+ t .Parallel ()
305
+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
306
+ user := coderdtest .CreateFirstUser (t , client )
307
+ version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
308
+ exp := 24 * time .Hour .Milliseconds ()
309
+ template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID , func (ctr * codersdk.CreateTemplateRequest ) {
310
+ ctr .DefaultTTLMillis = & exp
311
+ })
312
+ coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
313
+
314
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
315
+ defer cancel ()
316
+
317
+ // no TTL provided should use template default
318
+ req := codersdk.CreateWorkspaceRequest {
319
+ TemplateID : template .ID ,
320
+ Name : "testing" ,
321
+ }
322
+ ws , err := client .CreateWorkspace (ctx , template .OrganizationID , codersdk .Me , req )
323
+ require .NoError (t , err )
324
+ require .EqualValues (t , exp , * ws .TTLMillis )
325
+
326
+ // TTL provided should override template default
327
+ req .Name = "testing2"
328
+ exp = 1 * time .Hour .Milliseconds ()
329
+ req .TTLMillis = & exp
330
+ ws , err = client .CreateWorkspace (ctx , template .OrganizationID , codersdk .Me , req )
331
+ require .NoError (t , err )
332
+ require .EqualValues (t , exp , * ws .TTLMillis )
333
+ })
302
334
}
303
335
304
336
func TestWorkspaceByOwnerAndName (t * testing.T ) {
@@ -1135,25 +1167,6 @@ func TestWorkspaceUpdateTTL(t *testing.T) {
1135
1167
ttlMillis : ptr .Ref ((24 * 7 * time .Hour + time .Minute ).Milliseconds ()),
1136
1168
expectedError : "time until shutdown must be less than 7 days" ,
1137
1169
},
1138
- {
1139
- name : "above template maximum ttl" ,
1140
- ttlMillis : ptr .Ref ((12 * time .Hour ).Milliseconds ()),
1141
- expectedError : "ttl_ms: time until shutdown must be below template maximum 8h0m0s" ,
1142
- modifyTemplate : func (ctr * codersdk.CreateTemplateRequest ) {
1143
- ctr .DefaultTTLMillis = ptr .Ref ((8 * time .Hour ).Milliseconds ())
1144
- },
1145
- },
1146
- {
1147
- name : "no template maximum ttl" ,
1148
- ttlMillis : ptr .Ref ((7 * 24 * time .Hour ).Milliseconds ()),
1149
- modifyTemplate : func (ctr * codersdk.CreateTemplateRequest ) { ctr .DefaultTTLMillis = ptr .Ref (int64 (0 )) },
1150
- },
1151
- {
1152
- name : "above maximum ttl even with no template max" ,
1153
- ttlMillis : ptr .Ref ((365 * 24 * time .Hour ).Milliseconds ()),
1154
- expectedError : "ttl_ms: time until shutdown must be less than 7 days" ,
1155
- modifyTemplate : func (ctr * codersdk.CreateTemplateRequest ) { ctr .DefaultTTLMillis = ptr .Ref (int64 (0 )) },
1156
- },
1157
1170
}
1158
1171
1159
1172
for _ , testCase := range testCases {
0 commit comments