11package tftypes
22
33import (
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
1024func 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