Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cli/templatepush.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ func (r *RootCmd) templatePush() *serpent.Command {
}
}

_, _ = fmt.Fprintf(inv.Stdout, "Updated version at %s!\n", pretty.Sprint(cliui.DefaultStyles.DateTimeStamp, time.Now().Format(time.Stamp)))
_, _ = fmt.Fprintf(inv.Stdout, "Updated version %s at %s!\n",
pretty.Sprint(cliui.DefaultStyles.Keyword, job.Name),
pretty.Sprint(cliui.DefaultStyles.DateTimeStamp, time.Now().Format(time.Stamp)))
return nil
},
}
Expand Down
83 changes: 82 additions & 1 deletion cli/templatepush_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestTemplatePush(t *testing.T) {
inv = inv.WithContext(ctx)
w := clitest.StartWithWaiter(t, inv)

pty.ExpectNoMatchBefore(ctx, "Template message is longer than 72 characters", "Updated version at")
pty.ExpectNoMatchBefore(ctx, "Template message is longer than 72 characters", "Updated version")

w.RequireSuccess()

Expand Down Expand Up @@ -1302,6 +1302,87 @@ cli_overrides_file_var: from-file`)
require.Equal(t, "from-cli-override", varMap["cli_overrides_file_var"])
})
})

t.Run("DisplayAutogeneratedVersionName", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
owner := coderdtest.CreateFirstUser(t, client)
templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin())
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)
_ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)

template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)

// Test the cli command without --name flag (autogenerated name).
source := clitest.CreateTemplateVersionSource(t, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionApply: echo.ApplyComplete,
})
inv, root := clitest.New(t, "templates", "push", template.Name, "--directory", source, "--test.provisioner", string(database.ProvisionerTypeEcho), "--yes")
clitest.SetupConfig(t, templateAdmin, root)
pty := ptytest.New(t).Attach(inv)

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
defer cancel()

inv = inv.WithContext(ctx)
w := clitest.StartWithWaiter(t, inv)

// Expect the output to contain "Updated version" followed by the version name.
pty.ExpectMatchContext(ctx, "Updated version")

w.RequireSuccess()

// Verify the autogenerated template version was created.
templateVersions, err := client.TemplateVersionsByTemplate(context.Background(), codersdk.TemplateVersionsByTemplateRequest{
TemplateID: template.ID,
})
require.NoError(t, err)
assert.Len(t, templateVersions, 2)
assert.NotEqual(t, template.ActiveVersionID, templateVersions[1].ID)
// Verify the autogenerated name is not empty (it should be something like "fervent_austin5").
assert.NotEmpty(t, templateVersions[1].Name)
})

t.Run("DisplayUserSpecifiedVersionName", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
owner := coderdtest.CreateFirstUser(t, client)
templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin())
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)
_ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)

template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)

// Test the cli command with --name flag.
source := clitest.CreateTemplateVersionSource(t, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionApply: echo.ApplyComplete,
})
versionName := "my-custom-version"
inv, root := clitest.New(t, "templates", "push", template.Name, "--directory", source, "--test.provisioner", string(database.ProvisionerTypeEcho), "--name", versionName, "--yes")
clitest.SetupConfig(t, templateAdmin, root)
pty := ptytest.New(t).Attach(inv)

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
defer cancel()

inv = inv.WithContext(ctx)
w := clitest.StartWithWaiter(t, inv)

// Expect the output to contain "Updated version my-custom-version".
pty.ExpectMatchContext(ctx, "Updated version "+versionName)

w.RequireSuccess()

// Assert that the template version has the correct name.
templateVersions, err := client.TemplateVersionsByTemplate(context.Background(), codersdk.TemplateVersionsByTemplateRequest{
TemplateID: template.ID,
})
require.NoError(t, err)
assert.Len(t, templateVersions, 2)
require.Equal(t, versionName, templateVersions[1].Name)
})
}

func createEchoResponsesWithTemplateVariables(templateVariables []*proto.TemplateVariable) *echo.Responses {
Expand Down
Loading