Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: Remove github.com/nsf/jsondiff #235

Merged
merged 1 commit into from Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Expand Up @@ -10,7 +10,6 @@ require (
github.com/hashicorp/terraform-plugin-log v0.7.0
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c
github.com/mitchellh/go-testing-interface v1.14.1
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce
github.com/vmihailenco/msgpack/v4 v4.3.12
google.golang.org/grpc v1.50.1
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Expand Up @@ -66,8 +66,6 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU=
github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758=
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
26 changes: 20 additions & 6 deletions tftypes/type_json_test.go
@@ -1,10 +1,24 @@
package tftypes

import (
"encoding/json"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/nsf/jsondiff"
)

// Reference: https://github.com/google/go-cmp/issues/224
var cmpTransformJSON = cmp.FilterValues(
func(x, y []byte) bool {
return json.Valid(x) && json.Valid(y)
},
cmp.Transformer("ParseJSON", func(in []byte) (out interface{}) {
if err := json.Unmarshal(in, &out); err != nil {
panic(err) // should never occur given previous filter to ensure valid JSON
}

return out
}),
)

func TestTypeJSON(t *testing.T) {
Expand Down Expand Up @@ -138,7 +152,7 @@ func TestTypeJSON(t *testing.T) {
}},
},
}
jsondiffopts := jsondiff.DefaultConsoleOptions()

for name, test := range testCases {
name, test := name, test
t.Run(name, func(t *testing.T) {
Expand All @@ -150,13 +164,13 @@ func TestTypeJSON(t *testing.T) {
t.Fatalf("Unexpected parsing results (-wanted +got): %s", cmp.Diff(test.typ, typ))
}

json, err := typ.MarshalJSON()
typJSON, err := typ.MarshalJSON()
if err != nil {
t.Fatalf("unexpected error generating JSON: %s", err)
}
diff, diffStr := jsondiff.Compare([]byte(test.json), json, &jsondiffopts)
if diff != jsondiff.FullMatch {
t.Fatalf("unexpected JSON generating results (got => expected): %s", diffStr)

if diff := cmp.Diff([]byte(test.json), typJSON, cmpTransformJSON); diff != "" {
t.Fatalf("unexpected generated JSON difference: %s", diff)
}
})
}
Expand Down