-
Notifications
You must be signed in to change notification settings - Fork 2
/
serf_test.go
119 lines (103 loc) · 2.58 KB
/
serf_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
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"testing"
)
const (
testSerfRPCAddress = "serf:7373"
testSerfRPCAddressWithAuth = "serf-auth:7373"
serfAuthKey = "IX2Uzr/UQ3nrdM7U6wMBFA=="
)
func TestSerfFilterCompare(t *testing.T) {
sf1 := serfFilter{
Name: "",
Status: "alive",
Tags: map[string]string{
"a": "65",
"b": "66",
"c": "67",
},
}
sf2 := serfFilter{
Name: "",
Status: "alive",
Tags: map[string]string{
"a": "65",
"b": "66",
"c": "67",
},
}
sf3 := serfFilter{
Name: "",
Status: "alive",
Tags: map[string]string{
"a": "65",
"b": "66",
},
}
if sf1.Compare(sf2) != true {
t.Errorf("SerfFilter Compare return unexpected result.")
}
if sf1.Compare(sf3) != false {
t.Errorf("SerfFilter Compare return unexpected result.")
}
}
func TestConnectSerfAgentExpectingFailure(t *testing.T) {
client, err := connectSerfAgent("127.0.0.1:55555", "")
defer closeSerfConnection(client)
if err == nil {
t.Errorf("Connect to wrong address return no error")
}
if client != nil {
t.Errorf("Connect to wrong address return opened client")
}
}
func TestConnectSerfAgentExpectingSuccess(t *testing.T) {
client, err := connectSerfAgent(testSerfRPCAddress, "")
defer closeSerfConnection(client)
if err != nil {
t.Errorf("Connect to default address return error: %s", err.Error())
}
if client == nil {
t.Errorf("Connect to default address return nil client. Did you setup test environment?")
}
}
func TestConnectSerfAgentWithAuthKey(t *testing.T) {
client, err := connectSerfAgent(testSerfRPCAddressWithAuth, serfAuthKey)
defer closeSerfConnection(client)
if err != nil {
t.Errorf("Connect to serf-auth address return error. Did you setup test environment?")
}
if client == nil {
t.Errorf("Connect to serf-auth address return nil client. Did you setup test environment?")
t.FailNow()
}
_, err = client.Members()
if err != nil {
t.Errorf("Cannot retrieve member list. Wrong RPC auth key?")
}
}
func TestGetSerfMembers(t *testing.T) {
client, err := connectSerfAgent(testSerfRPCAddress, "")
defer closeSerfConnection(client)
if err != nil {
t.Errorf("Connect to default address return no error: %s", err.Error())
}
if client == nil {
t.FailNow()
}
filter := serfFilter{
Name: "",
Status: "alive",
Tags: map[string]string{
"role": "web",
"dc": "cali",
},
}
members, err := getSerfMembers(client, filter)
if err != nil {
t.Errorf("Connect to default address return no error. Did you setup test environment?")
}
if members == nil {
t.Errorf("No members found from serf. Did you setup test environment?")
}
}