Skip to content

Instantly share code, notes, and snippets.

@hnakamur
Created November 25, 2019 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnakamur/ee3fff0ddf15d0ab30041bbe771235ff to your computer and use it in GitHub Desktop.
Save hnakamur/ee3fff0ddf15d0ab30041bbe771235ff to your computer and use it in GitHub Desktop.
Go test example for comparing JSON results
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)
}
}
@hnakamur
Copy link
Author

example output
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment