github.com/docker/engine@v22.0.0-20211208180946-d456264580cf+incompatible/pkg/namesgenerator/names-generator_test.go (about)

     1  package namesgenerator // import "github.com/docker/docker/pkg/namesgenerator"
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func TestNameFormat(t *testing.T) {
     9  	name := GetRandomName(0)
    10  	if !strings.Contains(name, "_") {
    11  		t.Fatalf("Generated name does not contain an underscore")
    12  	}
    13  	if strings.ContainsAny(name, "0123456789") {
    14  		t.Fatalf("Generated name contains numbers!")
    15  	}
    16  }
    17  
    18  func TestNameRetries(t *testing.T) {
    19  	name := GetRandomName(1)
    20  	if !strings.Contains(name, "_") {
    21  		t.Fatalf("Generated name does not contain an underscore")
    22  	}
    23  	if !strings.ContainsAny(name, "0123456789") {
    24  		t.Fatalf("Generated name doesn't contain a number")
    25  	}
    26  
    27  }
    28  
    29  func BenchmarkGetRandomName(b *testing.B) {
    30  	b.ReportAllocs()
    31  	var out string
    32  	for n := 0; n < b.N; n++ {
    33  		out = GetRandomName(5)
    34  	}
    35  	b.Log("Last result:", out)
    36  }