spiegel_podman/libpod/namesgenerator/names-generator_test.go
Jan Kaluza 8c4edb6121 libpod: include names-generator.go
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>
2026-03-09 16:08:43 +01:00

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)
}