package dirs import ( "bytes" "flag" "testing" "github.com/anchore/go-testutils" "github.com/anchore/imgbom/imgbom/pkg" "github.com/sergi/go-diff/diffmatchpatch" ) var update = flag.Bool("update", false, "update the *.golden files for json presenters") func TestJsonPresenter(t *testing.T) { var buffer bytes.Buffer catalog := pkg.NewCatalog() // populate catalog with test data catalog.Add(pkg.Package{ Name: "package-1", Version: "1.0.1", Type: pkg.DebPkg, }) catalog.Add(pkg.Package{ Name: "package-2", Version: "2.0.1", Type: pkg.DebPkg, }) pres := NewPresenter(catalog, "/some/path") // run presenter err := pres.Present(&buffer) if err != nil { t.Fatal(err) } actual := buffer.Bytes() if *update { testutils.UpdateGoldenFileContents(t, actual) } var expected = testutils.GetGoldenFileContents(t) if !bytes.Equal(expected, actual) { dmp := diffmatchpatch.New() diffs := dmp.DiffMain(string(actual), string(expected), true) t.Errorf("mismatched output:\n%s", dmp.DiffPrettyText(diffs)) } }