From baf892eb666b197969e3a01e25821324133c3696 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Tue, 8 Nov 2022 16:17:14 -0500 Subject: [PATCH] deps: Remove github.com/nsf/jsondiff It was only being used in one unit test and go-cmp can support something good enough for our purposes via a transformer. --- go.mod | 1 - go.sum | 2 -- tftypes/type_json_test.go | 26 ++++++++++++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 3d3b79d9..e2bb755d 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 9020145a..1995271b 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/tftypes/type_json_test.go b/tftypes/type_json_test.go index 5a8fac1f..e98b8afe 100644 --- a/tftypes/type_json_test.go +++ b/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) { @@ -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) { @@ -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) } }) }