forked from nanopack/shaman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_test.go
104 lines (88 loc) · 2.31 KB
/
cache_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
package cache_test
import (
"os"
"testing"
"github.com/jcelliott/lumber"
"github.com/nanopack/shaman/cache"
"github.com/nanopack/shaman/config"
shaman "github.com/nanopack/shaman/core/common"
)
var (
nanopack = shaman.Resource{Domain: "nanopack.io.", Records: []shaman.Record{{Address: "127.0.0.1"}}}
nanobox = shaman.Resource{Domain: "nanobox.io.", Records: []shaman.Record{{Address: "127.0.0.2"}}}
nanoBoth = []shaman.Resource{nanopack, nanobox}
)
func TestMain(m *testing.M) {
// manually configure
// config.Log = lumber.NewConsoleLogger(lumber.LvlInt("trace"))
config.Log = lumber.NewConsoleLogger(lumber.LvlInt("FATAL"))
// run tests
rtn := m.Run()
os.Exit(rtn)
}
// test nil cache init
func TestNoneInitialize(t *testing.T) {
config.L2Connect = "none://"
err := cache.Initialize()
if err != nil {
t.Errorf("Failed to initalize none cacher - %v", err)
}
}
// test nil cache addRecord
func TestNoneAddRecord(t *testing.T) {
noneReset()
err := cache.AddRecord(&shaman.Resource{})
if err != nil {
t.Errorf("Failed to add record to none cacher - %v", err)
}
}
// test nil cache getRecord
func TestNoneGetRecord(t *testing.T) {
noneReset()
_, err := cache.GetRecord("nanopack.io")
if err != nil {
t.Errorf("Failed to get record from none cacher - %v", err)
}
}
// test nil cache updateRecord
func TestNoneUpdateRecord(t *testing.T) {
noneReset()
err := cache.UpdateRecord("nanopack.io", &shaman.Resource{})
if err != nil {
t.Errorf("Failed to update record in none cacher - %v", err)
}
}
// test nil cache deleteRecord
func TestNoneDeleteRecord(t *testing.T) {
noneReset()
err := cache.DeleteRecord("nanopack.io")
if err != nil {
t.Errorf("Failed to delete record from none cacher - %v", err)
}
}
// test nil cache resetRecords
func TestNoneResetRecords(t *testing.T) {
noneReset()
err := cache.ResetRecords(&[]shaman.Resource{})
if err != nil {
t.Errorf("Failed to reset records in none cacher - %v", err)
}
}
// test nil cache listRecords
func TestNoneListRecords(t *testing.T) {
noneReset()
_, err := cache.ListRecords()
if err != nil {
t.Errorf("Failed to list records in none cacher - %v", err)
}
}
func TestNoneExists(t *testing.T) {
noneReset()
if cache.Exists() {
t.Error("Cache exits but shouldn't")
}
}
func noneReset() {
config.L2Connect = "none://"
cache.Initialize()
}