-
Notifications
You must be signed in to change notification settings - Fork 23
/
consumer_message_test.go
87 lines (72 loc) · 1.5 KB
/
consumer_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
package rabbus
import (
"testing"
"github.com/streadway/amqp"
)
func TestConsumerMessage(t *testing.T) {
t.Parallel()
tests := []struct {
scenario string
function func(*testing.T)
}{
{
"ack message",
testAckMessage,
},
{
"nack message",
testNackMessage,
},
{
"reject message",
testRejectMessage,
},
}
for _, test := range tests {
t.Run(test.scenario, func(t *testing.T) {
test.function(t)
})
}
}
func testAckMessage(t *testing.T) {
ack := &acknowledger{}
d := amqp.Delivery{Acknowledger: ack}
cm := newConsumerMessage(d)
cm.Ack(false)
if !ack.ackInvoked {
t.Fatal("expected acknowledger.Ack to be invoked")
}
}
func testNackMessage(t *testing.T) {
ack := &acknowledger{}
d := amqp.Delivery{Acknowledger: ack}
cm := newConsumerMessage(d)
cm.Nack(false, false)
if !ack.nackInvoked {
t.Fatal("expected acknowledger.Nack to be invoked")
}
}
func testRejectMessage(t *testing.T) {
ack := &acknowledger{}
d := amqp.Delivery{Acknowledger: ack}
cm := newConsumerMessage(d)
cm.Reject(false)
if !ack.rejectInvoked {
t.Fatal("expected acknowledger.Reject to be invoked")
}
}
type acknowledger struct {
ackInvoked, nackInvoked, rejectInvoked bool
}
func (a *acknowledger) Ack(tag uint64, multiple bool) error {
a.ackInvoked = true
return nil
}
func (a *acknowledger) Nack(tag uint64, multiple bool, requeue bool) error {
a.nackInvoked = true
return nil
}
func (a *acknowledger) Reject(tag uint64, requeue bool) error {
a.rejectInvoked = true
return nil
}