forked from nanopack/shaman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsul_test.go
87 lines (77 loc) · 2.17 KB
/
consul_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
package cache_test
import (
"testing"
"github.com/nanopack/shaman/cache"
"github.com/nanopack/shaman/config"
shaman "github.com/nanopack/shaman/core/common"
)
// test consul cache init
func TestConsulInitialize(t *testing.T) {
config.L2Connect = "consul://127.0.0.1:8500"
err := cache.Initialize()
cache.Initialize()
if err != nil {
t.Errorf("Failed to initalize consul cacher - %v", err)
}
}
// test consul cache addRecord
func TestConsulAddRecord(t *testing.T) {
consulReset()
err := cache.AddRecord(&nanopack)
if err != nil {
t.Errorf("Failed to add record to consul cacher - %v", err)
}
}
// test consul cache getRecord
func TestConsulGetRecord(t *testing.T) {
consulReset()
cache.AddRecord(&nanopack)
_, err := cache.GetRecord("nanobox.io")
_, err2 := cache.GetRecord("nanopack.io")
if err == nil || err2 != nil {
t.Errorf("Failed to get record from consul cacher - %v%v", err, err2)
}
}
// test consul cache updateRecord
func TestConsulUpdateRecord(t *testing.T) {
consulReset()
err := cache.UpdateRecord("nanobox.io", &nanopack)
err2 := cache.UpdateRecord("nanopack.io", &nanopack)
if err != nil || err2 != nil {
t.Errorf("Failed to update record in consul cacher - %v%v", err, err2)
}
}
// test consul cache deleteRecord
func TestConsulDeleteRecord(t *testing.T) {
consulReset()
err := cache.DeleteRecord("nanobox.io")
cache.AddRecord(&nanopack)
err2 := cache.DeleteRecord("nanopack.io")
if err != nil || err2 != nil {
t.Errorf("Failed to delete record from consul cacher - %v%v", err, err2)
}
}
// test consul cache resetRecords
func TestConsulResetRecords(t *testing.T) {
consulReset()
err := cache.ResetRecords(&nanoBoth)
if err != nil {
t.Errorf("Failed to reset records in consul cacher - %v", err)
}
}
// test consul cache listRecords
func TestConsulListRecords(t *testing.T) {
consulReset()
_, err := cache.ListRecords()
cache.ResetRecords(&nanoBoth)
_, err2 := cache.ListRecords()
if err != nil || err2 != nil {
t.Errorf("Failed to list records in consul cacher - %v%v", err, err2)
}
}
func consulReset() {
config.L2Connect = "consul://127.0.0.1:8500"
cache.Initialize()
blank := make([]shaman.Resource, 0, 0)
cache.ResetRecords(&blank)
}