-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnamers_test.go
40 lines (32 loc) · 1.2 KB
/
namers_test.go
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
package namecon_test
import (
"strings"
"testing"
"github.com/honeytrap/namecon"
)
// TestSimpleNamer validates the use of the provided namer to match the
// giving template rule set provided.
func TestSimpleNamer(t *testing.T) {
namer := namecon.GenerateNamer(namecon.SimpleNamer{}, "API-%s-%s")
firstName := namer("Trappa")
secondName := namer("Honey")
if firstName == secondName {
t.Fatalf("Should have successfully generated new unique generation names")
}
t.Logf("Should have successfully generated new unique generation names")
}
// TestLimitedNamer validates the use of the provided namer to match the
// giving template rule set provided.
func TestLimitedNamer(t *testing.T) {
namer := namecon.GenerateNamer(namecon.NewLimitNamer(50, 10), "API-%s-%s")
newName := namer("TrappaHouseOfSundaySchool")
if len(newName) > 50 {
t.Fatalf("Should have successfully new name within 120 characters")
}
t.Logf("Should have successfully new name within 120 characters")
parts := strings.Split(newName, "-")
if len(parts[1]) > 10 {
t.Fatalf("Should have successfully generated base name piece under 20 characters")
}
t.Logf("Should have successfully generated base name piece under 20 characters")
}