Skip to content

feat: Unify cli behavior for templates create and update #1385

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Clean up tests, amend PR comments
  • Loading branch information
mafredri committed May 12, 2022
commit 6bfed73c87b3b4214c0f69b747b0e0a3fb34234b
28 changes: 15 additions & 13 deletions cli/templatecreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,27 @@ func TestTemplateCreate(t *testing.T) {
cmd, root := clitest.New(t, "templates", "create", "my-template", "--directory", source, "--test.provisioner", string(database.ProvisionerTypeEcho))
clitest.SetupConfig(t, client, root)
_ = coderdtest.NewProvisionerDaemon(t, client)
doneChan := make(chan struct{})
pty := ptytest.New(t)
cmd.SetIn(pty.Input())
cmd.SetOut(pty.Output())

execDone := make(chan error)
go func() {
defer close(doneChan)
err := cmd.Execute()
require.NoError(t, err)
execDone <- cmd.Execute()
}()
matches := []string{
"Create and upload", "yes",
"Confirm create?", "yes",

matches := []struct {
match string
write string
}{
{match: "Create and upload", write: "yes"},
{match: "Confirm create?", write: "yes"},
}
for i := 0; i < len(matches); i += 2 {
match := matches[i]
value := matches[i+1]
pty.ExpectMatch(match)
pty.WriteLine(value)
for _, m := range matches {
pty.ExpectMatch(m.match)
pty.WriteLine(m.write)
}
<-doneChan

require.NoError(t, <-execDone)
})
}
26 changes: 14 additions & 12 deletions cli/templateupdate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,24 @@ func TestTemplateUpdate(t *testing.T) {
pty := ptytest.New(t)
cmd.SetIn(pty.Input())
cmd.SetOut(pty.Output())
done := make(chan struct{})

execDone := make(chan error)
go func() {
defer close(done)
err := cmd.Execute()
require.NoError(t, err)
execDone <- cmd.Execute()
}()
matches := []string{
"Upload", "yes",

matches := []struct {
match string
write string
}{
{match: "Upload", write: "yes"},
}
for i := 0; i < len(matches); i += 2 {
match := matches[i]
value := matches[i+1]
pty.ExpectMatch(match)
pty.WriteLine(value)
for _, m := range matches {
pty.ExpectMatch(m.match)
pty.WriteLine(m.write)
}
<-done

require.NoError(t, <-execDone)

// Assert that the template version changed.
templateVersions, err := client.TemplateVersionsByTemplate(context.Background(), codersdk.TemplateVersionsByTemplateRequest{
Expand Down