Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the test TestAccApigeeInstance_apigeeInstanceServiceAttachmentBas… (
#6793) (#13037) Signed-off-by: Modular Magician <magic-modules@google.com> Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
9a9d355
commit 7b64d79
Showing
3 changed files
with
144 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
apigee: Fixed permadiff on consumer_accept_list for `google_apigee_instance` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} | ||
} | ||
} |