-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added integration tests for queue service
- Loading branch information
1 parent
42f8eb9
commit 3d62d6c
Showing
4 changed files
with
138 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: "3.8" | ||
|
||
services: | ||
rabbitmq: | ||
image: rabbitmq:3-management | ||
hostname: rabbitmq | ||
environment: | ||
RABBITMQ_DEFAULT_USER: test | ||
RABBITMQ_DEFAULT_PASS: test | ||
ports: | ||
- "5672:5672" | ||
- "15672:15672" | ||
|
||
go-process-engine: | ||
container_name: process-engine | ||
image: process-engine:latest | ||
build: | ||
context: . | ||
dockerfile: ./docker/Dockerfile.test | ||
depends_on: | ||
- rabbitmq | ||
command: ["go", "test", "-v", "./services/queue_integration_test.go"] |
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
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,101 @@ | ||
package services | ||
|
||
import ( | ||
"testing" | ||
"github.com/stretchr/testify/suite" | ||
"github.com/streadway/amqp" | ||
) | ||
|
||
type RabbitMQSuite struct { | ||
suite.Suite | ||
Connection *amqp.Connection | ||
Channel *amqp.Channel | ||
QueueName string | ||
ExchangeName string | ||
RoutingKey string | ||
} | ||
|
||
func (suite *RabbitMQSuite) SetupSuite() { | ||
// Setup code for the entire suite here | ||
suite.QueueName = "test_queue" | ||
suite.ExchangeName = "test_exchange" | ||
suite.RoutingKey = "test.key" | ||
|
||
conn, err := amqp.Dial("amqp://test:test@rabbitmq:5672/") | ||
suite.NoError(err) | ||
suite.Connection = conn | ||
|
||
ch, err := conn.Channel() | ||
suite.NoError(err) | ||
suite.Channel = ch | ||
} | ||
|
||
func (suite *RabbitMQSuite) SetupTest() { | ||
// Setup code before each test here | ||
err := suite.Channel.ExchangeDeclare( | ||
suite.ExchangeName, | ||
"direct", | ||
true, | ||
false, | ||
false, | ||
false, | ||
nil, | ||
) | ||
suite.NoError(err) | ||
|
||
_, err = suite.Channel.QueueDeclare( | ||
suite.QueueName, | ||
true, | ||
false, | ||
false, | ||
false, | ||
nil, | ||
) | ||
suite.NoError(err) | ||
|
||
err = suite.Channel.QueueBind( | ||
suite.QueueName, | ||
suite.RoutingKey, | ||
suite.ExchangeName, | ||
false, | ||
nil, | ||
) | ||
suite.NoError(err) | ||
} | ||
|
||
func (suite *RabbitMQSuite) TearDownTest() { | ||
// Teardown code after each test here | ||
err := suite.Channel.QueueUnbind( | ||
suite.QueueName, | ||
suite.RoutingKey, | ||
suite.ExchangeName, | ||
nil, | ||
) | ||
suite.NoError(err) | ||
|
||
_, err = suite.Channel.QueueDelete(suite.QueueName, false, false, false) | ||
suite.NoError(err) | ||
|
||
err = suite.Channel.ExchangeDelete(suite.ExchangeName, false, false) | ||
suite.NoError(err) | ||
} | ||
|
||
func (suite *RabbitMQSuite) TearDownSuite() { | ||
// Teardown code for the entire suite here | ||
err := suite.Channel.Close() | ||
suite.NoError(err) | ||
|
||
err = suite.Connection.Close() | ||
suite.NoError(err) | ||
} | ||
|
||
func TestRabbitMQSuite(t *testing.T) { | ||
suite.Run(t, new(RabbitMQSuite)) | ||
} | ||
|
||
// Example of a test function | ||
func (suite *RabbitMQSuite) TestExample() { | ||
// Your test code here | ||
// Use suite.Channel to interact with RabbitMQ | ||
suite.True(true) // Dummy assertion | ||
} |