-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache_test.go
56 lines (45 loc) · 1.03 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
package microcache
import (
"testing"
"github.com/lpicanco/microcache/configuration"
)
func TestPutGet(t *testing.T) {
cache := New(configuration.DefaultConfiguration(100))
structValue := struct {
key int32
value string
}{
42, "answer",
}
cases := []struct {
in string
want interface{}
}{
{"Integer value", 432},
{"String value", "string key"},
{"String value", "string key 2"},
{"Array value", [3]string{"Val01", "Val02", "Val03"}},
{"Struct value", structValue},
{"Struct reference value", &structValue},
}
for _, c := range cases {
cache.Put(c.in, c.want)
got, found := cache.Get(c.in)
if !found {
t.Errorf("Cache.Get(%q) not found", c.in)
}
if got != c.want {
t.Errorf("Cache.Get(%q) == %v, want %v", c.in, got, c.want)
}
}
}
func TestNotFound(t *testing.T) {
cache := New(configuration.DefaultConfiguration(100))
got, found := cache.Get("key")
if found {
t.Error("Cache.Get(key) returned true")
}
if got != nil {
t.Errorf("Cache.Get(key) == %v, want %v", got, nil)
}
}