|
| 1 | +package discovery_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/gruntwork-io/terragrunt/internal/discovery" |
| 7 | + "github.com/gruntwork-io/terragrunt/test/helpers/logger" |
| 8 | + "github.com/gruntwork-io/terragrunt/test/helpers/venvtest" |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | +) |
| 11 | + |
| 12 | +func TestNewForDiscoveryCommand_QueueConstructAs(t *testing.T) { |
| 13 | + t.Parallel() |
| 14 | + |
| 15 | + newForDiscoveryCommand := func(t *testing.T, queueConstructAs string) (*discovery.Discovery, error) { |
| 16 | + t.Helper() |
| 17 | + |
| 18 | + v := venvtest.New() |
| 19 | + |
| 20 | + return discovery.NewForDiscoveryCommand(logger.CreateLogger(), v.FS, &discovery.DiscoveryCommandOptions{ |
| 21 | + WorkingDir: "/repo", |
| 22 | + QueueConstructAs: queueConstructAs, |
| 23 | + }) |
| 24 | + } |
| 25 | + |
| 26 | + testCases := []struct { |
| 27 | + name string |
| 28 | + queueConstructAs string |
| 29 | + }{ |
| 30 | + {name: "semicolon", queueConstructAs: ";"}, |
| 31 | + {name: "pipe", queueConstructAs: "|"}, |
| 32 | + {name: "logical and", queueConstructAs: "&&"}, |
| 33 | + {name: "redirect", queueConstructAs: ">"}, |
| 34 | + {name: "stderr redirect", queueConstructAs: "2>&1"}, |
| 35 | + {name: "whitespace", queueConstructAs: " "}, |
| 36 | + {name: "tab", queueConstructAs: "\t"}, |
| 37 | + {name: "command after separator", queueConstructAs: "; plan"}, |
| 38 | + {name: "double quoted empty string", queueConstructAs: `""`}, |
| 39 | + {name: "single quoted empty string", queueConstructAs: "''"}, |
| 40 | + } |
| 41 | + |
| 42 | + for _, tc := range testCases { |
| 43 | + t.Run(tc.name, func(t *testing.T) { |
| 44 | + t.Parallel() |
| 45 | + |
| 46 | + _, err := newForDiscoveryCommand(t, tc.queueConstructAs) |
| 47 | + require.ErrorAs(t, err, &discovery.EmptyQueueConstructAsError{}) |
| 48 | + }) |
| 49 | + } |
| 50 | + |
| 51 | + t.Run("command with arguments", func(t *testing.T) { |
| 52 | + t.Parallel() |
| 53 | + |
| 54 | + d, err := newForDiscoveryCommand(t, "apply -destroy") |
| 55 | + require.NoError(t, err) |
| 56 | + require.NotNil(t, d) |
| 57 | + }) |
| 58 | + |
| 59 | + t.Run("unbalanced quote", func(t *testing.T) { |
| 60 | + t.Parallel() |
| 61 | + |
| 62 | + _, err := newForDiscoveryCommand(t, "plan '") |
| 63 | + require.Error(t, err) |
| 64 | + require.NotErrorAs(t, err, &discovery.EmptyQueueConstructAsError{}) |
| 65 | + }) |
| 66 | +} |
0 commit comments