forked from nanopack/shaman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscribble_test.go
91 lines (81 loc) · 2.44 KB
/
scribble_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
package cache_test
import (
"os"
"testing"
"github.com/nanopack/shaman/cache"
"github.com/nanopack/shaman/config"
)
// test scribble cache init
func TestScribbleInitialize(t *testing.T) {
config.L2Connect = "/tmp/shamanCache" // default
err := cache.Initialize()
config.L2Connect = "!@#$%^&*()" // unparse-able
err2 := cache.Initialize()
config.L2Connect = "scribble://github.com/roots/file" // unable to init? (test no sudo)
err3 := cache.Initialize()
config.L2Connect = "scribble://github.com/" // defaulting to "/var/db"
cache.Initialize()
if err != nil || err2 == nil || err3 != nil {
t.Errorf("Failed to initalize scribble cacher - %v%v%v", err, err2, err3)
}
}
// test scribble cache addRecord
func TestScribbleAddRecord(t *testing.T) {
scribbleReset()
err := cache.AddRecord(&nanopack)
if err != nil {
t.Errorf("Failed to add record to scribble cacher - %v", err)
}
}
// test scribble cache getRecord
func TestScribbleGetRecord(t *testing.T) {
scribbleReset()
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 scribble cacher - %v%v", err, err2)
}
}
// test scribble cache updateRecord
func TestScribbleUpdateRecord(t *testing.T) {
scribbleReset()
err := cache.UpdateRecord("nanobox.io", &nanopack)
err2 := cache.UpdateRecord("nanopack.io", &nanopack)
if err != nil || err2 != nil {
t.Errorf("Failed to update record in scribble cacher - %v%v", err, err2)
}
}
// test scribble cache deleteRecord
func TestScribbleDeleteRecord(t *testing.T) {
scribbleReset()
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 scribble cacher - %v%v", err, err2)
}
}
// test scribble cache resetRecords
func TestScribbleResetRecords(t *testing.T) {
scribbleReset()
err := cache.ResetRecords(&nanoBoth)
if err != nil {
t.Errorf("Failed to reset records in scribble cacher - %v", err)
}
}
// test scribble cache listRecords
func TestScribbleListRecords(t *testing.T) {
scribbleReset()
_, err := cache.ListRecords()
cache.ResetRecords(&nanoBoth)
_, err2 := cache.ListRecords()
if err != nil || err2 != nil {
t.Errorf("Failed to list records in scribble cacher - %v%v", err, err2)
}
}
func scribbleReset() {
os.RemoveAll("/tmp/shamanCache")
config.L2Connect = "scribble://github.com/tmp/shamanCache"
cache.Initialize()
}