-
-
Notifications
You must be signed in to change notification settings - Fork 433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added example for RabbitMQ #1031
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,56 @@ | ||
name: RabbitMQ example pipeline | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- 'mkdocs.yml' | ||
- 'docs/**' | ||
- 'README.md' | ||
pull_request: | ||
paths-ignore: | ||
- 'mkdocs.yml' | ||
- 'docs/**' | ||
- 'README.md' | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test-rabbitmq: | ||
strategy: | ||
matrix: | ||
go-version: [1.19.x, 1.x] | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v3 | ||
|
||
- name: modVerify | ||
working-directory: ./examples/rabbitmq | ||
run: go mod verify | ||
|
||
- name: modTidy | ||
working-directory: ./examples/rabbitmq | ||
run: make tools-tidy | ||
|
||
- name: gotestsum | ||
working-directory: ./examples/rabbitmq | ||
run: make test-unit | ||
|
||
- name: Run checker | ||
run: | | ||
./scripts/check_environment.sh | ||
|
||
- name: Test Summary | ||
uses: test-summary/action@4ee9ece4bca777a38f05c8fc578ac2007fe266f7 | ||
with: | ||
paths: "**/TEST-rabbitmq*.xml" | ||
if: always() |
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,9 @@ | ||
# RabbitMQ | ||
|
||
<!--codeinclude--> | ||
[Creating a RabbitMQ container](../../examples/rabbitmq/rabbitmq.go) | ||
<!--/codeinclude--> | ||
|
||
<!--codeinclude--> | ||
[Test for a RabbitMQ container](../../examples/rabbitmq/rabbitmq_test.go) | ||
<!--/codeinclude--> |
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,5 @@ | ||
include ../../commons-test.mk | ||
|
||
.PHONY: test | ||
test: | ||
$(MAKE) test-rabbitmq |
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,50 @@ | ||
module github.com/testcontainers/testcontainers-go/examples/rabbitmq | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/rabbitmq/amqp091-go v1.8.0 | ||
github.com/testcontainers/testcontainers-go v0.19.0 | ||
gotest.tools/gotestsum v1.9.0 | ||
) | ||
|
||
require ( | ||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect | ||
github.com/Microsoft/go-winio v0.5.2 // indirect | ||
github.com/cenkalti/backoff/v4 v4.2.0 // indirect | ||
github.com/containerd/containerd v1.6.19 // indirect | ||
github.com/cpuguy83/dockercfg v0.3.1 // indirect | ||
github.com/dnephin/pflag v1.0.7 // indirect | ||
github.com/docker/distribution v2.8.1+incompatible // indirect | ||
github.com/docker/docker v23.0.1+incompatible // indirect | ||
github.com/docker/go-connections v0.4.0 // indirect | ||
github.com/docker/go-units v0.5.0 // indirect | ||
github.com/fatih/color v1.13.0 // indirect | ||
github.com/fsnotify/fsnotify v1.5.4 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/klauspost/compress v1.11.13 // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/mattn/go-colorable v0.1.12 // indirect | ||
github.com/mattn/go-isatty v0.0.16 // indirect | ||
github.com/moby/patternmatcher v0.5.0 // indirect | ||
github.com/moby/sys/sequential v0.5.0 // indirect | ||
github.com/moby/term v0.0.0-20221128092401-c43b287e0e0f // indirect | ||
github.com/morikuni/aec v1.0.0 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect | ||
github.com/opencontainers/runc v1.1.3 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/sirupsen/logrus v1.9.0 // indirect | ||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect | ||
golang.org/x/net v0.7.0 // indirect | ||
golang.org/x/sync v0.1.0 // indirect | ||
golang.org/x/sys v0.6.0 // indirect | ||
golang.org/x/term v0.5.0 // indirect | ||
golang.org/x/tools v0.1.12 // indirect | ||
google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad // indirect | ||
google.golang.org/grpc v1.47.0 // indirect | ||
google.golang.org/protobuf v1.28.0 // indirect | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
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,46 @@ | ||
package rabbitmq | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/testcontainers/testcontainers-go" | ||
"github.com/testcontainers/testcontainers-go/wait" | ||
) | ||
|
||
// rabbitmqContainer represents the mongodb container type used in the module | ||
type rabbitmqContainer struct { | ||
testcontainers.Container | ||
endpoint string | ||
} | ||
|
||
func startContainer(ctx context.Context) (*rabbitmqContainer, error) { | ||
req := testcontainers.ContainerRequest{ | ||
Image: "rabbitmq:3", | ||
ExposedPorts: []string{"5672/tcp"}, | ||
WaitingFor: wait.ForLog("started TCP listener on [::]:5672"), | ||
} | ||
|
||
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ | ||
ContainerRequest: req, | ||
Started: true, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
host, err := container.Host(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
mappedPort, err := container.MappedPort(ctx, "5672") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &rabbitmqContainer{ | ||
Container: container, | ||
endpoint: fmt.Sprintf("%s:%s", host, mappedPort.Port()), | ||
}, nil | ||
} |
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,38 @@ | ||
package rabbitmq | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
amqp "github.com/rabbitmq/amqp091-go" | ||
) | ||
|
||
func TestRabbitMQ(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
container, err := startContainer(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Clean up the container after the test is complete | ||
t.Cleanup(func() { | ||
if err := container.Terminate(ctx); err != nil { | ||
t.Fatalf("failed to terminate container: %s", err) | ||
} | ||
}) | ||
|
||
// perform assertions | ||
|
||
amqpConnection, err := amqp.Dial(fmt.Sprintf("amqp://guest:guest@%s", container.endpoint)) | ||
|
||
if err != nil { | ||
t.Fatal(fmt.Errorf("error creating amqp client: %w", err)) | ||
} | ||
|
||
err = amqpConnection.Close() | ||
if err != nil { | ||
t.Fatal(fmt.Errorf("error closing amqp connection: %s", err)) | ||
} | ||
} |
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,11 @@ | ||
//go:build tools | ||
// +build tools | ||
|
||
// This package contains the tool dependencies of the project. | ||
|
||
package tools | ||
|
||
import ( | ||
// Register gotestsum for pinning version | ||
_ "gotest.tools/gotestsum" | ||
) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's great having the amqp connection here. Could you extend the example on how to put/get values on/from the queue? 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
I'm just wondering what's the best way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not an expert in RabbitMQ, so I'd suggest adding the most educational example on how to do it.