47b9bba5e1
Fixes #2586 This fixes a few races where the name generator asks if a name is free but another container takes the name before it can be reserved. This solves this by generating the name and setting it. If the set fails with a non unique error then we try again. Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
23 lines
660 B
Go
23 lines
660 B
Go
package namesgenerator
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// Make sure the generated names are awesome
|
|
func TestGenerateAwesomeNames(t *testing.T) {
|
|
name := GetRandomName(0)
|
|
if !isAwesome(name) {
|
|
t.Fatalf("Generated name '%s' is not awesome.", name)
|
|
}
|
|
}
|
|
|
|
// To be awesome, a container name must involve cool inventors, be easy to remember,
|
|
// be at least mildly funny, and always be politically correct for enterprise adoption.
|
|
func isAwesome(name string) bool {
|
|
coolInventorNames := true
|
|
easyToRemember := true
|
|
mildlyFunnyOnOccasion := true
|
|
politicallyCorrect := true
|
|
return coolInventorNames && easyToRemember && mildlyFunnyOnOccasion && politicallyCorrect
|
|
}
|