Skip to content

Conversation

@EtherZa
Copy link
Contributor

@EtherZa EtherZa commented Sep 2, 2025

What does this PR do?

Adds support for the official Eclipse Mosquitto broker with anonymous publisher/subscriber topics. TLS can be optionally enabled.

Port Description
1883 MQTT
8883 MQTT (encrypted)
80 WebSocket
443 WebSocket Secure

Why is it important?

Container has been downloaded 500M+ times.
The python test containers module was added in June 2024.

Related issues

n/a

How to test this PR

Tests are available in the ./tests/TestContainers.Mosquitto.Tests project.

@netlify
Copy link

netlify bot commented Sep 2, 2025

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit d146f2d
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/691059143b414f0008f1d487
😎 Deploy Preview https://deploy-preview-1522--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@HofmeisterAn HofmeisterAn added module An official Testcontainers module enhancement New feature or request labels Sep 21, 2025
@HofmeisterAn HofmeisterAn force-pushed the develop branch 3 times, most recently from 4900ecd to 8fa5f1b Compare October 3, 2025 20:17
@coderabbitai
Copy link

coderabbitai bot commented Nov 8, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Mosquitto integration module with support for MQTT, MQTT over TLS, WebSocket, and secure WebSocket protocols, enabling testing of MQTT-based applications with optional certificate-based authentication.
  • Bug Fixes

    • Fixed TLS configuration validation to require both certificate and private key files.
  • Documentation

    • Added Mosquitto module entry to the modules reference documentation.

Walkthrough

Adds a new Testcontainers.Mosquitto module (builder, configuration, container), tests and test project, solution/project entries, MQTTnet package version, docs and editorconfig/usings, Testcontainers.dic/DotSettings updates, and tightens TLS detection in QdrantConfiguration.

Changes

Cohort / File(s) Summary
Package & Dictionaries
Directory.Packages.props, Testcontainers.dic, Testcontainers.sln.DotSettings
Added MQTTnet package version 5.0.1.1416; added mosquitto to user dictionaries.
Solution & Projects
Testcontainers.sln, src/Testcontainers.Mosquitto/Testcontainers.Mosquitto.csproj, tests/Testcontainers.Mosquitto.Tests/Testcontainers.Mosquitto.Tests.csproj
Added Testcontainers.Mosquitto and Testcontainers.Mosquitto.Tests projects to solution and project files; updated solution configuration mappings and project references.
Mosquitto Core
src/Testcontainers.Mosquitto/MosquittoBuilder.cs, src/Testcontainers.Mosquitto/MosquittoConfiguration.cs, src/Testcontainers.Mosquitto/MosquittoContainer.cs
New MosquittoBuilder (generates mosquitto.conf, listener/TLS config, build/validate/clone/merge), MosquittoConfiguration (certificate, key, TlsEnabled), and MosquittoContainer (endpoint getters, TLS checks, port mappings).
Project scaffolding & globals
src/Testcontainers.Mosquitto/.editorconfig, src/Testcontainers.Mosquitto/Usings.cs, tests/Testcontainers.Mosquitto.Tests/.editorconfig, tests/Testcontainers.Mosquitto.Tests/Usings.cs
Added EditorConfig and global using files for project and tests.
Tests & CI
tests/Testcontainers.Mosquitto.Tests/MosquittoContainerTest.cs, tests/Testcontainers.Mosquitto.Tests/.runs-on
Added abstract test base and four concrete test configurations (TCP/WebSocket × TLS/unencrypted) and set CI runner to ubuntu-24.04.
Docs
docs/modules/index.md
Added Mosquitto module entry (image eclipse-mosquitto:2.0) with links.
Other
src/Testcontainers.Qdrant/QdrantConfiguration.cs
Tightened TLS detection to require both certificate and private key to enable TLS.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Test as Test Code
    participant Builder as MosquittoBuilder
    participant Config as MosquittoConfiguration
    participant Docker as Docker Engine
    participant Container as MosquittoContainer

    Test->>Builder: new (optionally WithCertificate)
    Builder->>Config: create/merge configuration
    Test->>Builder: Build()
    Builder->>Builder: Validate & generate mosquitto.conf
    Builder->>Docker: Create/start container (map files & ports)
    Docker-->>Container: Running
    Test->>Container: GetConnectionString/GetSecureConnectionString/GetWsConnectionString/GetWssConnectionString
    Container-->>Test: Return URI (uses Hostname + mapped public port)
    Test->>Test: Connect via MQTTnet client, publish & subscribe
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Review focus:
    • mosquitto.conf generation and listener/TLS logic in MosquittoBuilder.cs
    • Certificate file mapping and TLS enabling/validation across Configuration/Builder/Container
    • Endpoint URI construction and port mapping in MosquittoContainer.cs
    • Tests: TLS behaviors, certificate handling, and CI runner expectations

Poem

🐰 I hopped through configs, ports, and keys,

I stitched a broker with gentle ease.
TCP, WS, secure or plain,
I nibbled tests until they sang again.
🎉📡

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 56.25% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: Add Mosquitto module' is concise, specific, and clearly summarizes the main change - adding support for Eclipse Mosquitto container integration.
Description check ✅ Passed The PR description includes all mandatory sections: 'What does this PR do?' explaining the Mosquitto support with port mappings, and 'Why is it important?' citing download statistics and precedent.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8617ccf and 5c40cce.

📒 Files selected for processing (17)
  • Directory.Packages.props (1 hunks)
  • Testcontainers.dic (1 hunks)
  • Testcontainers.sln (6 hunks)
  • Testcontainers.sln.DotSettings (1 hunks)
  • docs/modules/index.md (1 hunks)
  • src/Testcontainers.Mosquitto/.editorconfig (1 hunks)
  • src/Testcontainers.Mosquitto/MosquittoBuilder.cs (1 hunks)
  • src/Testcontainers.Mosquitto/MosquittoConfiguration.cs (1 hunks)
  • src/Testcontainers.Mosquitto/MosquittoContainer.cs (1 hunks)
  • src/Testcontainers.Mosquitto/Testcontainers.Mosquitto.csproj (1 hunks)
  • src/Testcontainers.Mosquitto/Usings.cs (1 hunks)
  • tests/Testcontainers.Mosquitto.Tests/.editorconfig (1 hunks)
  • tests/Testcontainers.Mosquitto.Tests/.runs-on (1 hunks)
  • tests/Testcontainers.Mosquitto.Tests/MosquittoContainerTest.cs (1 hunks)
  • tests/Testcontainers.Mosquitto.Tests/PemCertificate.cs (1 hunks)
  • tests/Testcontainers.Mosquitto.Tests/Testcontainers.Mosquitto.Tests.csproj (1 hunks)
  • tests/Testcontainers.Mosquitto.Tests/Usings.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (6)
src/Testcontainers.Mosquitto/Usings.cs (1)
src/Testcontainers/Polyfills/X509Certificate2.cs (1)
  • System (17-52)
src/Testcontainers.Mosquitto/MosquittoConfiguration.cs (3)
src/Testcontainers.Mosquitto/MosquittoBuilder.cs (1)
  • PublicAPI (4-127)
src/Testcontainers.Mosquitto/MosquittoContainer.cs (1)
  • PublicAPI (4-84)
src/Testcontainers/Builders/BuildConfiguration.cs (1)
  • BuildConfiguration (13-150)
src/Testcontainers.Mosquitto/MosquittoBuilder.cs (2)
src/Testcontainers.Mosquitto/MosquittoContainer.cs (2)
  • PublicAPI (4-84)
  • MosquittoContainer (13-17)
src/Testcontainers.Mosquitto/MosquittoConfiguration.cs (6)
  • PublicAPI (4-75)
  • MosquittoConfiguration (10-16)
  • MosquittoConfiguration (22-26)
  • MosquittoConfiguration (32-36)
  • MosquittoConfiguration (42-46)
  • MosquittoConfiguration (53-59)
tests/Testcontainers.Mosquitto.Tests/Usings.cs (1)
src/Testcontainers/Polyfills/X509Certificate2.cs (1)
  • System (17-52)
src/Testcontainers.Mosquitto/MosquittoContainer.cs (2)
src/Testcontainers.Mosquitto/MosquittoBuilder.cs (9)
  • PublicAPI (4-127)
  • MosquittoContainer (35-78)
  • MosquittoBuilder (19-23)
  • MosquittoBuilder (25-29)
  • MosquittoBuilder (80-87)
  • MosquittoBuilder (90-99)
  • MosquittoBuilder (111-114)
  • MosquittoBuilder (117-120)
  • MosquittoBuilder (123-126)
src/Testcontainers/Containers/DockerContainer.cs (5)
  • PublicAPI (19-758)
  • DockerContainer (36-40)
  • GetMappedPublicPort (256-260)
  • GetMappedPublicPort (263-266)
  • GetMappedPublicPort (269-283)
tests/Testcontainers.Mosquitto.Tests/MosquittoContainerTest.cs (3)
src/Testcontainers.Mosquitto/MosquittoBuilder.cs (8)
  • MosquittoBuilder (19-23)
  • MosquittoBuilder (25-29)
  • MosquittoBuilder (80-87)
  • MosquittoBuilder (90-99)
  • MosquittoBuilder (111-114)
  • MosquittoBuilder (117-120)
  • MosquittoBuilder (123-126)
  • MosquittoContainer (35-78)
src/Testcontainers.Mosquitto/MosquittoContainer.cs (5)
  • MosquittoContainer (13-17)
  • GetPort (32-35)
  • GetSecurePort (51-54)
  • GetWsEndpoint (60-63)
  • GetWssEndpoint (69-73)
tests/Testcontainers.Mosquitto.Tests/PemCertificate.cs (3)
  • PemCertificate (3-35)
  • PemCertificate (5-7)
  • PemCertificate (9-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.BigQuery, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: analyze (csharp)
🔇 Additional comments (13)
tests/Testcontainers.Mosquitto.Tests/PemCertificate.cs (3)

9-23: LGTM!

The certificate generation logic is correct and appropriate for test scenarios. Resource management is properly handled with using statements.


25-26: LGTM!

The singleton pattern is appropriate for this test utility, and using "localhost" as the common name is correct for local testing scenarios.


28-34: LGTM!

The public properties provide appropriate read-only access to the certificate data.

tests/Testcontainers.Mosquitto.Tests/.editorconfig (1)

1-1: LGTM - minimal EditorConfig setup.

The file correctly marks the root but doesn't define any formatting rules. This is acceptable if rules are inherited from a solution-level .editorconfig.

src/Testcontainers.Mosquitto/.editorconfig (1)

1-1: LGTM - minimal EditorConfig setup.

Consistent with the test project's .editorconfig approach.

Testcontainers.sln.DotSettings (1)

29-29: LGTM - dictionary entry added correctly.

The addition of "mosquitto" to the user dictionary is properly placed in alphabetical order and follows the existing pattern.

Testcontainers.dic (1)

20-20: LGTM - dictionary entry added correctly.

The "mosquitto" entry is properly positioned alphabetically and follows the existing format.

src/Testcontainers.Mosquitto/Usings.cs (1)

1-10: LGTM - comprehensive global usings.

The global usings provide convenient access to commonly needed namespaces. The selection appears reasonable for a Testcontainers module that likely handles Docker configurations, file I/O for certificates, and text processing.

tests/Testcontainers.Mosquitto.Tests/Usings.cs (1)

1-10: LGTM - test usings with crypto support.

The global usings appropriately include crypto namespaces for TLS testing and standard test frameworks. The self-reference to Testcontainers.Mosquitto.Tests on line 8 is unusual but acceptable if there are shared test utilities within the namespace.

tests/Testcontainers.Mosquitto.Tests/.runs-on (1)

1-1: No issues found.

ubuntu-24.04 is a supported GitHub Actions runner image, and as of January 17, 2025, it became the default ubuntu-latest image. The .runs-on file correctly specifies ubuntu-24.04, which is appropriate for this PR.

Directory.Packages.props (1)

74-74: MQTTnet version is current and secure.

Version 5.0.1.1416 is the latest stable release on NuGet (published January 5, 2025), and no known security vulnerabilities have been reported for this version. No action required.

docs/modules/index.md (1)

58-58: Documentation entry looks great.

Line 58 cleanly adds Mosquitto with the right image and links, keeping the modules table consistent. Nicely done.

src/Testcontainers.Mosquitto/Testcontainers.Mosquitto.csproj (1)

1-11: Project configuration looks solid.

Multi-targeting and the JetBrains.Annotations reference line up with the rest of the solution—no issues spotted here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
tests/Testcontainers.Mosquitto.Tests/MosquittoContainerTest.cs (1)

78-83: Consider testing the GetEndpoint() and GetSecureEndpoint() methods.

The TCP test configurations manually construct the connection using Container.Hostname and Container.GetMappedPublicPort(), but don't use the GetEndpoint() and GetSecureEndpoint() convenience methods. In contrast, the WebSocket configurations do use GetWsEndpoint() and GetWssEndpoint().

Since there are bugs in GetEndpoint() and GetSecureEndpoint() (incorrect URI scheme), adding tests that use these methods would catch such issues.

Consider refactoring to use the endpoint methods:

 protected override MqttClientOptions GetClientOptions()
 {
+    var endpoint = new Uri(Container.GetEndpoint());
     return new MqttClientOptionsBuilder()
-        .WithTcpServer(Container.Hostname, Container.GetMappedPublicPort(MosquittoBuilder.MqttPort))
+        .WithTcpServer(endpoint.Host, endpoint.Port)
         .Build();
 }

This would ensure the endpoint helper methods work as expected and provide a consistent API across TCP and WebSocket transports.

Also applies to: 95-102

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c40cce and 8f02018.

📒 Files selected for processing (7)
  • src/Testcontainers.Mosquitto/MosquittoBuilder.cs (1 hunks)
  • src/Testcontainers.Mosquitto/MosquittoConfiguration.cs (1 hunks)
  • src/Testcontainers.Mosquitto/MosquittoContainer.cs (1 hunks)
  • src/Testcontainers.Mosquitto/Testcontainers.Mosquitto.csproj (1 hunks)
  • src/Testcontainers.Mosquitto/Usings.cs (1 hunks)
  • tests/Testcontainers.Mosquitto.Tests/MosquittoContainerTest.cs (1 hunks)
  • tests/Testcontainers.Mosquitto.Tests/Usings.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/Testcontainers.Mosquitto.Tests/Usings.cs
  • src/Testcontainers.Mosquitto/MosquittoBuilder.cs
  • src/Testcontainers.Mosquitto/Testcontainers.Mosquitto.csproj
🧰 Additional context used
🧬 Code graph analysis (3)
src/Testcontainers.Mosquitto/MosquittoContainer.cs (3)
src/Testcontainers.Mosquitto/MosquittoBuilder.cs (9)
  • PublicAPI (4-139)
  • MosquittoContainer (59-110)
  • MosquittoBuilder (24-28)
  • MosquittoBuilder (34-38)
  • MosquittoBuilder (49-56)
  • MosquittoBuilder (113-120)
  • MosquittoBuilder (123-126)
  • MosquittoBuilder (129-132)
  • MosquittoBuilder (135-138)
src/Testcontainers.Mosquitto/MosquittoConfiguration.cs (6)
  • PublicAPI (4-76)
  • MosquittoConfiguration (12-18)
  • MosquittoConfiguration (24-28)
  • MosquittoConfiguration (34-38)
  • MosquittoConfiguration (44-48)
  • MosquittoConfiguration (55-60)
src/Testcontainers/Containers/DockerContainer.cs (5)
  • PublicAPI (19-758)
  • DockerContainer (36-40)
  • GetMappedPublicPort (256-260)
  • GetMappedPublicPort (263-266)
  • GetMappedPublicPort (269-283)
tests/Testcontainers.Mosquitto.Tests/MosquittoContainerTest.cs (3)
src/Testcontainers.Mosquitto/MosquittoBuilder.cs (8)
  • MosquittoBuilder (24-28)
  • MosquittoBuilder (34-38)
  • MosquittoBuilder (49-56)
  • MosquittoBuilder (113-120)
  • MosquittoBuilder (123-126)
  • MosquittoBuilder (129-132)
  • MosquittoBuilder (135-138)
  • MosquittoContainer (59-110)
src/Testcontainers.Mosquitto/MosquittoContainer.cs (3)
  • MosquittoContainer (13-17)
  • GetWsEndpoint (42-45)
  • GetWssEndpoint (51-55)
tests/Testcontainers.Commons/Certificates.cs (2)
  • Certificates (10-26)
  • GetFilePath (36-57)
src/Testcontainers.Mosquitto/MosquittoConfiguration.cs (3)
src/Testcontainers.Mosquitto/MosquittoBuilder.cs (1)
  • PublicAPI (4-139)
src/Testcontainers.Mosquitto/MosquittoContainer.cs (1)
  • PublicAPI (4-68)
src/Testcontainers/Builders/BuildConfiguration.cs (1)
  • BuildConfiguration (13-150)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.BigQuery, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: analyze (csharp)
🔇 Additional comments (6)
src/Testcontainers.Mosquitto/Usings.cs (1)

1-8: LGTM!

The global usings are appropriate for a Testcontainers module and follow the standard pattern used across the repository.

src/Testcontainers.Mosquitto/MosquittoConfiguration.cs (1)

55-60: LGTM!

The merge constructor correctly uses BuildConfiguration.Combine to merge the certificate properties, following the standard Testcontainers pattern for configuration merging.

src/Testcontainers.Mosquitto/MosquittoContainer.cs (2)

42-45: LGTM!

The WebSocket endpoint methods correctly use the "ws" and "wss" schemes, which are standard for WebSocket connections.

Also applies to: 51-55


61-67: LGTM!

Good defensive coding to prevent calling TLS endpoint methods when TLS is not configured. The exception message is clear and helpful.

tests/Testcontainers.Mosquitto.Tests/MosquittoContainerTest.cs (2)

3-72: LGTM!

Excellent test design using an abstract base class to enable multiple configuration scenarios. The tests comprehensively cover connection establishment and publish/subscribe functionality. The use of TaskCompletionSource for async message handling is a clean pattern.


86-103: LGTM!

The TLS-enabled test configurations properly override Configure() to install certificates and implement appropriate certificate validation in GetClientOptions(). The validation callback checking the certificate issuer ("CN=Test CA") is a good practice for test environments.

Also applies to: 117-134

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/Testcontainers.Mosquitto/MosquittoConfiguration.cs (1)

65-65: Consider checking for empty or whitespace strings in TlsEnabled.

The property currently only checks for null, but empty or whitespace-only strings would pass this check and cause runtime failures when the container attempts to configure TLS with invalid certificate data.

Apply this diff to strengthen the validation:

-public bool TlsEnabled => Certificate != null && CertificateKey != null;
+public bool TlsEnabled => !string.IsNullOrWhiteSpace(Certificate) && !string.IsNullOrWhiteSpace(CertificateKey);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f02018 and e6a01e6.

📒 Files selected for processing (3)
  • src/Testcontainers.Mosquitto/MosquittoConfiguration.cs (1 hunks)
  • src/Testcontainers.Mosquitto/MosquittoContainer.cs (1 hunks)
  • src/Testcontainers.Qdrant/QdrantConfiguration.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/Testcontainers.Mosquitto/MosquittoConfiguration.cs (1)
src/Testcontainers/Builders/BuildConfiguration.cs (1)
  • BuildConfiguration (13-150)
src/Testcontainers.Mosquitto/MosquittoContainer.cs (3)
src/Testcontainers.Mosquitto/MosquittoConfiguration.cs (6)
  • PublicAPI (4-76)
  • MosquittoConfiguration (12-18)
  • MosquittoConfiguration (24-28)
  • MosquittoConfiguration (34-38)
  • MosquittoConfiguration (44-48)
  • MosquittoConfiguration (55-60)
src/Testcontainers.Mosquitto/MosquittoBuilder.cs (9)
  • PublicAPI (4-139)
  • MosquittoContainer (59-110)
  • MosquittoBuilder (24-28)
  • MosquittoBuilder (34-38)
  • MosquittoBuilder (49-56)
  • MosquittoBuilder (113-120)
  • MosquittoBuilder (123-126)
  • MosquittoBuilder (129-132)
  • MosquittoBuilder (135-138)
src/Testcontainers/Containers/DockerContainer.cs (5)
  • PublicAPI (19-758)
  • DockerContainer (36-40)
  • GetMappedPublicPort (256-260)
  • GetMappedPublicPort (263-266)
  • GetMappedPublicPort (269-283)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.BigQuery, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: analyze (csharp)
🔇 Additional comments (2)
src/Testcontainers.Qdrant/QdrantConfiguration.cs (1)

69-69: No issues found—logic is correct and no breaking changes.

The tightened TLS check is sound. The public API WithCertificate() enforces both certificate and key parameters together, and all existing usage provides both. The change makes TlsEnabled accurately reflect actual TLS readiness, correcting a pre-existing logical issue (TLS cannot function with only a certificate).

While this Qdrant fix is out of scope for the stated "Add Mosquitto module" PR, it's a legitimate bug fix discovered while implementing similar TLS logic for Mosquitto. Consider documenting this in the PR description or moving to a separate PR for clarity.

src/Testcontainers.Mosquitto/MosquittoContainer.cs (1)

23-55: Verify that MQTT clients handle the trailing slash correctly.

UriBuilder.ToString() appends a trailing slash to all endpoint URIs (mqtt://hostname:port/, mqtts://hostname:port/, etc.). Some MQTT client libraries may be sensitive to this format. Consider testing these endpoints with the MQTT client libraries you'll be using to ensure compatibility.

If the trailing slash causes issues, you can remove it:

-return new UriBuilder("mqtt", Hostname, GetMappedPublicPort(MosquittoBuilder.MqttPort)).ToString();
+return new UriBuilder("mqtt", Hostname, GetMappedPublicPort(MosquittoBuilder.MqttPort)).Uri.ToString().TrimEnd('/');

Apply similar changes to the other endpoint methods if needed.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/Testcontainers.Mosquitto/MosquittoContainer.cs (1)

19-27: Consider adding properties for WebSocket ports to maintain API consistency.

The module exposes MqttPort and MqttTlsPort as properties, but GetWsConnectionString() and GetWssConnectionString() call GetMappedPublicPort() directly (lines 55, 66). Adding MqttWsPort and MqttWssPort properties would provide a more uniform API and allow consumers to access these ports independently if needed.

Example addition:

     /// <summary>
     /// Gets the secure MQTT port.
     /// </summary>
     public ushort MqttTlsPort => GetMappedPublicPort(MosquittoBuilder.MqttTlsPort);
+
+    /// <summary>
+    /// Gets the MQTT over WebSocket port.
+    /// </summary>
+    public ushort MqttWsPort => GetMappedPublicPort(MosquittoBuilder.MqttWsPort);
+
+    /// <summary>
+    /// Gets the secure MQTT over WebSocket port.
+    /// </summary>
+    public ushort MqttWssPort => GetMappedPublicPort(MosquittoBuilder.MqttWssPort);

Then update the connection string methods to use these properties:

     public string GetWsConnectionString()
     {
-        return new UriBuilder("ws", Hostname, GetMappedPublicPort(MosquittoBuilder.MqttWsPort)).ToString();
+        return new UriBuilder("ws", Hostname, MqttWsPort).ToString();
     }
     public string GetWssConnectionString()
     {
         ThrowIfTlsNotEnabled();
-        return new UriBuilder("wss", Hostname, GetMappedPublicPort(MosquittoBuilder.MqttWssPort)).ToString();
+        return new UriBuilder("wss", Hostname, MqttWssPort).ToString();
     }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6a01e6 and d146f2d.

📒 Files selected for processing (2)
  • src/Testcontainers.Mosquitto/MosquittoContainer.cs (1 hunks)
  • tests/Testcontainers.Mosquitto.Tests/MosquittoContainerTest.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Testcontainers.Mosquitto.Tests/MosquittoContainerTest.cs
🧰 Additional context used
🧬 Code graph analysis (1)
src/Testcontainers.Mosquitto/MosquittoContainer.cs (3)
src/Testcontainers.Mosquitto/MosquittoConfiguration.cs (6)
  • PublicAPI (4-76)
  • MosquittoConfiguration (12-18)
  • MosquittoConfiguration (24-28)
  • MosquittoConfiguration (34-38)
  • MosquittoConfiguration (44-48)
  • MosquittoConfiguration (55-60)
src/Testcontainers.Mosquitto/MosquittoBuilder.cs (9)
  • PublicAPI (4-139)
  • MosquittoContainer (59-110)
  • MosquittoBuilder (24-28)
  • MosquittoBuilder (34-38)
  • MosquittoBuilder (49-56)
  • MosquittoBuilder (113-120)
  • MosquittoBuilder (123-126)
  • MosquittoBuilder (129-132)
  • MosquittoBuilder (135-138)
src/Testcontainers/Containers/DockerContainer.cs (5)
  • PublicAPI (19-758)
  • DockerContainer (36-40)
  • GetMappedPublicPort (256-260)
  • GetMappedPublicPort (263-266)
  • GetMappedPublicPort (269-283)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ClickHouse, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: analyze (csharp)

Copy link
Collaborator

@HofmeisterAn HofmeisterAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing the Mosquitto module! There were some major changes in the develop branch, so I updated the PR to align with the latest repo standards. I also adjusted the ports to match the documented ones (https://test.mosquitto.org/) and simplified the tests a bit.

The module implementation looks good now. If you notice anything missing or think we should change something, feel free to open an issue or comment on the PR. Thanks again.

@HofmeisterAn HofmeisterAn merged commit b822e61 into testcontainers:develop Nov 9, 2025
78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request module An official Testcontainers module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants