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