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