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

Function TestTemplateInit

cli/templateinit_test.go:13–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestTemplateInit(t *testing.T) {
14 t.Parallel()
15 t.Run("Extract", func(t *testing.T) {
16 t.Parallel()
17 tempDir := t.TempDir()
18 inv, _ := clitest.New(t, "templates", "init", tempDir)
19 ptytest.New(t).Attach(inv)
20 clitest.Run(t, inv)
21 files, err := os.ReadDir(tempDir)
22 require.NoError(t, err)
23 require.Greater(t, len(files), 0)
24 })
25
26 t.Run("ExtractSpecific", func(t *testing.T) {
27 t.Parallel()
28 tempDir := t.TempDir()
29 inv, _ := clitest.New(t, "templates", "init", "--id", "docker", tempDir)
30 ptytest.New(t).Attach(inv)
31 clitest.Run(t, inv)
32 files, err := os.ReadDir(tempDir)
33 require.NoError(t, err)
34 require.Greater(t, len(files), 0)
35 })
36
37 t.Run("NotFound", func(t *testing.T) {
38 t.Parallel()
39 tempDir := t.TempDir()
40 inv, _ := clitest.New(t, "templates", "init", "--id", "thistemplatedoesnotexist", tempDir)
41 ptytest.New(t).Attach(inv)
42 err := inv.Run()
43 require.ErrorContains(t, err, "invalid choice: thistemplatedoesnotexist, should be one of")
44 files, err := os.ReadDir(tempDir)
45 require.NoError(t, err)
46 require.Empty(t, files)
47 })
48}

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
NewFunction · 0.92
RunFunction · 0.92
ReadDirMethod · 0.80
RunMethod · 0.65
TempDirMethod · 0.65
AttachMethod · 0.65
EmptyMethod · 0.45

Tested by

no test coverage detected