Files
Aneurin Barker Snook a9c1184d6b improve validate testing with examples
also simplified structure of test cases and failure logging
2024-07-18 06:53:20 +01:00

31 lines
701 B
Go

package validate
import (
"errors"
"fmt"
"testing"
)
func TestEqual(t *testing.T) {
testCases := map[string]map[string]error{
"abc": {"abc": nil, "def": ErrNotEqual.With("abc"), "xyz": ErrNotEqual.With("abc")},
"def": {"abc": ErrNotEqual.With("def"), "def": nil, "xyz": ErrNotEqual.With("def")},
"xyz": {"abc": ErrNotEqual.With("xyz"), "def": ErrNotEqual.With("xyz"), "xyz": nil},
}
for setup, values := range testCases {
testEqual := Equal(setup)
for input, want := range values {
t.Run(fmt.Sprintf("%s/%s", setup, input), func(t *testing.T) {
got := testEqual(input)
if !errors.Is(got, want) {
t.Error("got", got)
t.Error("want", want)
}
})
}
}
}