-
Notifications
You must be signed in to change notification settings - Fork 0
/
namegen_test.go
66 lines (59 loc) · 1.51 KB
/
namegen_test.go
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package namegen // import "github.com/docker/docker/pkg/namesgenerator"
import (
"strings"
"testing"
)
func Test_GetName_Format(t *testing.T) {
name := GetName(0)
if !strings.Contains(name, "_") {
t.Fatalf("Generated name does not contain an underscore")
}
if strings.ContainsAny(name, "0123456789") {
t.Fatalf("Generated name contains numbers!")
}
}
func Test_GetNameWithSeed_Format(t *testing.T) {
name := GetNameWithSeed(nil, 0)
if !strings.Contains(name, "_") {
t.Fatalf("Generated name does not contain an underscore")
}
if strings.ContainsAny(name, "0123456789") {
t.Fatalf("Generated name contains numbers!")
}
}
func Test_GetName_Retries(t *testing.T) {
name := GetName(1)
if !strings.Contains(name, "_") {
t.Fatalf("Generated name does not contain an underscore")
}
if !strings.ContainsAny(name, "0123456789") {
t.Fatalf("Generated name doesn't contain a number")
}
}
func Test_GetNameWithSeed_Retries(t *testing.T) {
name := GetNameWithSeed(nil, 1)
if !strings.Contains(name, "_") {
t.Fatalf("Generated name does not contain an underscore")
}
if !strings.ContainsAny(name, "0123456789") {
t.Fatalf("Generated name doesn't contain a number")
}
}
func Benchmark_GetName(b *testing.B) {
b.ReportAllocs()
var out string
for n := 0; n < b.N; n++ {
out = GetName(5)
}
_ = out
// b.Log("Last result:", out)
}
func Benchmark_GetNameWithSeed(b *testing.B) {
b.ReportAllocs()
var out string
for n := 0; n < b.N; n++ {
out = GetNameWithSeed(nil, 5)
}
_ = out
// b.Log("Last result:", out)
}