-
Notifications
You must be signed in to change notification settings - Fork 10
/
redis_test.go
51 lines (39 loc) · 972 Bytes
/
redis_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
package gokvstores
import (
"context"
"sort"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestRedisStore(t *testing.T) {
ctx := context.Background()
store, err := NewRedisClientStore(ctx, &RedisClientOptions{
Addr: "localhost:6379",
Password: "",
DB: 0,
}, time.Second*30)
assert.Nil(t, err)
testStore(t, store)
is := assert.New(t)
mapResults := map[string]map[string]interface{}{
"order1": {"language": "go"},
"order2": {"integer": "1"},
"order3": {"float": "20.2"},
}
expectedStrings := []string{"order1", "order2", "order3"}
for key, expected := range mapResults {
err = store.SetMap(ctx, key, expected)
is.NoError(err)
}
values, err := store.Keys(ctx, "order*")
is.NoError(err)
sort.Strings(expectedStrings)
result := make([]string, len(values))
for k, v := range values {
result[k], _ = v.(string)
}
sort.Strings(result)
is.Equal(expectedStrings, result)
assert.Nil(t, store.Close())
}