github.com/wulonghui/docker@v1.8.0-rc2/pkg/namesgenerator/names-generator_test.go (about) 1 package namesgenerator 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 // Make sure the generated names are awesome 9 func TestGenerateAwesomeNames(t *testing.T) { 10 name := GetRandomName(0) 11 if !isAwesome(name) { 12 t.Fatalf("Generated name '%s' is not awesome.", name) 13 } 14 } 15 16 func TestNameFormat(t *testing.T) { 17 name := GetRandomName(0) 18 if !strings.Contains(name, "_") { 19 t.Fatalf("Generated name does not contain an underscore") 20 } 21 if strings.ContainsAny(name, "0123456789") { 22 t.Fatalf("Generated name contains numbers!") 23 } 24 } 25 26 func TestNameRetries(t *testing.T) { 27 name := GetRandomName(1) 28 if !strings.Contains(name, "_") { 29 t.Fatalf("Generated name does not contain an underscore") 30 } 31 if !strings.ContainsAny(name, "0123456789") { 32 t.Fatalf("Generated name doesn't contain a number") 33 } 34 35 } 36 37 // To be awesome, a container name must involve cool inventors, be easy to remember, 38 // be at least mildly funny, and always be politically correct for enterprise adoption. 39 func isAwesome(name string) bool { 40 coolInventorNames := true 41 easyToRemember := true 42 mildlyFunnyOnOccasion := true 43 politicallyCorrect := true 44 return coolInventorNames && easyToRemember && mildlyFunnyOnOccasion && politicallyCorrect 45 }