uuid_test.go 661 B

1234567891011121314151617181920212223242526272829303132
  1. package validate
  2. import "testing"
  3. func TestInvalidUUID(t *testing.T) {
  4. invalid := []string{
  5. "Not a UUID",
  6. "00000000-00-0000-0000-00000000000000",
  7. "00000000000000000000000000000000",
  8. "01234567-89ab-cdef-ghij-klmnopqrstuv",
  9. }
  10. for _, uuid := range invalid {
  11. if err := UUID(uuid); err == nil {
  12. t.Errorf("%s is not a valid UUID", uuid)
  13. }
  14. }
  15. }
  16. func TestValidUUID(t *testing.T) {
  17. valid := []string{
  18. "00000000-0000-0000-0000-000000000000",
  19. "01234567-89ab-cdef-0123-456789abcdef",
  20. "abcdef01-2345-6789-abcd-ef0123456789",
  21. }
  22. for _, uuid := range valid {
  23. if err := UUID(uuid); err != nil {
  24. t.Errorf("%s is a valid UUID", uuid)
  25. }
  26. }
  27. }