-
Notifications
You must be signed in to change notification settings - Fork 2
/
custom_test.go
77 lines (69 loc) · 1.71 KB
/
custom_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
package main
import (
"io/ioutil"
"testing"
)
func TestCheckCustomDomainNameExistence(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 := range SFTable {
ok := checkCustomDomainNameExistence(dn, SFTable)
if !ok {
t.Errorf("Failed to find existing custom domain name %s", dn)
}
}
for _, dn := range []string{"not.exist.serf.", "no.good.nope.", "also.not.exists."} {
ok := checkCustomDomainNameExistence(dn, SFTable)
if ok {
t.Errorf("Failed: Custom domain name %s actually does not exist", dn)
}
}
}
func TestLoadCustomDomainName(t *testing.T) {
data, err := ioutil.ReadFile("custom-domain-name.json")
if err != nil {
t.Errorf("Error reading data from custom-domain-name.json: %s", err.Error())
}
expect := serfFilterTable{
"my-custom-dn-1.serf": serfFilter{
Name: "^web-[0-5][0-9]",
Status: "alive",
Tags: map[string]string{
"role": "web",
},
},
"failed.web.serf": serfFilter{
Name: "^web-.*",
Status: "failed",
Tags: map[string]string{
"role": "web",
},
},
"us.dc.serf": serfFilter{
Tags: map[string]string{
"dc": "us-.*",
},
},
}
result := loadCustomDomainName(data)
if len(expect) != len(result) {
t.Errorf("Failed to load custom domain name: result serf filter table is different from the expected one.")
}
for dn, sf := range expect {
resultSF := result[dn]
if sf.Compare(resultSF) != true {
t.Errorf("Failed to load custom domain name: result serf filter table is different from the expected one.")
}
}
}