uuid_test.go 424 B

12345678910111213141516171819202122
  1. package uuid
  2. import (
  3. "regexp"
  4. "testing"
  5. )
  6. func TestGenerateUUID(t *testing.T) {
  7. prev := GenerateUUID()
  8. for i := 0; i < 100; i++ {
  9. id := GenerateUUID()
  10. if prev == id {
  11. t.Fatalf("Should get a new ID!")
  12. }
  13. matched, err := regexp.MatchString(
  14. "[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}", id)
  15. if !matched || err != nil {
  16. t.Fatalf("expected match %s %v %s", id, matched, err)
  17. }
  18. }
  19. }