File: uuid_test.go

package info (click to toggle)
golang-github-hashicorp-uuid 0.0~git20160311.0.ebb0a03-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, experimental
  • size: 92 kB
  • ctags: 5
  • sloc: makefile: 2
file content (28 lines) | stat: -rw-r--r-- 522 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package uuid

import (
	"regexp"
	"testing"
)

func TestGenerateUUID(t *testing.T) {
	prev := GenerateUUID()
	for i := 0; i < 100; i++ {
		id := GenerateUUID()
		if prev == id {
			t.Fatalf("Should get a new ID!")
		}

		matched, err := regexp.MatchString(
			"[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}", id)
		if !matched || err != nil {
			t.Fatalf("expected match %s %v %s", id, matched, err)
		}
	}
}

func BenchmarkGenerateUUID(b *testing.B) {
	for n := 0; n < b.N; n++ {
		_ = GenerateUUID()
	}
}