2022-03-22 19:17:50 +00:00
|
|
|
package cli_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2023-08-18 18:55:43 +00:00
|
|
|
"github.com/coder/coder/v2/cli/clitest"
|
|
|
|
"github.com/coder/coder/v2/pty/ptytest"
|
2022-03-22 19:17:50 +00:00
|
|
|
)
|
|
|
|
|
2022-04-06 17:42:40 +00:00
|
|
|
func TestTemplateInit(t *testing.T) {
|
2022-03-22 19:17:50 +00:00
|
|
|
t.Parallel()
|
|
|
|
t.Run("Extract", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
tempDir := t.TempDir()
|
2023-03-23 22:42:20 +00:00
|
|
|
inv, _ := clitest.New(t, "templates", "init", tempDir)
|
|
|
|
ptytest.New(t).Attach(inv)
|
|
|
|
clitest.Run(t, inv)
|
2022-03-22 19:17:50 +00:00
|
|
|
files, err := os.ReadDir(tempDir)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Greater(t, len(files), 0)
|
|
|
|
})
|
2023-04-13 14:02:49 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
2022-03-22 19:17:50 +00:00
|
|
|
}
|