-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
resource_apigee_instance_test.go
111 lines (100 loc) · 2.74 KB
/
resource_apigee_instance_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
package google
import (
"testing"
)
func TestUnitApigeeInstance_projectListDiffSuppress(t *testing.T) {
for _, tc := range apigeeInstanceDiffSuppressTestCases {
tc.Test(t)
}
}
type ApigeeInstanceDiffSuppressTestCase struct {
Name string
KeysToSuppress []string
Before map[string]interface{}
After map[string]interface{}
}
var apigeeInstanceDiffSuppressTestCases = []ApigeeInstanceDiffSuppressTestCase{
{
Name: "projects with the same length and one project entry is converted to project id",
KeysToSuppress: []string{"consumer_accept_list.0"},
Before: map[string]interface{}{
"consumer_accept_list.#": 2,
"consumer_accept_list.0": "45796856818",
"consumer_accept_list.1": "12345",
},
After: map[string]interface{}{
"consumer_accept_list.#": 2,
"consumer_accept_list.0": "tf-test8v1bd04pxa",
"consumer_accept_list.1": "12345",
},
},
{
Name: "projects with the same length and no project conversion",
KeysToSuppress: []string{},
Before: map[string]interface{}{
"consumer_accept_list.#": 2,
"consumer_accept_list.0": "tf-test8v1bd04pxa",
"consumer_accept_list.1": "12345",
},
After: map[string]interface{}{
"consumer_accept_list.#": 2,
"consumer_accept_list.0": "tf-test8v1bd04pxa",
"consumer_accept_list.1": "12345",
},
},
{
Name: "projects are empty",
KeysToSuppress: []string{},
Before: map[string]interface{}{},
After: map[string]interface{}{},
},
{
Name: "projects have the different length",
KeysToSuppress: []string{},
Before: map[string]interface{}{},
After: map[string]interface{}{
"consumer_accept_list.#": 2,
"consumer_accept_list.0": "tf-test8v1bd04pxa",
"consumer_accept_list.1": "12345",
},
},
}
func (tc *ApigeeInstanceDiffSuppressTestCase) Test(t *testing.T) {
mockResourceDiff := &ResourceDiffMock{
Before: tc.Before,
After: tc.After,
}
keysHavingDiff := map[string]bool{}
for key, val1 := range tc.Before {
val2, ok := tc.After[key]
if !ok {
keysHavingDiff[key] = true
} else if val1 != val2 {
keysHavingDiff[key] = true
}
}
for key, val1 := range tc.After {
val2, ok := tc.Before[key]
if !ok {
keysHavingDiff[key] = true
} else if val1 != val2 {
keysHavingDiff[key] = true
}
}
keySuppressionMap := map[string]bool{}
for key := range tc.Before {
keySuppressionMap[key] = false
}
for key := range tc.After {
keySuppressionMap[key] = false
}
for _, key := range tc.KeysToSuppress {
keySuppressionMap[key] = true
}
for key := range keysHavingDiff {
actual := projectListDiffSuppressFunc(mockResourceDiff)
if actual != keySuppressionMap[key] {
t.Errorf("Test %s: expected key `%s` to be suppressed", tc.Name, key)
}
}
}