2023-10-06 11:58:24 +01:00
|
|
|
package validate
|
|
|
|
|
|
2023-11-19 20:27:33 +00:00
|
|
|
import (
|
|
|
|
|
"errors"
|
2024-07-18 06:53:20 +01:00
|
|
|
"fmt"
|
2023-11-19 20:27:33 +00:00
|
|
|
"testing"
|
|
|
|
|
)
|
2023-10-06 11:58:24 +01:00
|
|
|
|
2024-07-18 06:53:20 +01:00
|
|
|
func ExampleUUID() {
|
|
|
|
|
fmt.Println(UUID("not a uuid"))
|
|
|
|
|
// Output: invalid UUID
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-07 10:43:21 +01:00
|
|
|
func TestUUID(t *testing.T) {
|
2024-07-18 06:53:20 +01:00
|
|
|
testCases := map[string]error{
|
|
|
|
|
"00000000-0000-0000-0000-000000000000": nil,
|
|
|
|
|
"01234567-89ab-cdef-0123-456789abcdef": nil,
|
|
|
|
|
"abcdef01-2345-6789-abcd-ef0123456789": nil,
|
2023-10-06 11:58:24 +01:00
|
|
|
|
2024-07-18 06:53:20 +01:00
|
|
|
"not a uuid": ErrInvalidUUID,
|
|
|
|
|
"00000000-00-0000-0000-00000000000000": ErrInvalidUUID,
|
|
|
|
|
"00000000000000000000000000000000": ErrInvalidUUID,
|
|
|
|
|
"01234567-89ab-cdef-ghij-klmnopqrstuv": ErrInvalidUUID,
|
2023-10-06 11:58:24 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-18 06:53:20 +01:00
|
|
|
for input, want := range testCases {
|
|
|
|
|
t.Run(input, func(t *testing.T) {
|
|
|
|
|
got := UUID(input)
|
2023-10-08 15:21:02 +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-06 11:58:24 +01:00
|
|
|
}
|
|
|
|
|
}
|