-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage_test.go
126 lines (110 loc) · 3.48 KB
/
message_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
package redis
import (
"testing"
redis "github.com/go-redis/redis/v7"
)
var _ MessageDelegate = new(mockMessageDelegate)
type mockMessageDelegate struct {
ackCalledCount int
delCalledCount int
}
// OnAck implements MessageDelegate.
func (d *mockMessageDelegate) OnAck(msg *Message) {
d.ackCalledCount++
}
// OnDel implements MessageDelegate.
func (d *mockMessageDelegate) OnDel(msg *Message) {
d.delCalledCount++
}
func TestMessage(t *testing.T) {
d := new(mockMessageDelegate)
m := Message{
ConsumerGroup: "go-test-channel",
Stream: "goTestStream",
Delegate: d,
XMessage: &redis.XMessage{
ID: "1000",
Values: map[string]interface{}{
"foo": "bar",
},
},
}
{
var expectedAckCalledCount int = 0
if expectedAckCalledCount != d.ackCalledCount {
t.Errorf("mockMessageDelegate.ackCalledCount expect:: %v, got:: %v\n", expectedAckCalledCount, d.ackCalledCount)
}
var expectedDelCalledCount int = 0
if expectedDelCalledCount != d.delCalledCount {
t.Errorf("mockMessageDelegate.delCalledCount expect:: %v, got:: %v\n", expectedDelCalledCount, d.delCalledCount)
}
}
m.Ack()
{
var expectedAckCalledCount int = 1
if expectedAckCalledCount != d.ackCalledCount {
t.Errorf("mockMessageDelegate.ackCalledCount expect:: %v, got:: %v\n", expectedAckCalledCount, d.ackCalledCount)
}
var expectedDelCalledCount int = 0
if expectedDelCalledCount != d.delCalledCount {
t.Errorf("mockMessageDelegate.delCalledCount expect:: %v, got:: %v\n", expectedDelCalledCount, d.delCalledCount)
}
}
m.Del()
{
var expectedAckCalledCount int = 1
if expectedAckCalledCount != d.ackCalledCount {
t.Errorf("mockMessageDelegate.ackCalledCount expect:: %v, got:: %v\n", expectedAckCalledCount, d.ackCalledCount)
}
var expectedDelCalledCount int = 1
if expectedDelCalledCount != d.delCalledCount {
t.Errorf("mockMessageDelegate.delCalledCount expect:: %v, got:: %v\n", expectedDelCalledCount, d.delCalledCount)
}
}
m.Ack()
m.Del()
{
var expectedAckCalledCount int = 1
if expectedAckCalledCount != d.ackCalledCount {
t.Errorf("mockMessageDelegate.ackCalledCount expect:: %v, got:: %v\n", expectedAckCalledCount, d.ackCalledCount)
}
var expectedDelCalledCount int = 1
if expectedDelCalledCount != d.delCalledCount {
t.Errorf("mockMessageDelegate.delCalledCount expect:: %v, got:: %v\n", expectedDelCalledCount, d.delCalledCount)
}
}
}
func TestMessage_Clone(t *testing.T) {
d := new(mockMessageDelegate)
m := &Message{
ConsumerGroup: "go-test-channel",
Stream: "goTestStream",
Delegate: d,
XMessage: &redis.XMessage{
ID: "1000",
Values: map[string]interface{}{
"foo": "bar",
},
},
}
cloned := m.Clone()
if m == cloned {
t.Errorf("cloned Message should different then self\n")
}
var expectedConsumerGroup string = m.ConsumerGroup
if expectedConsumerGroup != cloned.ConsumerGroup {
t.Errorf("cloned.ConsumerGroup expect:: %v, got:: %v\n", expectedConsumerGroup, cloned.ConsumerGroup)
}
var expectedStream string = m.Stream
if expectedStream != cloned.Stream {
t.Errorf("cloned.Stream expect:: %v, got:: %v\n", expectedStream, cloned.Stream)
}
var expectedDelegate MessageDelegate = m.Delegate
if expectedDelegate != cloned.Delegate {
t.Errorf("cloned.Delegate expect:: %v, got:: %v\n", expectedDelegate, cloned.Delegate)
}
var expectedXMessage *XMessage = m.XMessage
if expectedXMessage != cloned.XMessage {
t.Errorf("cloned.XMessage expect:: %v, got:: %v\n", expectedXMessage, cloned.XMessage)
}
}