test: introduce helpers for go-cmp

This commit introduces three helpers to ignore dates, uuids and paths when
using cmp.diff() method
This commit is contained in:
Ondřej Budai 2019-11-28 14:08:58 +01:00 committed by Tom Gundersen
parent 613b659b95
commit be1cf79d6a

View file

@ -9,11 +9,12 @@ import (
"net/http"
"net/http/httptest"
"os"
"reflect"
"strings"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/uuid"
)
type API interface {
@ -144,3 +145,15 @@ func TestRoute(t *testing.T, api API, external bool, method, path, body string,
return
}
}
func IgnoreDates() cmp.Option {
return cmp.Comparer(func(a, b time.Time) bool { return true })
}
func IgnoreUuids() cmp.Option {
return cmp.Comparer(func(a, b uuid.UUID) bool { return true })
}
func Ignore(what string) cmp.Option {
return cmp.FilterPath(func(p cmp.Path) bool { return p.String() == what }, cmp.Ignore())
}