Skip to content

Commit b1a92ab

Browse files
authored
deps: Remove github.com/nsf/jsondiff (#235)
It was only being used in one unit test and go-cmp can support something good enough for our purposes via a transformer.
1 parent f3636ee commit b1a92ab

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ require (
1010
github.com/hashicorp/terraform-plugin-log v0.7.0
1111
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c
1212
github.com/mitchellh/go-testing-interface v1.14.1
13-
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce
1413
github.com/vmihailenco/msgpack/v4 v4.3.12
1514
google.golang.org/grpc v1.50.1
1615
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9
6666
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
6767
github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU=
6868
github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
69-
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758=
70-
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
7169
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
7270
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
7371
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

tftypes/type_json_test.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
package tftypes
22

33
import (
4+
"encoding/json"
45
"testing"
56

67
"github.com/google/go-cmp/cmp"
7-
"github.com/nsf/jsondiff"
8+
)
9+
10+
// Reference: https://github.com/google/go-cmp/issues/224
11+
var cmpTransformJSON = cmp.FilterValues(
12+
func(x, y []byte) bool {
13+
return json.Valid(x) && json.Valid(y)
14+
},
15+
cmp.Transformer("ParseJSON", func(in []byte) (out interface{}) {
16+
if err := json.Unmarshal(in, &out); err != nil {
17+
panic(err) // should never occur given previous filter to ensure valid JSON
18+
}
19+
20+
return out
21+
}),
822
)
923

1024
func TestTypeJSON(t *testing.T) {
@@ -138,7 +152,7 @@ func TestTypeJSON(t *testing.T) {
138152
}},
139153
},
140154
}
141-
jsondiffopts := jsondiff.DefaultConsoleOptions()
155+
142156
for name, test := range testCases {
143157
name, test := name, test
144158
t.Run(name, func(t *testing.T) {
@@ -150,13 +164,13 @@ func TestTypeJSON(t *testing.T) {
150164
t.Fatalf("Unexpected parsing results (-wanted +got): %s", cmp.Diff(test.typ, typ))
151165
}
152166

153-
json, err := typ.MarshalJSON()
167+
typJSON, err := typ.MarshalJSON()
154168
if err != nil {
155169
t.Fatalf("unexpected error generating JSON: %s", err)
156170
}
157-
diff, diffStr := jsondiff.Compare([]byte(test.json), json, &jsondiffopts)
158-
if diff != jsondiff.FullMatch {
159-
t.Fatalf("unexpected JSON generating results (got => expected): %s", diffStr)
171+
172+
if diff := cmp.Diff([]byte(test.json), typJSON, cmpTransformJSON); diff != "" {
173+
t.Fatalf("unexpected generated JSON difference: %s", diff)
160174
}
161175
})
162176
}

0 commit comments

Comments
 (0)