From 8c159b4a96a2afbf8765097ff1d19cecd03144ea Mon Sep 17 00:00:00 2001 From: Gabriel Freites Date: Mon, 31 Jul 2023 19:29:09 +0200 Subject: [PATCH] improving coverage --- pkg/rabbit/connections_handler_test.go | 16 ++++++++++++++++ pkg/rabbit/rabbit_mocks.go | 7 +------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/rabbit/connections_handler_test.go b/pkg/rabbit/connections_handler_test.go index a7bea2edfa..b1aec3a535 100644 --- a/pkg/rabbit/connections_handler_test.go +++ b/pkg/rabbit/connections_handler_test.go @@ -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) diff --git a/pkg/rabbit/rabbit_mocks.go b/pkg/rabbit/rabbit_mocks.go index 333d059567..0fec70d139 100644 --- a/pkg/rabbit/rabbit_mocks.go +++ b/pkg/rabbit/rabbit_mocks.go @@ -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 { @@ -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 {