Skip to content

Commit

Permalink
feat: added integration tests for queue service
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielojh committed Nov 9, 2023
1 parent 42f8eb9 commit 3d62d6c
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docker-compose-test.yml
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"]
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/joho/godotenv v1.5.1
github.com/rabbitmq/amqp091-go v1.9.0
github.com/stretchr/testify v1.8.0
go.mongodb.org/mongo-driver v1.12.1
google.golang.org/genproto v0.0.0-20230526161137-0005af68ea54
)

require (
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/golang/snappy v0.0.1 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/mitchellh/mapstructure v1.5.0
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/streadway/amqp v1.1.0
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rabbitmq/amqp091-go v1.9.0 h1:qrQtyzB4H8BQgEuJwhmVQqVHB9O4+MNDJCCAcpc3Aoo=
github.com/rabbitmq/amqp091-go v1.9.0/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
github.com/streadway/amqp v1.1.0 h1:py12iX8XSyI7aN/3dUT8DFIDJazNJsVJdxNVEpnQTZM=
github.com/streadway/amqp v1.1.0/go.mod h1:WYSrTEYHOXHd0nwFeUXAe2G2hRnQT+deZJJf88uS9Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
Expand Down Expand Up @@ -79,6 +85,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
101 changes: 101 additions & 0 deletions services/queue_integration_test.go
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
}

0 comments on commit 3d62d6c

Please sign in to comment.