File: name_generator_test.go

package info (click to toggle)
golang-github-scaleway-scaleway-sdk-go 1.0.0~beta12-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,000 kB
  • sloc: javascript: 160; sh: 70; makefile: 3
file content (44 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Source: github.com/docker/docker/pkg/namesgenerator

package namegenerator

import (
	"strings"
	"testing"
)

func TestNameFormat(t *testing.T) {
	name := GetRandomName()
	if strings.Count(name, "-") != 1 {
		t.Fatalf("Generated name does not contain exactly 1 hyphen")
	}
	if strings.ContainsAny(name, "0123456789") {
		t.Fatalf("Generated name contains numbers!")
	}
}

func TestNameFormatWithPrefix(t *testing.T) {
	name := GetRandomName("scw")
	if strings.Count(name, "-") != 2 {
		t.Fatalf("Generated name does not contain exactly 2 hyphens")
	}
	if !strings.HasPrefix(name, "scw-") {
		t.Fatalf("Generated name must begin with \"tf-scw-\"")
	}
	if strings.ContainsAny(name, "0123456789") {
		t.Fatalf("Generated name contains numbers!")
	}
}

func TestNameFormatWithPrefixes(t *testing.T) {
	name := GetRandomName("tf", "scw")
	if strings.Count(name, "-") != 3 {
		t.Fatalf("Generated name does not contain exactly 3 hyphens")
	}
	if !strings.HasPrefix(name, "tf-scw-") {
		t.Fatalf("Generated name must begin with \"tf-scw-\"")
	}
	if strings.ContainsAny(name, "0123456789") {
		t.Fatalf("Generated name contains numbers!")
	}
}