forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis_test.go
92 lines (73 loc) · 2.22 KB
/
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
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
package main
import (
"encoding/hex"
"testing"
//"fmt"
//"log/syslog"
)
func TestRedisParser_simpleRequest(t *testing.T) {
data := []byte(
"2a330d0a24330d0a5345540d0a24340d0a6b6579310d0a24350d0a48656c6c6f0d0a")
message, err := hex.DecodeString(string(data))
if err != nil {
t.Error("Failed to decode hex string")
}
stream := &RedisStream{tcpStream: nil, data: message, message: new(RedisMessage)}
ok, complete := redisMessageParser(stream)
if !ok {
t.Error("Parsing returned error")
}
if !complete {
t.Error("Expecting a complete message")
}
if !stream.message.IsRequest {
t.Error("Failed to parse Redis request")
}
if stream.message.Message != "SET key1 Hello" {
t.Error("Failed to parse Redis request: %s", stream.message.Message)
}
}
func TestRedisParser_PosResult(t *testing.T) {
data := []byte(
"2b4f4b0d0a")
message, err := hex.DecodeString(string(data))
if err != nil {
t.Error("Failed to decode hex string")
}
stream := &RedisStream{tcpStream: nil, data: message, message: new(RedisMessage)}
ok, complete := redisMessageParser(stream)
if !ok {
t.Error("Parsing returned error")
}
if !complete {
t.Error("Expecting a complete message")
}
if stream.message.IsRequest {
t.Error("Failed to parse Redis response")
}
if stream.message.Message != "OK" {
t.Error("Failed to parse Redis response: %s", stream.message.Message)
}
}
func TestRedisParser_NilResult(t *testing.T) {
data := []byte(
"2a310d0a242d310d0a")
message, err := hex.DecodeString(string(data))
if err != nil {
t.Error("Failed to decode hex string")
}
stream := &RedisStream{tcpStream: nil, data: message, message: new(RedisMessage)}
ok, complete := redisMessageParser(stream)
if !ok {
t.Error("Parsing returned error")
}
if !complete {
t.Error("Expecting a complete message")
}
if stream.message.IsRequest {
t.Error("Failed to parse Redis response")
}
if stream.message.Message != "nil" {
t.Error("Failed to parse Redis response: %s", stream.message.Message)
}
}