1
0
mirror of https://github.com/eventials/goevents.git synced 2025-04-24 13:48:53 +08:00

Fix mock object.

This commit is contained in:
Alexandre Vicenzi 2017-10-05 14:55:13 -03:00
parent e04eaa632d
commit 3e5e24f212
3 changed files with 45 additions and 15 deletions

View File

@ -9,16 +9,34 @@ type Connection struct {
mock.Mock
}
func (c *Connection) Consumer(autoAck bool) (messaging.Consumer, error) {
args := c.Called(autoAck)
func NewMockConnection() messaging.Connection {
return &Connection{}
}
func (c *Connection) Consumer(autoAck bool, exchange, queue string) (messaging.Consumer, error) {
args := c.Called(autoAck, exchange, queue)
return args.Get(0).(messaging.Consumer), args.Error(1)
}
func (c *Connection) Producer() (messaging.Producer, error) {
args := c.Called()
return args.Get(0).(*Producer), args.Error(1)
func (c *Connection) Producer(exchange string) (messaging.Producer, error) {
args := c.Called(exchange)
return args.Get(0).(messaging.Producer), args.Error(1)
}
func (c *Connection) Close() {
c.Called()
}
func (c *Connection) NotifyConnectionClose() <-chan error {
args := c.Called()
return args.Get(0).(chan error)
}
func (c *Connection) NotifyReestablish() <-chan bool {
args := c.Called()
return args.Get(0).(chan bool)
}
func (c *Connection) WaitUntilConnectionCloses() {
c.Called()
}

View File

@ -9,22 +9,29 @@ type Consumer struct {
mock.Mock
}
func NewMockConsumer() messaging.Consumer {
return &Consumer{}
}
func (c *Consumer) Subscribe(action string, handler messaging.EventHandler) error {
args := c.Called(action, handler)
return args.Error(1)
return args.Error(0)
}
func (c *Consumer) SubscribeWithOptions(options messaging.SubscribeOptions) error {
args := c.Called(options)
return args.Error(0)
}
func (c *Consumer) Unsubscribe(action string) error {
args := c.Called(action)
return args.Error(1)
return args.Error(0)
}
func (c *Consumer) Listen() error {
args := c.Called()
return args.Error(1)
func (c *Consumer) Consume() {
c.Called()
}
func (c *Consumer) ListenForever() error {
args := c.Called()
return args.Error(1)
func (c *Consumer) Close() {
c.Called()
}

View File

@ -1,6 +1,7 @@
package mock
import (
"github.com/eventials/goevents/messaging"
"github.com/stretchr/testify/mock"
)
@ -8,6 +9,10 @@ type Producer struct {
mock.Mock
}
func NewMockProducer() messaging.Producer {
return &Producer{}
}
func (p *Producer) Publish(action string, data []byte) {
p.Called(action, data)
}
@ -17,6 +22,6 @@ func (p *Producer) Close() {
}
func (p *Producer) NotifyClose() <-chan bool {
p.Called()
return make(chan bool)
args := p.Called()
return args.Get(0).(chan bool)
}