From 0c91f20720bb0cded0044b054f69711c172596fa Mon Sep 17 00:00:00 2001 From: Kira Pilot Date: Thu, 20 Apr 2023 16:11:24 +0000 Subject: [PATCH] fix: allow update of empty template description --- cli/templateedit_test.go | 8 +++++--- coderd/coderdtest/coderdtest.go | 5 ++--- coderd/templates.go | 7 ++----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cli/templateedit_test.go b/cli/templateedit_test.go index 8fdaf1835b134..eb84b0ba0f82a 100644 --- a/cli/templateedit_test.go +++ b/cli/templateedit_test.go @@ -167,11 +167,13 @@ func TestTemplateEdit(t *testing.T) { // Test the cli command. displayName := "New Display Name 789" + description := "New Description ABC" icon := "/icons/new-icon.png" cmdArgs := []string{ "templates", "edit", template.Name, + "--description", description, "--display-name", displayName, "--icon", icon, } @@ -186,8 +188,8 @@ func TestTemplateEdit(t *testing.T) { // Assert that the template metadata changed. updated, err := client.Template(context.Background(), template.ID) require.NoError(t, err) - assert.Equal(t, template.Name, updated.Name) // doesn't change - assert.Equal(t, initialDescription, updated.Description) // doesn't change + assert.Equal(t, template.Name, updated.Name) // doesn't change + assert.Equal(t, description, updated.Description) assert.Equal(t, displayName, updated.DisplayName) assert.Equal(t, icon, updated.Icon) }) @@ -234,9 +236,9 @@ func TestTemplateEdit(t *testing.T) { require.NoError(t, err) // Properties don't change assert.Equal(t, template.Name, updated.Name) - assert.Equal(t, template.Description, updated.Description) // These properties are removed, as the API considers it as "delete" request // See: https://github.com/coder/coder/issues/5066 + assert.Equal(t, "", updated.Description) assert.Equal(t, "", updated.Icon) assert.Equal(t, "", updated.DisplayName) }) diff --git a/coderd/coderdtest/coderdtest.go b/coderd/coderdtest/coderdtest.go index 7ed0717cf3674..9c98f1cb38aaa 100644 --- a/coderd/coderdtest/coderdtest.go +++ b/coderd/coderdtest/coderdtest.go @@ -591,9 +591,8 @@ func CreateWorkspaceBuild( // compatibility with testing. The name assigned is randomly generated. func CreateTemplate(t *testing.T, client *codersdk.Client, organization uuid.UUID, version uuid.UUID, mutators ...func(*codersdk.CreateTemplateRequest)) codersdk.Template { req := codersdk.CreateTemplateRequest{ - Name: randomUsername(t), - Description: randomUsername(t), - VersionID: version, + Name: randomUsername(t), + VersionID: version, } for _, mut := range mutators { mut(&req) diff --git a/coderd/templates.go b/coderd/templates.go index f36e25348e259..44def2d4b00b4 100644 --- a/coderd/templates.go +++ b/coderd/templates.go @@ -493,8 +493,8 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) { } // Update template metadata -- empty fields are not overwritten, - // except for display_name, icon, and default_ttl. - // The exception is required to clear content of these fields with UI. + // except for display_name, description, icon, and default_ttl. + // These exceptions are required to clear content of these fields with UI. name := req.Name displayName := req.DisplayName desc := req.Description @@ -503,9 +503,6 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) { if name == "" { name = template.Name } - if desc == "" { - desc = template.Description - } var err error updated, err = tx.UpdateTemplateMetaByID(ctx, database.UpdateTemplateMetaByIDParams{