-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathintegration_errors_test.go
175 lines (127 loc) · 6.17 KB
/
integration_errors_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package test_test
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gruntwork-io/terragrunt/test/helpers"
"github.com/gruntwork-io/terragrunt/util"
"github.com/stretchr/testify/require"
)
const (
testSimpleErrors = "fixtures/errors/default"
testIgnoreErrors = "fixtures/errors/ignore"
testIgnoreSignalErrors = "fixtures/errors/ignore-signal"
testRunAllIgnoreErrors = "fixtures/errors/run-all-ignore"
testRetryErrors = "fixtures/errors/retry"
testRetryFailErrors = "fixtures/errors/retry-fail"
testRunAllErrors = "fixtures/errors/run-all"
testNegativePatternErrors = "fixtures/errors/ignore-negative-pattern"
testMultiLineErrors = "fixtures/errors/multi-line"
)
func TestErrorsHandling(t *testing.T) {
t.Parallel()
cleanupTerraformFolder(t, testSimpleErrors)
tmpEnvPath := helpers.CopyEnvironment(t, testSimpleErrors)
rootPath := util.JoinPath(tmpEnvPath, testSimpleErrors)
_, _, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-working-dir "+rootPath)
require.NoError(t, err)
}
func TestIgnoreError(t *testing.T) {
t.Parallel()
cleanupTerraformFolder(t, testIgnoreErrors)
tmpEnvPath := helpers.CopyEnvironment(t, testIgnoreErrors)
rootPath := util.JoinPath(tmpEnvPath, testIgnoreErrors)
_, stderr, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-working-dir "+rootPath)
require.NoError(t, err)
assert.Contains(t, stderr, "Ignoring error example1")
assert.NotContains(t, stderr, "Ignoring error example2")
}
func TestRunAllIgnoreError(t *testing.T) {
t.Parallel()
cleanupTerraformFolder(t, testRunAllIgnoreErrors)
tmpEnvPath := helpers.CopyEnvironment(t, testRunAllIgnoreErrors)
rootPath := util.JoinPath(tmpEnvPath, testRunAllIgnoreErrors)
stdout, stderr, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt run-all apply -auto-approve --terragrunt-non-interactive --terragrunt-working-dir "+rootPath)
require.NoError(t, err)
assert.Contains(t, stderr, "Ignoring error example1")
assert.NotContains(t, stderr, "Ignoring error example2")
assert.Contains(t, stdout, "value-from-app-2")
}
func TestRetryError(t *testing.T) {
t.Parallel()
cleanupTerraformFolder(t, testRetryErrors)
tmpEnvPath := helpers.CopyEnvironment(t, testRetryErrors)
rootPath := util.JoinPath(tmpEnvPath, testRetryErrors)
_, stderr, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-working-dir "+rootPath)
require.NoError(t, err)
assert.Contains(t, stderr, "Encountered retryable error: script_errors")
assert.NotContains(t, stderr, "aws_errors")
}
func TestRetryFailError(t *testing.T) {
t.Parallel()
cleanupTerraformFolder(t, testRetryFailErrors)
tmpEnvPath := helpers.CopyEnvironment(t, testRetryFailErrors)
rootPath := util.JoinPath(tmpEnvPath, testRetryFailErrors)
_, stderr, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-working-dir "+rootPath)
require.Error(t, err)
assert.Contains(t, stderr, "Encountered retryable error: script_errors")
}
func TestIgnoreSignal(t *testing.T) {
t.Parallel()
cleanupTerraformFolder(t, testIgnoreSignalErrors)
tmpEnvPath := helpers.CopyEnvironment(t, testIgnoreSignalErrors)
rootPath := util.JoinPath(tmpEnvPath, testIgnoreSignalErrors)
_, stderr, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-working-dir "+rootPath)
require.NoError(t, err)
assert.Contains(t, stderr, "Ignoring error example1")
assert.NotContains(t, stderr, "Ignoring error example2")
signalsFile := filepath.Join(rootPath, "error-signals.json")
assert.FileExists(t, signalsFile)
content, err := os.ReadFile(signalsFile)
require.NoError(t, err, "Failed to read error-signals.json")
var signals struct {
Message string `json:"message"`
}
err = json.Unmarshal(content, &signals)
require.NoError(t, err, "Failed to parse error-signals.json")
assert.Equal(t, "Failed example1", signals.Message, "Unexpected error message")
}
func TestRunAllError(t *testing.T) {
t.Parallel()
cleanupTerraformFolder(t, testRunAllErrors)
tmpEnvPath := helpers.CopyEnvironment(t, testRunAllErrors)
rootPath := util.JoinPath(tmpEnvPath, testRunAllErrors)
_, stderr, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt run-all apply -auto-approve --terragrunt-non-interactive --terragrunt-working-dir "+rootPath)
require.NoError(t, err)
assert.Contains(t, stderr, "Ignoring error example1")
assert.NotContains(t, stderr, "Ignoring error example2")
assert.Contains(t, stderr, "Encountered retryable error: script_errors")
}
func TestRunAllFail(t *testing.T) {
t.Parallel()
cleanupTerraformFolder(t, testRunAllErrors)
tmpEnvPath := helpers.CopyEnvironment(t, testRunAllErrors)
rootPath := util.JoinPath(tmpEnvPath, testRunAllErrors)
_, _, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt run-all apply -auto-approve --feature unstable=false --terragrunt-non-interactive --terragrunt-working-dir "+rootPath)
require.Error(t, err)
}
func TestIgnoreNegativePattern(t *testing.T) {
t.Parallel()
cleanupTerraformFolder(t, testNegativePatternErrors)
tmpEnvPath := helpers.CopyEnvironment(t, testNegativePatternErrors)
rootPath := util.JoinPath(tmpEnvPath, testNegativePatternErrors)
_, stdout, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-working-dir "+rootPath)
require.Error(t, err)
assert.Contains(t, stdout, "Error: baz")
}
func TestHandleMultiLineErrors(t *testing.T) {
t.Parallel()
cleanupTerraformFolder(t, testMultiLineErrors)
tmpEnvPath := helpers.CopyEnvironment(t, testMultiLineErrors)
rootPath := util.JoinPath(tmpEnvPath, testMultiLineErrors)
_, stdout, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-working-dir "+rootPath)
require.NoError(t, err)
assert.Contains(t, stdout, "Ignoring transit gateway not found when creating internal route")
}