MCPcopy Index your code
hub / github.com/coder/coder / TestCliTemplateCreate

Function TestCliTemplateCreate

cli/templatecreate_test.go:21–309  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestCliTemplateCreate(t *testing.T) {
22 t.Parallel()
23 t.Run("Create", func(t *testing.T) {
24 t.Parallel()
25 client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
26 coderdtest.CreateFirstUser(t, client)
27 source := clitest.CreateTemplateVersionSource(t, completeWithAgent())
28 args := []string{
29 "templates",
30 "create",
31 "my-template",
32 "--directory", source,
33 "--test.provisioner", string(database.ProvisionerTypeEcho),
34 "--default-ttl", "24h",
35 }
36 inv, root := clitest.New(t, args...)
37 clitest.SetupConfig(t, client, root)
38 pty := ptytest.New(t).Attach(inv)
39
40 clitest.Start(t, inv)
41
42 matches := []struct {
43 match string
44 write string
45 }{
46 {match: "Upload", write: "yes"},
47 {match: "compute.main"},
48 {match: "smith (linux, i386)"},
49 {match: "Confirm create?", write: "yes"},
50 }
51 for _, m := range matches {
52 pty.ExpectMatch(m.match)
53 if len(m.write) > 0 {
54 pty.WriteLine(m.write)
55 }
56 }
57 })
58 t.Run("CreateNoLockfile", func(t *testing.T) {
59 t.Parallel()
60 client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
61 coderdtest.CreateFirstUser(t, client)
62 source := clitest.CreateTemplateVersionSource(t, completeWithAgent())
63 require.NoError(t, os.Remove(filepath.Join(source, ".terraform.lock.hcl")))
64 args := []string{
65 "templates",
66 "create",
67 "my-template",
68 "--directory", source,
69 "--test.provisioner", string(database.ProvisionerTypeEcho),
70 "--default-ttl", "24h",
71 }
72 inv, root := clitest.New(t, args...)
73 clitest.SetupConfig(t, client, root)
74 pty := ptytest.New(t).Attach(inv)
75
76 execDone := make(chan error)
77 go func() {
78 execDone <- inv.Run()

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
CreateFirstUserFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
StartFunction · 0.92
TarFunction · 0.92
completeWithAgentFunction · 0.85
createFunction · 0.85

Tested by

no test coverage detected