Skip to content

Commit f037aad

Browse files
fix: Accepts empty string for the icon prop to remove it (#3760)
1 parent 1dc0485 commit f037aad

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

coderd/templates.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,6 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
470470
if desc == "" {
471471
desc = template.Description
472472
}
473-
if icon == "" {
474-
icon = template.Icon
475-
}
476473
if minAutostartInterval == 0 {
477474
minAutostartInterval = time.Duration(template.MinAutostartInterval)
478475
}

coderd/templates_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,27 @@ func TestPatchTemplateMeta(t *testing.T) {
481481
assert.Equal(t, template.MaxTTLMillis, updated.MaxTTLMillis)
482482
assert.Equal(t, template.MinAutostartIntervalMillis, updated.MinAutostartIntervalMillis)
483483
})
484+
485+
t.Run("RemoveIcon", func(t *testing.T) {
486+
t.Parallel()
487+
488+
client := coderdtest.New(t, nil)
489+
user := coderdtest.CreateFirstUser(t, client)
490+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
491+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
492+
ctr.Icon = "/icons/code.png"
493+
})
494+
req := codersdk.UpdateTemplateMeta{
495+
Icon: "",
496+
}
497+
498+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
499+
defer cancel()
500+
501+
updated, err := client.UpdateTemplateMeta(ctx, template.ID, req)
502+
require.NoError(t, err)
503+
assert.Equal(t, updated.Icon, "")
504+
})
484505
}
485506

486507
func TestDeleteTemplate(t *testing.T) {

0 commit comments

Comments
 (0)