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:
parent
613b659b95
commit
be1cf79d6a
1 changed files with 14 additions and 1 deletions
|
|
@ -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())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue