A Go test assertion library for comparing lists of structs with rich tabular diff output.
go get github.com/dashmug/datadiffpackage yourpkg
import (
"testing"
"github.com/dashmug/datadiff"
)
type Person struct {
Name string
Age int
City string
}
func TestPeople(t *testing.T) {
expected := []Person{
{Name: "Alice", Age: 30, City: "New York"},
{Name: "Bob", Age: 25, City: "Boston"},
}
actual := []Person{
{Name: "Alice", Age: 30, City: "New York"},
{Name: "Bob", Age: 26, City: "Boston"},
}
if !datadiff.Assert(t, expected, actual) {
return
}
}When the assertion fails, output is tabular and highlights mismatched rows and columns:
datadiff: []Person are not equal
# Name Age City
- - - - -
✓ 0 Alice 30 New York
✗ 1 Bob 25 Boston ← expected
Bob 26 Boston ← actual
Assert is strict by default: order and length must match.
Use IgnoreOrder to compare rows regardless of position.
ok := datadiff.Assert(t, expected, actual, datadiff.IgnoreOrder)Use IgnoreLengths to allow extras while still comparing overlapping
rows.
ok := datadiff.Assert(t, expected, actual, datadiff.IgnoreLengths)You can combine both flags:
ok := datadiff.Assert(t, expected, actual, datadiff.IgnoreOrder, datadiff.IgnoreLengths)This project is inspired by chispa, a Python DataFrame assertion helper.
MIT