feat(cli): add --create flag to templates push (#8454)

This commit is contained in:
Marcin Tojek
2023-07-13 12:58:34 +02:00
committed by GitHub
parent 5432c3f5ea
commit 3727e02bbf
4 changed files with 95 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import (
"strings"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -613,6 +614,52 @@ func TestTemplatePush(t *testing.T) {
require.Equal(t, "second_variable", templateVariables[1].Name)
require.Equal(t, "foobar", templateVariables[1].Value)
})
t.Run("CreateTemplate", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user := coderdtest.CreateFirstUser(t, client)
source := clitest.CreateTemplateVersionSource(t, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionApply: provisionCompleteWithAgent,
})
const templateName = "my-template"
args := []string{
"templates",
"push",
templateName,
"--directory", source,
"--test.provisioner", string(database.ProvisionerTypeEcho),
"--create",
}
inv, root := clitest.New(t, args...)
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t).Attach(inv)
waiter := clitest.StartWithWaiter(t, inv)
matches := []struct {
match string
write string
}{
{match: "Upload", write: "yes"},
{match: "template has been created"},
}
for _, m := range matches {
pty.ExpectMatch(m.match)
if m.write != "" {
pty.WriteLine(m.write)
}
}
waiter.RequireSuccess()
template, err := client.TemplateByName(context.Background(), user.OrganizationID, templateName)
require.NoError(t, err)
require.Equal(t, templateName, template.Name)
require.NotEqual(t, uuid.Nil, template.ActiveVersionID)
})
})
}