-
Notifications
You must be signed in to change notification settings - Fork 2
/
parse_test.go
107 lines (94 loc) · 2.17 KB
/
parse_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"testing"
)
func TestParseDomainName(t *testing.T) {
config.Parse()
SFTable := serfFilterTable{
"dead.digit.serf.": serfFilter{
Name: "^[0-9].*",
Status: "failed",
},
"digit.name.serf.": serfFilter{
Name: "^[0-9].*",
Status: "alive",
},
"dead.serf.": serfFilter{
Status: "failed",
},
}
for dn, sf := range SFTable {
resultSF := parseDomainName(dn, SFTable)
ok := sf.Compare(resultSF)
if !ok {
t.Errorf("Failed to parse custom domain name %s", dn)
}
}
domainNameSample := "foo.srv.cali.dc.serf."
expect := serfFilter{
Tags: map[string]string{
"srv": "foo",
"dc": "cali",
},
Status: "alive",
}
result := parseDomainName(domainNameSample, SFTable)
ok := expect.Compare(result)
if !ok {
t.Errorf("Failed to parse domain name %s", domainNameSample)
}
}
func TestParseTagsDomainName(t *testing.T) {
config.Parse()
domainNameSample := "foo.srv.cali.dc.serf."
expectedSerfFilter := serfFilter{
Tags: map[string]string{
"srv": "foo",
"dc": "cali",
},
Status: "alive",
}
resultSerfFilter := parseTagsDomainName(domainNameSample)
ok := expectedSerfFilter.Compare(resultSerfFilter)
if !ok {
t.Errorf("Failed to parse domain name %s", domainNameSample)
}
}
func TestFindTag(t *testing.T) {
sample := "a.b.c.d."
expectedTagValue := "a"
expectedTagName := "b"
expectedRemain := "c.d."
resultTagValue, resultTagName, resultRemain := findTag(sample)
if expectedTagName != resultTagName {
t.Errorf("Failed to find tag in domain name")
}
if expectedTagValue != resultTagValue {
t.Errorf("Failed to find tag in domain name")
}
if expectedRemain != resultRemain {
t.Errorf("Failed to find tag in domain name")
}
}
func TestParseCustomDomainName(t *testing.T) {
SFTable := serfFilterTable{
"dead.digit.serf.": serfFilter{
Name: "^[0-9].*",
Status: "failed",
},
"digit.name.serf.": serfFilter{
Name: "^[0-9].*",
Status: "alive",
},
"dead.serf.": serfFilter{
Status: "failed",
},
}
for dn, sf := range SFTable {
resultSF := parseCustomDomainName(dn, SFTable)
ok := sf.Compare(resultSF)
if !ok {
t.Errorf("Failed to parse custom domain name %s", dn)
}
}
}