-
Notifications
You must be signed in to change notification settings - Fork 6
/
name_test.go
93 lines (83 loc) · 1.9 KB
/
name_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package grid
import (
"errors"
"fmt"
"strings"
"testing"
)
func TestIsNameValidEmpty(t *testing.T) {
t.Parallel()
if isNameValid("") {
t.Fatal("expected false")
}
}
func TestIsNameValidBadChars(t *testing.T) {
t.Parallel()
for _, c := range strings.Split("( ) ` ~ ! @ # $ % ^ & * + = | \\ { } [ ] : ; ' < > , . ? /", "") {
name := fmt.Sprintf("some-name-%s-that-is-bad", c)
if isNameValid(name) {
t.Fatalf("expected false with name containing: %s", c)
}
}
}
func TestStripNamespaceWithInvalidName(t *testing.T) {
t.Parallel()
_, err := stripNamespace(Peers, "ns", "hello")
if !errors.Is(err, ErrInvalidName) {
t.Fatal("expected invalid name error")
}
}
func TestStripNamespace(t *testing.T) {
t.Parallel()
// Peers
{
res, err := stripNamespace(Peers, "ns", "ns.peer.hello")
if err != nil {
t.Fatal(err)
}
if res != "hello" {
t.Fatal("expected name without namespace")
}
}
// Actors
{
res, err := stripNamespace(Actors, "ns", "ns.actor.hello")
if err != nil {
t.Fatal(err)
}
if res != "hello" {
t.Fatal("expected name without namespace")
}
}
// Mailboxes
{
res, err := stripNamespace(Mailboxes, "ns", "ns.mailbox.hello")
if err != nil {
t.Fatal(err)
}
if res != "hello" {
t.Fatal("expected name without namespace")
}
}
}
func TestNamespaceNameInvalidName(t *testing.T) {
t.Parallel()
_, err := namespaceName(Peers, "valid", "invalid-!")
if !errors.Is(err, ErrInvalidName) {
t.Fatal("expected invalid name error")
}
}
func TestNamespaceNameInvalidNamespace(t *testing.T) {
t.Parallel()
_, err := namespaceName(Peers, "invalid-!", "valid")
if !errors.Is(err, ErrInvalidNamespace) {
t.Fatal("expected invalid namespace error")
}
}
func TestNamespacePrefixInvalidNamespace(t *testing.T) {
t.Parallel()
_, err := namespacePrefix(Peers, "invalid-!")
if !errors.Is(err, ErrInvalidNamespace) {
t.Fatal("expected invalid namespace error")
}
}