Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(cli): display template version name in push output#21192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
matifali wants to merge3 commits intomain
base:main
Choose a base branch
Loading
fromfix/issue-21111-display-version-name
Open
Show file tree
Hide file tree
Changes fromall 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 deletioncli/templatepush.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletioncli/templatepush_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can we make sure that the template version matches the one exposed via API, and match the whole phraseUpdated version XYZ at?

EDIT:
I guess we could match the timestamp too, but it isn't crucial.


w.RequireSuccess()

Expand DownExpand 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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Same


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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I guess we don't need a separate case for that, just modify "OK" test case :)

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

[8]ページ先頭

©2009-2025 Movatter.jp