From 4ddc4a1cdfdcfb6f9cb6cf90ace2266fc1186420 Mon Sep 17 00:00:00 2001
From: Dave Tucker
Date: Tue, 21 Jul 2015 15:06:31 +0100
Subject: [PATCH] golint: Lint pkg/namesgenerator
Also addded a couple more tests
Updates #14756
Signed-off-by: Dave Tucker
---
namesgenerator/names-generator.go | 3 +++
namesgenerator/names-generator_test.go | 22 ++++++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/namesgenerator/names-generator.go b/namesgenerator/names-generator.go
index 54a3204..105a122 100644
--- a/namesgenerator/names-generator.go
+++ b/namesgenerator/names-generator.go
@@ -358,6 +358,9 @@ var (
rnd = rand.New(random.NewSource())
)
+// GetRandomName generates a random name from the list of adjectives and surnames in this package
+// formatted as "adjective_surname". For example 'focused_turing'. If retry is non-zero, a random
+// integer between 0 and 10 will be added to the end of the name, e.g `focused_turing3`
func GetRandomName(retry int) string {
begin:
name := fmt.Sprintf("%s_%s", left[rnd.Intn(len(left))], right[rnd.Intn(len(right))])
diff --git a/namesgenerator/names-generator_test.go b/namesgenerator/names-generator_test.go
index 2652d42..f7dae27 100644
--- a/namesgenerator/names-generator_test.go
+++ b/namesgenerator/names-generator_test.go
@@ -1,6 +1,7 @@
package namesgenerator
import (
+ "strings"
"testing"
)
@@ -12,6 +13,27 @@ func TestGenerateAwesomeNames(t *testing.T) {
}
}
+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")
+ }
+
+}
+
// 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 {