Skip to content

Commit

Permalink
improving coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gabo1208 committed Jul 31, 2023
1 parent 8e2b28a commit 107f3c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
16 changes: 16 additions & 0 deletions pkg/rabbit/connections_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ func Test_InvalidSetupRabbitMQ(t *testing.T) {

rabbitMQHelper.Connection, _ = rabbitMQHelper.createConnection("amqp://localhost:5672/%2f", ValidDial)
rabbitMQHelper.Channel, _ = rabbitMQHelper.createChannel()
if rabbitMQHelper.Connection.IsClosed() {
t.Errorf("unexpected closed connection error")
}

if _, err := rabbitMQHelper.Channel.QueueInspect("test"); err != nil {
t.Errorf("unexpected queue inspect error")
}

if _, err := rabbitMQHelper.Channel.Consume("test", "test", true, true, true, true, amqp091.Table{}); err != nil {
t.Errorf("unexpected channel consume error")
}

if _, err := rabbitMQHelper.Channel.PublishWithDeferredConfirm("test", "test", true, true, amqp091.Publishing{}); err != nil {
t.Errorf("unexpected channel publish with deferred confirm error")
}

err = rabbitMQHelper.configConnectionAndChannel(InvalidConfigTest)
if err == nil || rabbitMQHelper.GetConnection() == nil || rabbitMQHelper.GetChannel() == nil {
t.Errorf("unexpected error == nil when setting up invalid config %s %s %s", rabbitMQHelper.GetConnection(), rabbitMQHelper.GetChannel(), err)
Expand Down
7 changes: 1 addition & 6 deletions pkg/rabbit/rabbit_mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,9 @@ func (rm *RabbitMQBadConnectionMock) Close() error {
return nil
}

func (rm *RabbitMQBadConnectionMock) NotifyClose(c chan *amqp.Error) chan *amqp.Error {
return c
}

type RabbitMQChannelMock struct {
NotifyCloseChannel chan *amqp.Error
ConsumeChannel <-chan amqp.Delivery
dc *amqp.DeferredConfirmation
}

func (rm *RabbitMQChannelMock) IsClosed() bool {
Expand All @@ -84,7 +79,7 @@ func (rm *RabbitMQChannelMock) Consume(a string, b string, c bool, d bool, e boo
}

func (rm *RabbitMQChannelMock) PublishWithDeferredConfirm(a string, b string, c bool, d bool, p amqp.Publishing) (*amqp.DeferredConfirmation, error) {
return rm.dc, nil
return &amqp.DeferredConfirmation{}, nil
}

func (rm *RabbitMQChannelMock) Confirm(a bool) error {
Expand Down

0 comments on commit 107f3c3

Please sign in to comment.