Files
coder/cli/templateinit_test.go
Kyle Carberry 22e781eced chore: add /v2 to import module path (#9072)
* chore: add /v2 to import module path

go mod requires semantic versioning with versions greater than 1.x

This was a mechanical update by running:
```
go install github.com/marwan-at-work/mod/cmd/mod@latest
mod upgrade
```

Migrate generated files to import /v2

* Fix gen
2023-08-18 18:55:43 +00:00

49 lines
1.2 KiB
Go

package cli_test
import (
"os"
"testing"
"github.com/stretchr/testify/require"
"github.com/coder/coder/v2/cli/clitest"
"github.com/coder/coder/v2/pty/ptytest"
)
func TestTemplateInit(t *testing.T) {
t.Parallel()
t.Run("Extract", func(t *testing.T) {
t.Parallel()
tempDir := t.TempDir()
inv, _ := clitest.New(t, "templates", "init", tempDir)
ptytest.New(t).Attach(inv)
clitest.Run(t, inv)
files, err := os.ReadDir(tempDir)
require.NoError(t, err)
require.Greater(t, len(files), 0)
})
t.Run("ExtractSpecific", func(t *testing.T) {
t.Parallel()
tempDir := t.TempDir()
inv, _ := clitest.New(t, "templates", "init", "--id", "docker", tempDir)
ptytest.New(t).Attach(inv)
clitest.Run(t, inv)
files, err := os.ReadDir(tempDir)
require.NoError(t, err)
require.Greater(t, len(files), 0)
})
t.Run("NotFound", func(t *testing.T) {
t.Parallel()
tempDir := t.TempDir()
inv, _ := clitest.New(t, "templates", "init", "--id", "thistemplatedoesnotexist", tempDir)
ptytest.New(t).Attach(inv)
err := inv.Run()
require.ErrorContains(t, err, "invalid choice: thistemplatedoesnotexist, should be one of")
files, err := os.ReadDir(tempDir)
require.NoError(t, err)
require.Empty(t, files)
})
}