forked from redis/rueidis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
result_test.go
97 lines (85 loc) · 2.18 KB
/
result_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package mock
import (
"errors"
"reflect"
"testing"
"github.com/rueian/rueidis"
)
func TestRedisString(t *testing.T) {
m := RedisString("s")
if v, err := m.ToString(); err != nil || v != "s" {
t.Fatalf("unexpected value %v", v)
}
}
func TestRedisError(t *testing.T) {
m := RedisError("s")
if err := m.Error(); err == nil || err.Error() != "s" {
t.Fatalf("unexpected value %v", err)
}
}
func TestRedisInt64(t *testing.T) {
m := RedisInt64(1)
if v, err := m.ToInt64(); err != nil || v != int64(1) {
t.Fatalf("unexpected value %v", v)
}
if v, err := m.AsInt64(); err != nil || v != int64(1) {
t.Fatalf("unexpected value %v", v)
}
}
func TestRedisFloat64(t *testing.T) {
m := RedisFloat64(1)
if v, err := m.ToFloat64(); err != nil || v != float64(1) {
t.Fatalf("unexpected value %v", v)
}
if v, err := m.AsFloat64(); err != nil || v != float64(1) {
t.Fatalf("unexpected value %v", v)
}
}
func TestRedisBool(t *testing.T) {
m := RedisBool(true)
if v, err := m.ToBool(); err != nil || v != true {
t.Fatalf("unexpected value %v", v)
}
if v, err := m.AsBool(); err != nil || v != true {
t.Fatalf("unexpected value %v", v)
}
}
func TestRedisNil(t *testing.T) {
m := RedisNil()
if err := m.Error(); err == nil {
t.Fatalf("unexpected value %v", err)
}
if v := m.IsNil(); v != true {
t.Fatalf("unexpected value %v", v)
}
}
func TestRedisArray(t *testing.T) {
m := RedisArray(RedisString("0"), RedisString("1"), RedisString("2"))
if arr, err := m.AsStrSlice(); err != nil || !reflect.DeepEqual(arr, []string{"0", "1", "2"}) {
t.Fatalf("unexpected value %v", err)
}
}
func TestRedisMap(t *testing.T) {
m := RedisMap(map[string]rueidis.RedisMessage{
"a": RedisString("0"),
"b": RedisString("1"),
})
if arr, err := m.AsStrMap(); err != nil || !reflect.DeepEqual(arr, map[string]string{
"a": "0",
"b": "1",
}) {
t.Fatalf("unexpected value %v", err)
}
}
func TestRedisResult(t *testing.T) {
r := Result(RedisNil())
if err := r.Error(); !rueidis.IsRedisNil(err) {
t.Fatalf("unexpected value %v", err)
}
}
func TestErrorResult(t *testing.T) {
r := ErrorResult(errors.New("any"))
if err := r.Error(); err.Error() != "any" {
t.Fatalf("unexpected value %v", err)
}
}