2018-02-05 16:05:59 -05:00
|
|
|
package namesgenerator // import "github.com/docker/docker/pkg/namesgenerator"
|
2013-10-28 17:23:33 -04:00
|
|
|
|
|
|
|
import (
|
2015-07-21 10:06:31 -04:00
|
|
|
"strings"
|
2013-10-28 17:23:33 -04:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-07-21 10:06:31 -04:00
|
|
|
func TestNameFormat(t *testing.T) {
|
|
|
|
name := GetRandomName(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 TestNameRetries(t *testing.T) {
|
|
|
|
name := GetRandomName(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")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-09-14 09:15:29 -04:00
|
|
|
|
|
|
|
func BenchmarkGetRandomName(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
|
|
|
var out string
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
out = GetRandomName(5)
|
|
|
|
}
|
|
|
|
b.Log("Last result:", out)
|
|
|
|
}
|