-
Notifications
You must be signed in to change notification settings - Fork 3
/
tempdb_test.go
136 lines (123 loc) · 2.22 KB
/
tempdb_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package tempdb
import (
"crypto/tls"
"net"
"testing"
"time"
)
func TestTempdb(t *testing.T) {
t.Parallel()
tests := []struct {
scenario string
function func(*testing.T)
}{
{
"new",
testNew,
},
{
"insert",
testInsert,
},
{
"find",
testFind,
},
}
for _, test := range tests {
t.Run(test.scenario, func(t *testing.T) {
test.function(t)
})
}
}
func testNew(t *testing.T) {
_, err := New(Options{
Network: "foo",
Addr: "localhost:6379",
Dialer: func() (c net.Conn, err error) { return },
DB: 1,
Password: "foo",
MaxRetries: 1,
DialTimeout: time.Second * 5,
ReadTimeout: time.Second * 5,
WriteTimeout: time.Second * 5,
PoolSize: 1,
PoolTimeout: time.Second * 5,
IdleTimeout: time.Second * 5,
IdleCheckFrequency: time.Second * 5,
ReadOnly: true,
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
},
})
if err != nil {
t.Fatalf("expected to initialize tempdb: %s", err)
}
}
func testInsert(t *testing.T) {
temp, err := New(Options{})
if err != nil {
t.Fatalf("expected to initialize tempdb: %s", err)
}
cases := []struct {
key, value string
wantErr bool
}{
{
"key", "value", false,
},
{
"", "value", true,
},
{
"key", "", true,
},
}
for _, c := range cases {
err := temp.Insert(c.key, c.value, 0)
if c.wantErr {
if err == nil {
t.Fatalf("unexpected insert return value: %v", err)
}
} else {
if err != nil {
t.Fatalf("unexpected insert return value: %v", err)
}
}
}
}
func testFind(t *testing.T) {
temp, err := New(Options{})
if err != nil {
t.Fatalf("expected to initialize tempdb: %v", err)
}
if err := temp.Insert("key", "value", 0); err != nil {
t.Fatalf("expected to insert key/value: %v", err)
}
cases := []struct {
key string
wantErr bool
}{
{
"", true,
},
{
"invalid_key", true,
},
{
"key", false,
},
}
for _, c := range cases {
_, err := temp.Find(c.key)
if c.wantErr {
if err == nil {
t.Fatalf("unexpected find return value")
}
} else {
if err != nil {
t.Fatalf("unexpected find return value")
}
}
}
}