Skip to content

feat(cli): validate name length on template create #3823

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
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
Next Next commit
fixup
  • Loading branch information
jsjoeio committed Sep 2, 2022
commit 7f8019bccff57fc7e6888b1673497ddfbc49a663
23 changes: 21 additions & 2 deletions cli/templatecreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,16 @@ func TestTemplateCreate(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
coderdtest.CreateFirstUser(t, client)
// Template name "1234567890123456789012345678901234567890" exceeds 32 char limit
cmd, root := clitest.New(t, "templates", "create", "1234567890123456789012345678901234567890", "--test.provisioner", string(database.ProvisionerTypeEcho))
source := clitest.CreateTemplateVersionSource(t, &echo.Responses{
Parse: createTestParseResponse(),
Provision: echo.ProvisionComplete,
ProvisionDryRun: echo.ProvisionComplete,
})
tempDir := t.TempDir()
removeTmpDirUntilSuccessAfterTest(t, tempDir)
parameterFile, _ := os.CreateTemp(tempDir, "testParameterFile*.yaml")
_, _ = parameterFile.WriteString("zone: \"bananas\"")
cmd, root := clitest.New(t, "templates", "create", "1234567890123456789012345678901234567890", "--directory", source, "--test.provisioner", string(database.ProvisionerTypeEcho), "--parameter-file", parameterFile.Name())
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t)
cmd.SetIn(pty.Input())
Expand All @@ -258,6 +266,17 @@ func TestTemplateCreate(t *testing.T) {
execDone <- cmd.Execute()
}()

matches := []struct {
match string
write string
}{
{match: "Create and upload", write: "yes"},
}
for _, m := range matches {
pty.ExpectMatch(m.match)
pty.WriteLine(m.write)
}

require.EqualError(t, <-execDone, "template name must be less than 32 characters")
})
}
Expand Down