-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmap_test.go
49 lines (36 loc) · 1.04 KB
/
map_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
package sync
import (
"testing"
"time"
)
const (
testKey = "foo"
testValue = "bar"
)
func TestSyncMap(t *testing.T) {
c := New()
if err := c.Save(testKey, testValue, 1*time.Nanosecond); err != nil {
t.Errorf("save fail: expected nil, got %v", err)
}
if _, err := c.Fetch(testKey); err == nil {
t.Errorf("fetch fail: expected an error, got %v", err)
}
_ = c.Save(testKey, testValue, 10*time.Second)
if res, _ := c.Fetch(testKey); res != testValue {
t.Errorf("fetch fail, wrong value: expected %s, got %s", testValue, res)
}
_ = c.Save(testKey, testValue, 0)
if !c.Contains(testKey) {
t.Errorf("contains failed: the key %s should be exist", testKey)
}
_ = c.Save("bar", testValue, 0)
if values := c.FetchMulti([]string{testKey, "bar"}); len(values) == 0 {
t.Errorf("fetch multi failed: expected %d, got %d", 2, len(values))
}
if err := c.Flush(); err != nil {
t.Errorf("flush failed: expected nil, got %v", err)
}
if c.Contains(testKey) {
t.Errorf("contains failed: the key %s should not be exist", testKey)
}
}