Skip to content

dashmug/datadiff

Repository files navigation

datadiff

License: MIT Go Reference CI

A Go test assertion library for comparing lists of structs with rich tabular diff output.

Install

go get github.com/dashmug/datadiff

Usage

package 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

Flags

Assert is strict by default: order and length must match.

IgnoreOrder

Use IgnoreOrder to compare rows regardless of position.

ok := datadiff.Assert(t, expected, actual, datadiff.IgnoreOrder)

IgnoreLengths

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)

Inspiration

This project is inspired by chispa, a Python DataFrame assertion helper.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages