Skip to content

Instantly share code, notes, and snippets.

@krak3n
Created September 12, 2017 10:37
Show Gist options
  • Save krak3n/ac94d2519650710946559a8d837c544d to your computer and use it in GitHub Desktop.
Save krak3n/ac94d2519650710946559a8d837c544d to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"bytes"
"io/ioutil"
"path/filepath"
"testing"
)
func TestToJSON(t *testing.T) {
var b bytes.Buffer
w := bufio.NewWriter(&b)
err := ToJSON(w)
if err != nil {
t.Fatalf("failed writing json: %s", err)
}
w.Flush()
g, err := ioutil.ReadFile(filepath.Join("testdata", t.Name()+".golden"))
if err != nil {
t.Fatalf("failed reading .golden: %s", err)
}
if !bytes.Equal(b.Bytes(), g) {
t.Errorf("written json does not match .golden file")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment