forked from bluele/gcache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers_test.go
More file actions
37 lines (33 loc) · 747 Bytes
/
Copy pathhelpers_test.go
File metadata and controls
37 lines (33 loc) · 747 Bytes
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
package gcache_test
import (
"fmt"
"github.com/bluele/gcache"
"testing"
)
func loader(key interface{}) (interface{}, error) {
return fmt.Sprintf("valueFor%s", key), nil
}
func testSetCache(t *testing.T, gc gcache.Cache, numbers int) {
for i := 0; i < numbers; i++ {
key := fmt.Sprintf("Key-%d", i)
value, err := loader(key)
if err != nil {
t.Error(err)
return
}
gc.Set(key, value)
}
}
func testGetCache(t *testing.T, gc gcache.Cache, numbers int) {
for i := 0; i < numbers; i++ {
key := fmt.Sprintf("Key-%d", i)
v, err := gc.Get(key)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
expectedV, _ := loader(key)
if v != expectedV {
t.Errorf("Expected value is %v, not %v", expectedV, v)
}
}
}