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

39 lines
594 B
Go

package validate
import (
"errors"
"fmt"
"testing"
)
func ExampleIn() {
testIn := In("abc", "def", "xyz")
fmt.Println(testIn("123"))
// Output: not allowed
}
func TestIn(t *testing.T) {
testIn := In("abc", "def", "xyz")
testCases := map[string]error{
"abc": nil,
"def": nil,
"xyz": nil,
"abcd": ErrValueNotAllowed,
"123": ErrValueNotAllowed,
"": ErrValueNotAllowed,
}
for input, want := range testCases {
t.Run(input, func(t *testing.T) {
got := testIn(input)
if !errors.Is(got, want) {
t.Error("got", got)
t.Error("want", want)
}
})
}
}