2023-10-06 11:58:24 +01:00
|
|
|
package validate
|
|
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
2023-10-07 10:43:21 +01:00
|
|
|
func TestUUID(t *testing.T) {
|
|
|
|
|
type TestCase struct {
|
|
|
|
|
Input string
|
|
|
|
|
Err bool
|
2023-10-06 11:58:24 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-07 10:43:21 +01:00
|
|
|
testCases := []TestCase{
|
|
|
|
|
{Input: "00000000-0000-0000-0000-000000000000"},
|
|
|
|
|
{Input: "01234567-89ab-cdef-0123-456789abcdef"},
|
|
|
|
|
{Input: "abcdef01-2345-6789-abcd-ef0123456789"},
|
|
|
|
|
{Input: "Not a UUID", Err: true},
|
|
|
|
|
{Input: "00000000-00-0000-0000-00000000000000", Err: true},
|
|
|
|
|
{Input: "00000000000000000000000000000000", Err: true},
|
|
|
|
|
{Input: "01234567-89ab-cdef-ghij-klmnopqrstuv", Err: true},
|
2023-10-06 11:58:24 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-07 10:44:47 +01:00
|
|
|
for _, tc := range testCases {
|
|
|
|
|
err := UUID(tc.Input)
|
|
|
|
|
if tc.Err {
|
2023-10-07 10:43:21 +01:00
|
|
|
if err == nil {
|
2023-10-07 10:44:47 +01:00
|
|
|
t.Errorf("Expected %q to be an invalid UUID; got nil", tc.Input)
|
2023-10-07 10:43:21 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if err != nil {
|
2023-10-07 10:44:47 +01:00
|
|
|
t.Errorf("Expected %q to be a valid UUID; got %s", tc.Input, err)
|
2023-10-07 10:43:21 +01:00
|
|
|
}
|
2023-10-06 11:58:24 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|