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

* feat(cli): add template create validation test

This adds a test to validate that `template create` prints an error
message if called with a template name exceeding the 32-char limit.

* fixup

* fixup test

* feat(cli): add name validation to templatecreate

This adds a validation step to ensure the template name is less than 32
characters.

* fixup!: use utf8.RuneCountInString

* fixup!: remove pty from test
This commit is contained in:
Joe Previte
2022-09-07 13:01:18 -07:00
committed by GitHub
parent 720c9dadcf
commit 1359850715
2 changed files with 20 additions and 0 deletions

View File

@ -241,6 +241,21 @@ func TestTemplateCreate(t *testing.T) {
err = create()
require.NoError(t, err, "Template must be recreated without error")
})
t.Run("WithParameterExceedingCharLimit", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
coderdtest.CreateFirstUser(t, client)
cmd, root := clitest.New(t, "templates", "create", "1234567890123456789012345678901234567891", "--test.provisioner", string(database.ProvisionerTypeEcho))
clitest.SetupConfig(t, client, root)
execDone := make(chan error)
go func() {
execDone <- cmd.Execute()
}()
require.EqualError(t, <-execDone, "Template name must be less than 32 characters")
})
}
func createTestParseResponse() []*proto.Parse_Response {