@@ -11,7 +11,7 @@ import (
11
11
log "github.com/corvus-ch/logr/buffered"
12
12
"github.com/corvus-ch/rabbitmq-cli-consumer/command"
13
13
"github.com/corvus-ch/rabbitmq-cli-consumer/consumer"
14
- "github.com/corvus-ch/rabbitmq-cli-consumer/metadata "
14
+ "github.com/corvus-ch/rabbitmq-cli-consumer/delivery "
15
15
"github.com/stretchr/testify/assert"
16
16
"github.com/stretchr/testify/mock"
17
17
"github.com/thockin/logr"
@@ -25,26 +25,26 @@ var processingTests = []struct {
25
25
strict bool
26
26
onFailure int
27
27
}{
28
- {"ack" , "Ack" , []interface {}{true }, 0 , false , 0 },
28
+ {"ack" , "Ack" , []interface {}{}, 0 , false , 0 },
29
29
{"reject" , "Reject" , []interface {}{false }, 1 , false , 3 },
30
30
{"rejectRequeue" , "Reject" , []interface {}{true }, 1 , false , 4 },
31
- {"nack" , "Nack" , []interface {}{true , false }, 1 , false , 5 },
32
- {"nackRequeue" , "Nack" , []interface {}{true , true }, 1 , false , 6 },
33
- {"fallback" , "Nack" , []interface {}{true , true }, 1 , false , 0 },
34
- {"strictAck" , "Ack" , []interface {}{true }, 0 , true , 0 },
31
+ {"nack" , "Nack" , []interface {}{false }, 1 , false , 5 },
32
+ {"nackRequeue" , "Nack" , []interface {}{true }, 1 , false , 6 },
33
+ {"fallback" , "Nack" , []interface {}{true }, 1 , false , 0 },
34
+ {"strictAck" , "Ack" , []interface {}{}, 0 , true , 0 },
35
35
{"strictReject" , "Reject" , []interface {}{false }, 3 , true , 0 },
36
36
{"strictRejectRequeue" , "Reject" , []interface {}{true }, 4 , true , 0 },
37
- {"strictNack" , "Nack" , []interface {}{true , false }, 5 , true , 0 },
38
- {"strictNackRequeue" , "Nack" , []interface {}{true , true }, 6 , true , 0 },
37
+ {"strictNack" , "Nack" , []interface {}{false }, 5 , true , 0 },
38
+ {"strictNackRequeue" , "Nack" , []interface {}{true }, 6 , true , 0 },
39
39
}
40
40
41
41
func TestProcessing (t * testing.T ) {
42
42
for _ , test := range processingTests {
43
43
t .Run (test .name , func (t * testing.T ) {
44
44
d := new (TestDelivery )
45
45
b := new (TestBuilder )
46
- p := metadata .Properties {}
47
- di := metadata. DeliveryInfo {}
46
+ p := delivery .Properties {}
47
+ di := delivery. Info {}
48
48
cmd := new (TestCommand )
49
49
body := []byte (test .name )
50
50
c := consumer.Consumer {
@@ -55,9 +55,11 @@ func TestProcessing(t *testing.T) {
55
55
b .On ("GetCommand" , p , di , body ).Return (cmd , nil )
56
56
d .On ("Body" ).Return (body )
57
57
d .On (test .ackMethod , test .ackArgs ... ).Return (nil )
58
+ d .On ("Properties" ).Return (p )
59
+ d .On ("Info" ).Return (di )
58
60
cmd .On ("Run" ).Return (test .exit )
59
61
60
- c .ProcessMessage (d , p , di )
62
+ c .ProcessMessage (d )
61
63
62
64
d .AssertExpectations (t )
63
65
b .AssertExpectations (t )
@@ -70,8 +72,8 @@ func TestCommandFailure(t *testing.T) {
70
72
l := log .New (0 )
71
73
d := new (TestDelivery )
72
74
b := new (TestBuilder )
73
- p := metadata .Properties {}
74
- di := metadata. DeliveryInfo {}
75
+ p := delivery .Properties {}
76
+ di := delivery. Info {}
75
77
body := []byte ("cmdFailure" )
76
78
c := consumer.Consumer {
77
79
Builder : b ,
@@ -80,9 +82,11 @@ func TestCommandFailure(t *testing.T) {
80
82
81
83
b .On ("GetCommand" , p , di , body ).Return (new (TestCommand ), fmt .Errorf ("failed from test" ))
82
84
d .On ("Body" ).Return (body )
83
- d .On ("Nack" , true , true ).Return (nil )
85
+ d .On ("Nack" , true ).Return (nil )
86
+ d .On ("Properties" ).Return (p )
87
+ d .On ("Info" ).Return (di )
84
88
85
- c .ProcessMessage (d , p , di )
89
+ c .ProcessMessage (d )
86
90
87
91
assert .Equal (t , "ERROR failed to create command: failed from test\n " , l .Buf ().String ())
88
92
d .AssertExpectations (t )
@@ -98,8 +102,8 @@ func TestStrictDefault(t *testing.T) {
98
102
99
103
d := new (TestDelivery )
100
104
b := new (TestBuilder )
101
- p := metadata .Properties {}
102
- di := metadata. DeliveryInfo {}
105
+ p := delivery .Properties {}
106
+ di := delivery. Info {}
103
107
cmd := new (TestCommand )
104
108
body := []byte ("strictDefault" )
105
109
c := consumer.Consumer {
@@ -110,11 +114,13 @@ func TestStrictDefault(t *testing.T) {
110
114
111
115
b .On ("GetCommand" , p , di , body ).Return (cmd , nil )
112
116
d .On ("Body" ).Return (body )
113
- d .On ("Nack" , true , true ).Return (nil )
117
+ d .On ("Nack" , true ).Return (nil )
118
+ d .On ("Properties" ).Return (p )
119
+ d .On ("Info" ).Return (di )
114
120
cmd .On ("Run" ).Return (1 )
115
121
116
122
assert .PanicsWithValue (t , "os.Exit called with: 11" , func () {
117
- c .ProcessMessage (d , p , di )
123
+ c .ProcessMessage (d )
118
124
}, "os.Exit was not called" )
119
125
120
126
d .AssertExpectations (t )
@@ -143,7 +149,7 @@ func (b *TestBuilder) SetCommand(cmd string) {
143
149
b .Called (cmd )
144
150
}
145
151
146
- func (b * TestBuilder ) GetCommand (p metadata .Properties , d metadata. DeliveryInfo , body []byte ) (command.Command , error ) {
152
+ func (b * TestBuilder ) GetCommand (p delivery .Properties , d delivery. Info , body []byte ) (command.Command , error ) {
147
153
argsT := b .Called (p , d , body )
148
154
149
155
return argsT .Get (0 ).(command.Command ), argsT .Error (1 )
@@ -161,3 +167,43 @@ func (t TestCommand) Run() int {
161
167
func (t TestCommand ) Cmd () * exec.Cmd {
162
168
return t .Called ().Get (0 ).(* exec.Cmd )
163
169
}
170
+
171
+ type TestDelivery struct {
172
+ mock.Mock
173
+ }
174
+
175
+ func (t * TestDelivery ) Ack () error {
176
+ argstT := t .Called ()
177
+
178
+ return argstT .Error (0 )
179
+ }
180
+
181
+ func (t * TestDelivery ) Nack (requeue bool ) error {
182
+ argsT := t .Called (requeue )
183
+
184
+ return argsT .Error (0 )
185
+ }
186
+
187
+ func (t * TestDelivery ) Reject (requeue bool ) error {
188
+ argsT := t .Called (requeue )
189
+
190
+ return argsT .Error (0 )
191
+ }
192
+
193
+ func (t * TestDelivery ) Body () []byte {
194
+ argsT := t .Called ()
195
+
196
+ return argsT .Get (0 ).([]byte )
197
+ }
198
+
199
+ func (t * TestDelivery ) Properties () delivery.Properties {
200
+ argsT := t .Called ()
201
+
202
+ return argsT .Get (0 ).(delivery.Properties )
203
+ }
204
+
205
+ func (t * TestDelivery ) Info () delivery.Info {
206
+ argsT := t .Called ()
207
+
208
+ return argsT .Get (0 ).(delivery.Info )
209
+ }
0 commit comments