mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
This PR makes the following changes: - Adds an --id parameter to coder templates init so that you can non-interactively initialize a specific example template by ID (e.g. folder name) - Updates develop.sh and lima/coder.yaml to use this parameter to select the docker example template.
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/cli/clitest"
|
|
"github.com/coder/coder/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)
|
|
})
|
|
}
|