-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions_test.go
73 lines (66 loc) · 1.56 KB
/
functions_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
package consulmq
import "testing"
import "time"
func TestRegisterServiceConsul(t *testing.T) {
mq, err := Connect(Config{
Address: "172.17.0.2:8500",
})
if err != nil {
t.Error(err)
}
err = registerServiceConsul(mq)
if err != nil {
t.Error(err)
}
}
func TestGetIP(t *testing.T) {
ip, err := getIP("8.8.8.8:53")
if err != nil {
t.Error(err)
}
if ip == "" {
t.Errorf("Unable to get local IP!")
}
_, err = getIP("failure")
if err == nil {
t.Errorf("Something failed!")
}
}
func TestSetDefaults(t *testing.T) {
conf := Config{}
newconf := Config{}
// test for setting on nul values
def := setDefaults(&conf, &newconf, defaults)
if def.Address != defaults["Address"] {
t.Errorf("Unable to set address default value")
}
if def.Datacenter != defaults["Datacenter"] {
t.Errorf("Unable to set datacenter default value")
}
if def.MQName != defaults["MQName"] {
t.Errorf("Unable to set message queue default value")
}
if def.TTL != 87600*time.Hour {
t.Errorf("Unable to set TTL default value")
}
// test for not over-writing given values
conf = Config{
Address: "1.2.3.4:8500",
Datacenter: "testDatacenter",
MQName: "testMQ",
TTL: 5 * time.Minute,
}
def = setDefaults(&conf, &newconf, defaults)
if def.Address != "1.2.3.4:8500" {
t.Errorf("Address value was not preserved")
}
if def.Datacenter != "testDatacenter" {
t.Errorf("Datacenter value was not preserved")
}
if def.MQName != "testMQ" {
t.Errorf("MQName value was not preserved")
}
if def.TTL != 5*time.Minute {
t.Errorf("TTLvalue was not preserved")
}
}