Files

31 lines
701 B
Go
Raw Permalink Normal View History

2023-10-12 19:55:08 +01:00
package validate
import (
"errors"
2024-07-18 06:53:20 +01:00
"fmt"
"testing"
)
2023-10-12 19:55:08 +01:00
2024-07-18 06:53:20 +01:00
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},
2023-10-12 19:55:08 +01:00
}
2024-07-18 06:53:20 +01:00
for setup, values := range testCases {
testEqual := Equal(setup)
2023-10-12 19:55:08 +01:00
2024-07-18 06:53:20 +01:00
for input, want := range values {
t.Run(fmt.Sprintf("%s/%s", setup, input), func(t *testing.T) {
got := testEqual(input)
2023-10-12 19:55:08 +01:00
2024-07-18 06:53:20 +01:00
if !errors.Is(got, want) {
t.Error("got", got)
t.Error("want", want)
}
})
2023-10-12 19:55:08 +01:00
}
}
}