Created
November 25, 2019 20:22
-
-
Save hnakamur/ee3fff0ddf15d0ab30041bbe771235ff to your computer and use it in GitHub Desktop.
Go test example for comparing JSON results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package foo | |
import ( | |
"testing" | |
"github.com/nsf/jsondiff" | |
) | |
var jsondiffOpts = jsondiff.DefaultConsoleOptions() | |
func TestHelloWorld(t *testing.T) { | |
got := `{"a": 123, "b": 456, "c": [7, 8, 9]}` | |
want := `{"a": 123, "c": [7, 8], "d": 10}` | |
if d, s := jsondiff.Compare([]byte(got), []byte(want), &jsondiffOpts); d != jsondiff.FullMatch { | |
t.Errorf("unmatch, got=%s, want=%s, diff=%s", got, want, s) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example output