uuid_test.go 772 B

123456789101112131415161718192021222324252627282930313233343536
  1. package validate
  2. import (
  3. "errors"
  4. "fmt"
  5. "testing"
  6. )
  7. func ExampleUUID() {
  8. fmt.Println(UUID("not a uuid"))
  9. // Output: invalid UUID
  10. }
  11. func TestUUID(t *testing.T) {
  12. testCases := map[string]error{
  13. "00000000-0000-0000-0000-000000000000": nil,
  14. "01234567-89ab-cdef-0123-456789abcdef": nil,
  15. "abcdef01-2345-6789-abcd-ef0123456789": nil,
  16. "not a uuid": ErrInvalidUUID,
  17. "00000000-00-0000-0000-00000000000000": ErrInvalidUUID,
  18. "00000000000000000000000000000000": ErrInvalidUUID,
  19. "01234567-89ab-cdef-ghij-klmnopqrstuv": ErrInvalidUUID,
  20. }
  21. for input, want := range testCases {
  22. t.Run(input, func(t *testing.T) {
  23. got := UUID(input)
  24. if !errors.Is(got, want) {
  25. t.Error("got", got)
  26. t.Error("want", want)
  27. }
  28. })
  29. }
  30. }