uuid_test.go 800 B

123456789101112131415161718192021222324252627282930313233
  1. package validate
  2. import "testing"
  3. func TestUUID(t *testing.T) {
  4. type TestCase struct {
  5. Input string
  6. Err bool
  7. }
  8. testCases := []TestCase{
  9. {Input: "00000000-0000-0000-0000-000000000000"},
  10. {Input: "01234567-89ab-cdef-0123-456789abcdef"},
  11. {Input: "abcdef01-2345-6789-abcd-ef0123456789"},
  12. {Input: "Not a UUID", Err: true},
  13. {Input: "00000000-00-0000-0000-00000000000000", Err: true},
  14. {Input: "00000000000000000000000000000000", Err: true},
  15. {Input: "01234567-89ab-cdef-ghij-klmnopqrstuv", Err: true},
  16. }
  17. for _, tc := range testCases {
  18. err := UUID(tc.Input)
  19. if tc.Err {
  20. if err == nil {
  21. t.Errorf("Expected %q to be an invalid UUID; got nil", tc.Input)
  22. }
  23. } else {
  24. if err != nil {
  25. t.Errorf("Expected %q to be a valid UUID; got %s", tc.Input, err)
  26. }
  27. }
  28. }
  29. }