forked from astaxie/goredis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hmget_test.go
56 lines (44 loc) · 1.03 KB
/
hmget_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 goredis
import (
"reflect"
"testing"
)
func TestContainerToString(t *testing.T) {
vals := make(map[string]string, 2)
vals["f1"] = "hello"
vals["f2"] = "world"
args := make([]string, 0, 5)
args = append(args, "myhash")
args, _ = containerToString(reflect.ValueOf(vals), args)
correct_args := make([]string, 5)
correct_args[0] = "myhash"
correct_args[1] = "f1"
correct_args[2] = "hello"
correct_args[3] = "f2"
correct_args[4] = "world"
for i, v := range correct_args {
if args[i] != v {
t.Fatalf("%dth argument should be %s, but it is %s", i, v, args[i])
}
}
}
func TestHmset(t *testing.T) {
var client Client
client.Addr = "127.0.0.1:6379"
client.Db = 13
vals := make(map[string]string, 2)
vals["f1"] = "hello"
vals["f2"] = "world"
key := "myhash"
client.Hmset(key, vals)
for f, v := range vals {
value, err := client.Hget(key, f)
if err != nil {
t.Fatalf("Database error: %v", err)
}
str := string(value)
if str != v {
t.Fatalf("field %s should be %s but it is %s", f, v, str)
}
}
}