-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(MAGNETO-7807): Fixed rabbitmq sonar issues (#86)
* fix(MAGNETO-7807): Fixed rabbitmq sonar issues * fix(MAGNETO-7807): Session init fix * fix(MAGNETO-7807): Remeved wrong struct field * fix(MAGNETO-7807): Removed wrong empty line * fix(MAGNETO-7807): Fixed code smells
- Loading branch information
1 parent
261eed8
commit 8323b6b
Showing
7 changed files
with
869 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2021 Telefonica Cybersecurity & Cloud Tech SL | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package rabbit | ||
|
||
import ( | ||
"github.com/streadway/amqp" | ||
) | ||
|
||
type AMQPServiceFunctions interface { | ||
Dial(url string) (*amqp.Connection, error) | ||
ConnectionChannel(c *amqp.Connection) (*amqp.Channel, error) | ||
ChannelExchangeDeclare(channel *amqp.Channel, name string) error | ||
ChannelQueueDeclare(channel *amqp.Channel) (amqp.Queue, error) | ||
ChannelQueueBind(channel *amqp.Channel, name, exchange string) error | ||
ChannelConsume(channel *amqp.Channel, queue string, | ||
) (<-chan amqp.Delivery, error) | ||
ChannelClose(channel *amqp.Channel) error | ||
ChannelPublish(channel *amqp.Channel, | ||
exchange string, | ||
msg amqp.Publishing, | ||
) error | ||
} | ||
|
||
type AMQPService struct{} | ||
|
||
func NewAMQPService() *AMQPService { | ||
return &AMQPService{} | ||
} | ||
|
||
func (a AMQPService) Dial(url string) (*amqp.Connection, error) { | ||
return amqp.Dial(url) | ||
} | ||
|
||
func (a AMQPService) ConnectionChannel(connection *amqp.Connection) (*amqp.Channel, error) { | ||
return connection.Channel() | ||
} | ||
func (a AMQPService) ChannelExchangeDeclare(channel *amqp.Channel, name string) error { | ||
return channel.ExchangeDeclare(name, "fanout", true, false, false, false, nil) | ||
} | ||
|
||
func (a AMQPService) ChannelQueueDeclare(channel *amqp.Channel) (amqp.Queue, error) { | ||
return channel.QueueDeclare("", false, true, true, false, nil) | ||
} | ||
func (a AMQPService) ChannelQueueBind(channel *amqp.Channel, name, exchange string) error { | ||
return channel.QueueBind(name, "", exchange, false, nil) | ||
} | ||
|
||
func (a AMQPService) ChannelConsume(channel *amqp.Channel, queue string, | ||
) (<-chan amqp.Delivery, error) { | ||
return channel.Consume(queue, "", true, false, false, false, nil) | ||
} | ||
|
||
func (a AMQPService) ChannelClose(channel *amqp.Channel) error { | ||
return channel.Close() | ||
} | ||
|
||
func (a AMQPService) ChannelPublish(channel *amqp.Channel, | ||
exchange string, | ||
msg amqp.Publishing, | ||
) error { | ||
return channel.Publish(exchange, "", false, false, msg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2021 Telefonica Cybersecurity & Cloud Tech SL | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package rabbit | ||
|
||
import ( | ||
"github.com/streadway/amqp" | ||
) | ||
|
||
var ( | ||
DialError error | ||
ConnectionChannelError error | ||
ChannelExchangeDeclareError error | ||
ChannelQueueDeclareError error | ||
ChannelQueueBindError error | ||
ChannelConsumeError error | ||
MockSubCh <-chan amqp.Delivery | ||
ChannelPublishError error | ||
) | ||
|
||
type AMQPServiceFuncMock struct{} | ||
|
||
func (a AMQPServiceFuncMock) Dial(url string) (*amqp.Connection, error) { | ||
return nil, DialError | ||
} | ||
|
||
func (a AMQPServiceFuncMock) ConnectionChannel(c *amqp.Connection) (*amqp.Channel, error) { | ||
return nil, ConnectionChannelError | ||
} | ||
|
||
func (a AMQPServiceFuncMock) ChannelExchangeDeclare(channel *amqp.Channel, name string) error { | ||
return ChannelExchangeDeclareError | ||
} | ||
|
||
func (a AMQPServiceFuncMock) ChannelQueueDeclare(channel *amqp.Channel) (amqp.Queue, error) { | ||
amqpQueue := amqp.Queue{} | ||
return amqpQueue, ChannelQueueDeclareError | ||
} | ||
|
||
func (a AMQPServiceFuncMock) ChannelQueueBind(channel *amqp.Channel, name, exchange string) error { | ||
return ChannelQueueBindError | ||
} | ||
|
||
func (a AMQPServiceFuncMock) ChannelConsume(channel *amqp.Channel, queue string, | ||
) (<-chan amqp.Delivery, error) { | ||
return MockSubCh, ChannelConsumeError | ||
} | ||
func (a AMQPServiceFuncMock) ChannelClose(channel *amqp.Channel) error { | ||
return nil | ||
} | ||
|
||
func (a AMQPServiceFuncMock) ChannelPublish(channel *amqp.Channel, | ||
exchange string, | ||
msg amqp.Publishing, | ||
) error { | ||
return ChannelPublishError | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.