mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-05 00:15:44 +00:00
In the moby/moby, the namesgenerator is internal. We still want to depend on it, so this commit copies it from moby/moby to our code-base. The good thing is the file is frozen upstream, so no more changes are going to appear in it. Fixes: #27536. Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
40 lines
1,014 B
Go
40 lines
1,014 B
Go
// This file has been copied from
|
|
// https://github.com/moby/moby/tree/a52171f5eeb6e553e7c4744abf6b722962b2aca4/internal/namesgenerator.
|
|
// It is licensed under the Apache License 2.0.
|
|
// See https://github.com/moby/moby/blob/a52171f5eeb6e553e7c4744abf6b722962b2aca4/LICENSE.
|
|
|
|
package namesgenerator
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
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")
|
|
}
|
|
}
|
|
|
|
func BenchmarkGetRandomName(b *testing.B) {
|
|
b.ReportAllocs()
|
|
var out string
|
|
for b.Loop() {
|
|
out = GetRandomName(5)
|
|
}
|
|
b.Log("Last result:", out)
|
|
}
|