|
4 | 4 | package json_test |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "cmp" |
| 8 | + "slices" |
7 | 9 | "testing" |
8 | 10 |
|
9 | | - "github.com/google/go-cmp/cmp" |
| 11 | + gocmp "github.com/google/go-cmp/cmp" |
10 | 12 | tfjson "github.com/hashicorp/terraform-provider-aws/internal/json" |
11 | 13 | mattbairdjsonpatch "github.com/mattbaird/jsonpatch" |
12 | 14 | ) |
@@ -72,11 +74,20 @@ func TestCreatePatchFromStrings(t *testing.T) { |
72 | 74 | t.Parallel() |
73 | 75 |
|
74 | 76 | got, err := tfjson.CreatePatchFromStrings(testCase.a, testCase.b) |
75 | | - if got, want := err != nil, testCase.wantErr; !cmp.Equal(got, want) { |
| 77 | + if got, want := err != nil, testCase.wantErr; !gocmp.Equal(got, want) { |
76 | 78 | t.Errorf("CreatePatchFromStrings(%s, %s) err %t, want %t", testCase.a, testCase.b, got, want) |
77 | 79 | } |
78 | 80 | if err == nil { |
79 | | - if diff := cmp.Diff(got, testCase.wantPatch); diff != "" { |
| 81 | + sortTransformer := gocmp.Transformer("SortPatchOps", func(ops []mattbairdjsonpatch.JsonPatchOperation) []mattbairdjsonpatch.JsonPatchOperation { |
| 82 | + sorted := make([]mattbairdjsonpatch.JsonPatchOperation, len(ops)) |
| 83 | + copy(sorted, ops) |
| 84 | + slices.SortFunc(sorted, func(a, b mattbairdjsonpatch.JsonPatchOperation) int { |
| 85 | + return cmp.Or(cmp.Compare(a.Operation, b.Operation), cmp.Compare(a.Path, b.Path)) |
| 86 | + }) |
| 87 | + return sorted |
| 88 | + }) |
| 89 | + |
| 90 | + if diff := gocmp.Diff(got, testCase.wantPatch, sortTransformer); diff != "" { |
80 | 91 | t.Errorf("unexpected diff (+wanted, -got): %s", diff) |
81 | 92 | } |
82 | 93 | } |
|
0 commit comments