-
Notifications
You must be signed in to change notification settings - Fork 3
/
client_test.go
95 lines (86 loc) · 1.5 KB
/
client_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
package redis_client
import (
"context"
"github.com/alicebob/miniredis/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)
type command struct {
input []interface{}
output interface{}
}
func TestConnect(t *testing.T) {
tt := []struct {
name string
commands []command
}{
{
name: "execute a set and a get",
commands: []command{
{
input: []interface{}{
"SET",
"some-key",
"Maurício",
},
output: "OK",
},
{
input: []interface{}{
"GET",
"some-key",
},
output: "Maurício",
},
},
},
{
name: "execute a get",
commands: []command{
{
input: []interface{}{
"GET",
"some-other-key",
},
output: nil,
},
},
},
{
name: "execute a set and get with UTF characters",
commands: []command{
{
input: []interface{}{
"SET",
"対馬",
"Tsushima",
},
output: "OK",
},
{
input: []interface{}{
"GET",
"対馬",
},
output: "Tsushima",
},
},
},
}
for _, ts := range tt {
t.Run(ts.name, func(t *testing.T) {
server, err := miniredis.Run()
require.NoError(t, err)
defer server.Close()
client, err := Connect(context.Background(), server.Addr())
require.NoError(t, err)
defer client.Close()
for _, c := range ts.commands {
result, err := client.Send(c.input)
require.NoError(t, err)
assert.Equal(t, c.output, result.Content())
}
})
}
}