forked from gruntwork-io/terragrunt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote_state_gcs_test.go
113 lines (106 loc) · 3.1 KB
/
remote_state_gcs_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
package remote
import (
"testing"
"github.com/gruntwork-io/terragrunt/options"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGCSConfigValuesEqual(t *testing.T) {
t.Parallel()
terragruntOptions, err := options.NewTerragruntOptionsForTest("remote_state_test")
require.Nil(t, err, "Unexpected error creating NewTerragruntOptionsForTest: %v", err)
testCases := []struct {
name string
config map[string]interface{}
backend *TerraformBackend
shouldBeEqual bool
}{
{
"equal-both-empty",
map[string]interface{}{},
&TerraformBackend{Type: "gcs", Config: map[string]interface{}{}},
true,
},
{
"equal-empty-and-nil",
map[string]interface{}{},
nil,
true,
},
{
"equal-empty-and-nil-backend-config",
map[string]interface{}{},
&TerraformBackend{Type: "gcs"},
true,
},
{
"equal-one-key",
map[string]interface{}{"foo": "bar"},
&TerraformBackend{Type: "gcs", Config: map[string]interface{}{"foo": "bar"}},
true,
},
{
"equal-multiple-keys",
map[string]interface{}{"foo": "bar", "baz": []string{"a", "b", "c"}, "blah": 123, "bool": true},
&TerraformBackend{Type: "gcs", Config: map[string]interface{}{"foo": "bar", "baz": []string{"a", "b", "c"}, "blah": 123, "bool": true}},
true,
},
{
"equal-encrypt-bool-handling",
map[string]interface{}{"encrypt": true},
&TerraformBackend{Type: "gcs", Config: map[string]interface{}{"encrypt": "true"}},
true,
},
{
"equal-general-bool-handling",
map[string]interface{}{"something": true, "encrypt": true},
&TerraformBackend{Type: "gcs", Config: map[string]interface{}{"something": "true", "encrypt": "true"}},
true,
},
{
"equal-ignore-gcs-labels",
map[string]interface{}{"foo": "bar", "gcs_bucket_labels": []map[string]string{{"foo": "bar"}}},
&TerraformBackend{Type: "gcs", Config: map[string]interface{}{"foo": "bar"}},
true,
},
{
"unequal-wrong-backend",
map[string]interface{}{"foo": "bar"},
&TerraformBackend{Type: "wrong", Config: map[string]interface{}{"foo": "bar"}},
false,
},
{
"unequal-values",
map[string]interface{}{"foo": "bar"},
&TerraformBackend{Type: "gcs", Config: map[string]interface{}{"foo": "different"}},
false,
},
{
"unequal-non-empty-config-nil",
map[string]interface{}{"foo": "bar"},
nil,
false,
},
{
"unequal-general-bool-handling",
map[string]interface{}{"something": true},
&TerraformBackend{Type: "gcs", Config: map[string]interface{}{"something": "false"}},
false,
},
{
"equal-null-ignored",
map[string]interface{}{"something": "foo"},
&TerraformBackend{Type: "gcs", Config: map[string]interface{}{"something": "foo", "ignored-because-null": nil}},
true,
},
}
for _, testCase := range testCases {
// Save the testCase in local scope so all the t.Run calls don't end up with the last item in the list
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
actual := gcsConfigValuesEqual(testCase.config, testCase.backend, terragruntOptions)
assert.Equal(t, testCase.shouldBeEqual, actual)
})
}
}