| 11 | ) |
| 12 | |
| 13 | func 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 | } |