-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannel.go
42 lines (34 loc) · 1.35 KB
/
channel.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
package messenger_amqp
import (
"github.com/streadway/amqp"
"github.com/stretchr/testify/mock"
)
type Channel interface {
Publish(exchange, key string, mandatory, immediate bool, msg amqp.Publishing) error
Consume(queue, consumer string, autoAck, exclusive, noLocal, noWait bool, args amqp.Table) (<-chan amqp.Delivery, error)
Cancel(consumer string, noWait bool) error
Ack(tag uint64, multiple bool) error
Nack(tag uint64, multiple bool, requeue bool) error
}
type mockChannel struct {
mock.Mock
}
func (m *mockChannel) Publish(exchange, key string, mandatory, immediate bool, msg amqp.Publishing) error {
return m.Called(exchange, key, mandatory, immediate, msg).Error(0)
}
func (m *mockChannel) Consume(queue, consumer string, autoAck, exclusive, noLocal, noWait bool, args amqp.Table) (<-chan amqp.Delivery, error) {
called := m.Called(queue, consumer, autoAck, exclusive, noLocal, noWait, args)
if ch, ok := called.Get(0).(chan amqp.Delivery); ok {
return ch, called.Error(1)
}
return nil, called.Error(1)
}
func (m *mockChannel) Cancel(consumer string, noWait bool) error {
return m.Called(consumer, noWait).Error(0)
}
func (m *mockChannel) Ack(tag uint64, multiple bool) error {
return m.Called(tag, multiple).Error(0)
}
func (m *mockChannel) Nack(tag uint64, multiple bool, requeue bool) error {
return m.Called(tag, multiple, requeue).Error(0)
}