-
-
Notifications
You must be signed in to change notification settings - Fork 588
feat(azure)!: add Azurite, EventHubs and ServiceBus in the new Azure module, deprecating the old Azurite module #3008
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
Merged
Merged
Changes from 43 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
2e46706
feat: move Azurite container to the new Azure module, deprecating the…
mdelapenya f81fb5d
feat: add eventhubs module
mdelapenya 3a5354c
fix: right import
mdelapenya 733963d
chore: use tabs for Azurite code examples
mdelapenya 69d080b
fix: azure has no go files
mdelapenya 25da330
chore: rename
mdelapenya 056d519
feat: add a way to share the MSSQL Server password in the container
mdelapenya 41a3225
feat: add servicebus emulator module
mdelapenya de0bcdc
chore: add wait strategy for the eventhubs container
mdelapenya de62a49
chore: add more robust wait strategies for the azurite container
mdelapenya 87b6843
chore: add more tests for the azurite module
mdelapenya 5b2c75a
chore: run mod tidy
mdelapenya 74ab1a5
fix: use the new azurite imports
mdelapenya 0379d78
fix: lint
mdelapenya 80480d4
chore: remove unused import
mdelapenya 71ea08b
chore: pin mssql version
mdelapenya 05ccaad
fix: mod tidy
mdelapenya fbf78a0
wip: cosmosdb container
mdelapenya 25db8c1
Merge branch 'main' into azure-modules
mdelapenya fc1e31c
Revert "wip: cosmosdb container"
mdelapenya 5a26e07
chore: retry in example tests
mdelapenya 0b45138
chore: docs and wrap errors
mdelapenya 192f58e
docs: add method docs for MSSQL
mdelapenya b07a621
chore: refine ServiceBus wait strategies
mdelapenya fcd6383
chore: customiser MSSQL Server
mdelapenya 3f4ebc7
chore: customise Azurite container
mdelapenya af6a40f
Merge branch 'main' into azure-modules
mdelapenya 751b652
fix: add azure to dependabot
mdelapenya 7195326
chore: refine EventHubs wait strategies
mdelapenya 4f1ede5
chore: handle EULA variable correctly
mdelapenya 75a15d0
docs: proper comments
mdelapenya 98ad9b3
chore!: remove settings, as it not used
mdelapenya 9a4fde1
fixup comments
mdelapenya 4529186
chore: options returns error
mdelapenya 03e5d4d
chore: do not leak network
mdelapenya e64edb7
chore: simplify wait strategies
mdelapenya 6e5f9bf
fix: wait for all does not handle nil waits
mdelapenya 96c60a6
chore!: remove Must methods from the azure containers
mdelapenya 8933b6e
fix: wait for http code 200 OK
mdelapenya 3bc4568
fix: wait for the default port in the MSSQL Server module
mdelapenya 8d8a92a
Merge branch 'main' into azure-modules
mdelapenya 1537421
fix: mod tidy azurite
mdelapenya 916a6d9
Merge branch 'main' into azure-modules
mdelapenya b92fb28
chore: rename container type for Azurite
mdelapenya 9c4ec5a
chore: save variable
mdelapenya d0f0a31
chore: do not expose services
mdelapenya f23f143
chore: exclude azurite deprecations from lint
mdelapenya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,292 @@ | ||
| # Azure | ||
|
|
||
| Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| ## Introduction | ||
|
|
||
| The Testcontainers module for Azure. | ||
|
|
||
| ## Adding this module to your project dependencies | ||
|
|
||
| Please run the following command to add the Azure module to your Go dependencies: | ||
|
|
||
| ``` | ||
| go get github.com/testcontainers/testcontainers-go/modules/azure | ||
| ``` | ||
|
|
||
| ## Usage example | ||
|
|
||
| The Azure module exposes the following Go packages: | ||
|
|
||
| - [Azurite](#azurite): `github.com/testcontainers/testcontainers-go/modules/azure/azurite`. | ||
| - [EventHubs](#eventhubs): `github.com/testcontainers/testcontainers-go/modules/azure/eventhubs`. | ||
| - [ServiceBus](#servicebus): `github.com/testcontainers/testcontainers-go/modules/azure/servicebus`. | ||
| !!! warning "EULA Acceptance" | ||
| Due to licensing restrictions you are required to explicitly accept an End User License Agreement (EULA) for the EventHubs container image. This is facilitated through the `WithAcceptEULA` function. | ||
|
|
||
| <!--codeinclude--> | ||
| [Creating a Azurite container](../../modules/azure/azurite/examples_test.go) inside_block:runAzuriteContainer | ||
| <!--/codeinclude--> | ||
|
|
||
| ## Azurite | ||
|
|
||
| ### Run function | ||
|
|
||
| - Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| The Azurite module exposes one entrypoint function to create the Azurite container, and this function receives three parameters: | ||
|
|
||
| ```golang | ||
| func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*AzuriteContainer, error) | ||
| ``` | ||
|
|
||
| - `context.Context`, the Go context. | ||
| - `string`, the Docker image to use. | ||
| - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. | ||
|
|
||
| ### Default Credentials | ||
|
|
||
| The Azurite container uses the following default credentials: | ||
|
|
||
| <!--codeinclude--> | ||
| [Default Credentials](../../modules/azure/azurite/azurite.go) inside_block:defaultCredentials | ||
| <!--/codeinclude--> | ||
|
|
||
| ### Container Options | ||
|
|
||
| When starting the Azurite container, you can pass options in a variadic way to configure it. | ||
|
|
||
| #### Image | ||
|
|
||
| Use the second argument in the `Run` function to set a valid Docker image. | ||
| In example: `Run(context.Background(), "mcr.microsoft.com/azure-storage/azurite:3.28.0")`. | ||
|
|
||
| {% include "../features/common_functional_options.md" %} | ||
|
|
||
| #### WithInMemoryPersistence | ||
|
|
||
| - Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| If you want to use in-memory persistence, you can use `WithInMemoryPersistence(megabytes float64)`. E.g. `azurite.WithInMemoryPersistence(64.0)`. | ||
|
|
||
| Please read the [Azurite documentation](https://github.com/Azure/Azurite?tab=readme-ov-file#use-in-memory-storage) for more information. | ||
|
|
||
| !!! warning | ||
| This option is only available in Azurite versions 3.28.0 and later. | ||
|
|
||
| ### Container Methods | ||
|
|
||
| The Azurite container exposes the following methods: | ||
|
|
||
| #### ServiceURL | ||
|
|
||
| - Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| Returns the service URL to connect to the Azurite container and an error, passing the Go context and the service name as parameters. | ||
|
|
||
| ### Examples | ||
|
|
||
| #### Blob Operations | ||
|
|
||
| In the following example, we will create a container with Azurite and perform some blob operations. For that, using the default | ||
| credentials, we will create an Azurite container, upload a blob to it, list the blobs, and download the blob. Finally, we will remove the created blob and container. | ||
|
|
||
| <!--codeinclude--> | ||
| [Create Container](../../modules/azure/azurite/examples_test.go) inside_block:runForBlobOperations | ||
| [Create Shared Key Credential](../../modules/azure/azurite/examples_test.go) inside_block:createSharedKeyCredential | ||
| [Create Client](../../modules/azure/azurite/examples_test.go) inside_block:createClient | ||
| [Create Container](../../modules/azure/azurite/examples_test.go) inside_block:createContainer | ||
| [Upload and Download Blob](../../modules/azure/azurite/examples_test.go) inside_block:uploadDownloadBlob | ||
| [List Blobs](../../modules/azure/azurite/examples_test.go) inside_block:listBlobs | ||
| [Delete Blob](../../modules/azure/azurite/examples_test.go) inside_block:deleteBlob | ||
| [Delete Container](../../modules/azure/azurite/examples_test.go) inside_block:deleteContainer | ||
| <!--/codeinclude--> | ||
|
|
||
| #### Queue Operations | ||
|
|
||
| In the following example, we will create an Azurite container and perform some queue operations. For that, using the default | ||
| credentials, we will create a queue, list the queues, and finally we will remove the created queue. | ||
|
|
||
| <!--codeinclude--> | ||
| [Run Azurite Container](../../modules/azure/azurite/examples_test.go) inside_block:runForQueueOperations | ||
| [Create Shared Key Credential](../../modules/azure/azurite/examples_test.go) inside_block:queueOperations_createSharedKeyCredential | ||
| [Create Client](../../modules/azure/azurite/examples_test.go) inside_block:queueOperations_createClient | ||
| [Create Queue](../../modules/azure/azurite/examples_test.go) inside_block:createQueue | ||
| [List Queues](../../modules/azure/azurite/examples_test.go) inside_block:listQueues | ||
| [Delete Queue](../../modules/azure/azurite/examples_test.go) inside_block:deleteQueue | ||
| <!--/codeinclude--> | ||
|
|
||
| #### Table Operations | ||
|
|
||
| In the following example, we will create an Azurite container and perform some table operations. For that, using the default | ||
| credentials, we will create a table, list the tables, and finally we will remove the created table. | ||
|
|
||
| <!--codeinclude--> | ||
| [Run Azurite Container](../../modules/azure/azurite/examples_test.go) inside_block:runForTableOperations | ||
| [Create Shared Key Credential](../../modules/azure/azurite/examples_test.go) inside_block:tableOperations_createSharedKeyCredential | ||
| [Create Client](../../modules/azure/azurite/examples_test.go) inside_block:tableOperations_createClient | ||
| [Create Table](../../modules/azure/azurite/examples_test.go) inside_block:createTable | ||
| [List Tables](../../modules/azure/azurite/examples_test.go) inside_block:listTables | ||
| [Delete Table](../../modules/azure/azurite/examples_test.go) inside_block:deleteTable | ||
| <!--/codeinclude--> | ||
|
|
||
| ## EventHubs | ||
|
|
||
| ### Run function | ||
|
|
||
| - Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| The EventHubs module exposes one entrypoint function to create the EventHubs container, and this function receives three parameters: | ||
|
|
||
| ```golang | ||
| func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) | ||
| ``` | ||
|
|
||
| - `context.Context`, the Go context. | ||
| - `string`, the Docker image to use. | ||
| - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. | ||
|
|
||
| The EventHubs container needs an Azurite container to be running, for that reason _Testcontainers for Go_ **automatically creates a Docker network and an Azurite container** for EventHubs to work. | ||
| When terminating the EventHubs container, the Azurite container and the Docker network are also terminated. | ||
|
|
||
| ### Container Options | ||
|
|
||
| When starting the EventHubs container, you can pass options in a variadic way to configure it. | ||
|
|
||
| #### Image | ||
|
|
||
| Use the second argument in the `Run` function to set a valid Docker image. | ||
| In example: `Run(context.Background(), "mcr.microsoft.com/azure-messaging/eventhubs-emulator:2.0.1")`. | ||
|
|
||
| {% include "../features/common_functional_options.md" %} | ||
|
|
||
| #### WithAzurite | ||
|
|
||
| - Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This option allows you to set a different Azurite Docker image, instead of the default one, and also pass options to the Azurite container, in the form of a variadic argument of `testcontainers.ContainerCustomizer`. | ||
|
|
||
| #### WithAcceptEULA | ||
|
|
||
| - Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This option allows you to accept the EULA for the EventHubs container. | ||
|
|
||
| #### WithConfig | ||
|
|
||
| - Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This option allows you to set a custom EventHubs config file for the EventHubs container. | ||
|
|
||
| The config file must be a valid EventHubs config file, and it must be a valid JSON object. | ||
|
|
||
| <!--codeinclude--> | ||
| [EventHubs JSON Config](../../modules/azure/eventhubs/testdata/eventhubs_config.json) | ||
| <!--/codeinclude--> | ||
|
|
||
| ### Container Methods | ||
|
|
||
| The EventHubs container exposes the following methods: | ||
|
|
||
| #### ConnectionString | ||
|
|
||
| - Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| Returns the connection string to connect to the EventHubs container and an error, passing the Go context as parameter. | ||
|
|
||
| ### Examples | ||
|
|
||
| #### Send events to EventHubs | ||
|
|
||
| In the following example, inspired by the [Azure Event Hubs Go SDK](https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-go-get-started-send), we are creating an EventHubs container and sending events to it. | ||
|
|
||
| <!--codeinclude--> | ||
| [EventHubs Config](../../modules/azure/eventhubs/examples_test.go) inside_block:cfg | ||
| [Run EventHubs Container](../../modules/azure/eventhubs/examples_test.go) inside_block:runEventHubsContainer | ||
| [Create Producer Client](../../modules/azure/eventhubs/examples_test.go) inside_block:createProducerClient | ||
| [Create Sample Events](../../modules/azure/eventhubs/examples_test.go) inside_block:createSampleEvents | ||
| [Create Batch](../../modules/azure/eventhubs/examples_test.go) inside_block:createBatch | ||
| [Send Event Data Batch to the EventHub](../../modules/azure/eventhubs/examples_test.go) inside_block:sendEventDataBatch | ||
| <!--/codeinclude--> | ||
|
|
||
| ## ServiceBus | ||
|
|
||
| ### Run function | ||
|
|
||
| - Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| The ServiceBus module exposes one entrypoint function to create the ServiceBus container, and this function receives three parameters: | ||
|
|
||
| ```golang | ||
| func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) | ||
| ``` | ||
|
|
||
| - `context.Context`, the Go context. | ||
| - `string`, the Docker image to use. | ||
| - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. | ||
|
|
||
| The ServiceBus container needs a MSSQL Server container to be running, for that reason _Testcontainers for Go_ **automatically creates a Docker network and an MSSQL Server container** for ServiceBus to work. | ||
| When terminating the ServiceBus container, the MSSQL Server container and the Docker network are also terminated. | ||
|
|
||
| !!! info | ||
| Since version `1.1.2` of the ServiceBus emulator, it's possible to set the `SQL_WAIT_INTERVAL` environment variable to the given seconds. | ||
| This module sets it to `0` by default, because the MSSQL Server container is started first. | ||
|
|
||
| ### Container Options | ||
|
|
||
| When starting the ServiceBus container, you can pass options in a variadic way to configure it. | ||
|
|
||
| #### Image | ||
|
|
||
| Use the second argument in the `Run` function to set a valid Docker image. | ||
| In example: `Run(context.Background(), "mcr.microsoft.com/azure-messaging/servicebus-emulator:1.1.2")`. | ||
|
|
||
| {% include "../features/common_functional_options.md" %} | ||
|
|
||
| #### WithMSSQL | ||
|
|
||
| - Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This option allows you to set a different MSSQL Server Docker image, instead of the default one, and also pass options to the MSSQL container, in the form of a variadic argument of `testcontainers.ContainerCustomizer`. | ||
|
|
||
| #### WithAcceptEULA | ||
|
|
||
| - Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This option allows you to accept the EULA for the ServiceBus container. | ||
|
|
||
| #### WithConfig | ||
|
|
||
| - Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This option allows you to set a custom ServiceBus config file for the ServiceBus container. | ||
|
|
||
| The config file must be a valid ServiceBus config file, and it must be a valid JSON object. | ||
|
|
||
| <!--codeinclude--> | ||
| [ServiceBus JSON Config](../../modules/azure/servicebus/testdata/servicebus_config.json) | ||
| <!--/codeinclude--> | ||
|
|
||
| ### Container Methods | ||
|
|
||
| The ServiceBus container exposes the following methods: | ||
|
|
||
| #### ConnectionString | ||
|
|
||
| - Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| Returns the connection string to connect to the ServiceBus container and an error, passing the Go context as parameter. | ||
|
|
||
| ### Examples | ||
|
|
||
| #### Send events to ServiceBus | ||
|
|
||
| In the following example, inspired by the [Azure Event Hubs Go SDK](https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-go-get-started-send), we are creating an EventHubs container and sending events to it. | ||
|
|
||
| <!--codeinclude--> | ||
| [ServiceBus Config](../../modules/azure/servicebus/examples_test.go) inside_block:cfg | ||
| [Run ServiceBus Container](../../modules/azure/servicebus/examples_test.go) inside_block:runServiceBusContainer | ||
| [Create Client](../../modules/azure/servicebus/examples_test.go) inside_block:createClient | ||
| [Send messages to a Queue](../../modules/azure/servicebus/examples_test.go) inside_block:sendMessages | ||
| [Receive messages from a Queue](../../modules/azure/servicebus/examples_test.go) inside_block:receiveMessages | ||
| <!--/codeinclude--> |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.