-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhoard_test.go
75 lines (60 loc) · 1.52 KB
/
hoard_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
package redishoard
import (
"testing"
"time"
"github.com/go-redis/redis"
ssp "github.com/sqrldev/server-go-ssp"
)
// Redis must be installed locally on the default port to run these tests
func TestSave(t *testing.T) {
client := redis.NewUniversalClient(&redis.UniversalOptions{})
h := NewHoard(client)
var nut ssp.Nut = "blah"
hoardCache := &ssp.HoardCache{
State: "boom!",
}
err := h.Save(nut, hoardCache, time.Second)
if err != nil {
t.Fatalf("Failed saving hoard cache: %v", err)
}
val, err := h.Get(nut)
if err != nil {
t.Fatalf("Failed getting from Hoard: %v", err)
}
if val.State != "boom!" {
t.Fatalf("Wrong value from Hoard: %#v", val)
}
}
func TestGetAndDelete(t *testing.T) {
client := redis.NewUniversalClient(&redis.UniversalOptions{})
h := NewHoard(client)
var nut ssp.Nut = "GetAndDelete"
hoardCache := &ssp.HoardCache{
State: "boom!",
}
err := h.Save(nut, hoardCache, time.Second)
if err != nil {
t.Fatalf("Failed saving hoard cache: %v", err)
}
val, err := h.Get(nut)
if err != nil {
t.Fatalf("Failed Get from Hoard: %v", err)
}
if val.State != "boom!" {
t.Fatalf("Wrong value from Hoard: %#v", val)
}
val, err = h.GetAndDelete(nut)
if err != nil {
t.Fatalf("Failed GetAndDelete from Hoard: %v", err)
}
if val.State != "boom!" {
t.Fatalf("Wrong value from Hoard: %#v", val)
}
val, err = h.GetAndDelete(nut)
if err != ssp.ErrNotFound {
t.Fatalf("Should have been deleted but wasn't: %v", err)
}
if val != nil {
t.Fatalf("Wrong value from Hoard: %#v", val)
}
}