Skip to content

Commit 9f37134

Browse files
committed
fixup! allow setting template max_ttl to 0
1 parent 877e3d0 commit 9f37134

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

coderd/templates.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,6 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
461461
if icon == "" {
462462
icon = template.Icon
463463
}
464-
if maxTTL == 0 {
465-
maxTTL = time.Duration(template.MaxTtl)
466-
}
467464
if minAutostartInterval == 0 {
468465
minAutostartInterval = time.Duration(template.MinAutostartInterval)
469466
}

coderd/templates_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,32 @@ func TestPatchTemplateMeta(t *testing.T) {
329329
assert.Equal(t, req.MinAutostartIntervalMillis, updated.MinAutostartIntervalMillis)
330330
})
331331

332+
t.Run("NoMaxTTL", func(t *testing.T) {
333+
t.Parallel()
334+
335+
client := coderdtest.New(t, nil)
336+
user := coderdtest.CreateFirstUser(t, client)
337+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
338+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
339+
ctr.MaxTTLMillis = ptr.Ref(24 * time.Hour.Milliseconds())
340+
})
341+
req := codersdk.UpdateTemplateMeta{
342+
MaxTTLMillis: 0,
343+
}
344+
345+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
346+
defer cancel()
347+
348+
_, err := client.UpdateTemplateMeta(ctx, template.ID, req)
349+
require.NoError(t, err)
350+
351+
// Extra paranoid: did it _really_ happen?
352+
updated, err := client.Template(ctx, template.ID)
353+
require.NoError(t, err)
354+
assert.Greater(t, updated.UpdatedAt, template.UpdatedAt)
355+
assert.Equal(t, req.MaxTTLMillis, updated.MaxTTLMillis)
356+
})
357+
332358
t.Run("MaxTTLTooLow", func(t *testing.T) {
333359
t.Parallel()
334360

0 commit comments

Comments
 (0)