Skip to content

Add Mosquitto module#1390

Merged
cristianrgreco merged 12 commits into
testcontainers:mainfrom
ChxGuillaume:feat/mosquitto-module
Jun 29, 2026
Merged

Add Mosquitto module#1390
cristianrgreco merged 12 commits into
testcontainers:mainfrom
ChxGuillaume:feat/mosquitto-module

Conversation

@ChxGuillaume

Copy link
Copy Markdown
Contributor

Add Mosquitto module

This PR introduces a new @testcontainers/mosquitto module for the Eclipse Mosquitto MQTT broker, following the same structure as the existing HiveMQ module.

What's included

  • MosquittoContainer — starts an eclipse-mosquitto:2 container with a custom config injected at startup, since Mosquitto 2.x disallows anonymous connections by default
  • Anonymous mode (allow_anonymous true) out of the box
  • Authenticated mode via withUsername() / withPassword() — creates the password file using mosquitto_passwd -b before launching the broker, with a chown to fix ownership since Mosquitto drops privileges to the mosquitto user
  • StartedMosquittoContainer.getPort() and getConnectionString() — the latter includes credentials in the URL when auth is configured
  • Two test files (mosquitto-container.test.ts and mosquitto-container-auth.test.ts) kept separate to avoid a codeinclude block-name collision between mosquittoConnect and mosquittoConnectWithCredentials
  • Documentation at docs/modules/mosquitto.md with codeinclude examples for both usage patterns, added to the mkdocs navigation

…up log matching, upgrade to Mosquitto 2 base image, and fix file permissions during setup.
…o a dedicated file and updated related documentation references.
@netlify

netlify Bot commented Jun 28, 2026

Copy link
Copy Markdown

Deploy Preview for testcontainers-node ready!

Name Link
🔨 Latest commit 676fffb
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-node/deploys/6a4244e97462ee000860fb16
😎 Deploy Preview https://deploy-preview-1390--testcontainers-node.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.

@cristianrgreco cristianrgreco left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the module — nice and clean, closely following the HiveMQ structure. A few notes inline. Two points that don't anchor well to a single line:

  • package-lock.json: the diff also removes libc arrays from several unrelated packages (lightningcss and one MPL-2.0 dep). That looks like npm-version drift rather than part of this module. Could you regenerate the lockfile with the project's npm version so the only change here is the new @testcontainers/mosquitto entry?

  • Prior art: for what it's worth, Mosquitto modules already exist in .NET (Testcontainers.Mosquitto), Python (testcontainers[mqtt]) and Rust (testcontainers-rs-modules-community), so this is a welcome addition. The .NET module is the closest reference if we ever want cross-language API consistency.

Comment thread mkdocs.yml Outdated
Comment thread packages/modules/mosquitto/src/mosquitto-container.ts Outdated
Comment thread packages/modules/mosquitto/src/mosquitto-container.ts
Comment thread packages/modules/mosquitto/src/mosquitto-container.ts
Comment thread packages/modules/mosquitto/src/mosquitto-container-auth.test.ts Outdated
Comment thread packages/modules/mosquitto/Dockerfile Outdated
@cristianrgreco cristianrgreco added enhancement New feature or request minor Backward compatible functionality labels Jun 29, 2026

@cristianrgreco cristianrgreco left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the quick turnaround — this addresses almost all of the earlier feedback:

  • ✅ Image pinned to eclipse-mosquitto:2.0.22
  • ✅ Nav entry now alphabetically placed (after MongoDB)
  • ✅ Wait strategy switched to Wait.forListeningPorts() — more robust than the log regex
  • withUsername/withPassword reject empty values
  • ✅ Partial auth now fails loudly via the XOR check (Both username and password must be set together.)
  • ✅ Tests merged into a single mosquitto-container.test.ts with two it() blocks, docs updated

The XOR guard and the forListeningPorts() switch both look correct. One item from the previous round is still outstanding:

package-lock.json — the diff still strips libc arrays from several unrelated packages (lightningcss and one MPL-2.0 dep); the hunk is unchanged from before. This is npm-version drift rather than part of the module. Could you regenerate the lockfile with the project's npm version (or revert those specific hunks) so the only change is the new @testcontainers/mosquitto entry? Once that's cleaned up I think this is good to go.

@ChxGuillaume ChxGuillaume force-pushed the feat/mosquitto-module branch from 4b36c3d to 2d65607 Compare June 29, 2026 09:04
@ChxGuillaume

ChxGuillaume commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the quick turnaround — this addresses almost all of the earlier feedback:

  • ✅ Image pinned to eclipse-mosquitto:2.0.22
  • ✅ Nav entry now alphabetically placed (after MongoDB)
  • ✅ Wait strategy switched to Wait.forListeningPorts() — more robust than the log regex
  • withUsername/withPassword reject empty values
  • ✅ Partial auth now fails loudly via the XOR check (Both username and password must be set together.)
  • ✅ Tests merged into a single mosquitto-container.test.ts with two it() blocks, docs updated

The XOR guard and the forListeningPorts() switch both look correct. One item from the previous round is still outstanding:

package-lock.json — the diff still strips libc arrays from several unrelated packages (lightningcss and one MPL-2.0 dep); the hunk is unchanged from before. This is npm-version drift rather than part of the module. Could you regenerate the lockfile with the project's npm version (or revert those specific hunks) so the only change is the new @testcontainers/mosquitto entry? Once that's cleaned up I think this is good to go.

Hey i'm quite not used to handle this kind of package-lock, i've tried to generate it but it was always removing them, is it because i'm working on a Mac or something would like know if you can help me learn more on that thing 😅

Updated it kind "manually" to have them back but i'm not a huge fan of this move...

@cristianrgreco

Copy link
Copy Markdown
Collaborator

@ChxGuillaume Which version of Node/NPM are you using?

@ChxGuillaume

Copy link
Copy Markdown
Contributor Author

@ChxGuillaume Which version of Node/NPM are you using?

npm --version && node -v
11.16.0
v24.18.0

Just installed the last Node version with NVM to try and generate it

Comment thread packages/modules/mosquitto/src/mosquitto-container.ts Outdated
@cristianrgreco

Copy link
Copy Markdown
Collaborator

@ChxGuillaume Two things to get CI green:

1. Lint failure (Lint (mosquitto))

It's just a Prettier formatting nit — an extra space:

packages/modules/mosquitto/src/mosquitto-container.ts
  60:3  error  Delete `·`  prettier/prettier

CI runs ESLint without --fix, so it fails on it. From the repo root just run:

npm run lint

That auto-fixes it (it's eslint --fix with the Prettier plugin). npm run format works too. Then commit the result.

2. The package-lock.json

Now that you're on Node 24.18 / npm 11.16 you're on the right toolchain — that version doesn't prune the cross-platform optional deps, so no need to edit anything by hand. The key is to start from a clean lockfile rather than regenerating on top of the manually-edited one:

git checkout main -- package-lock.json   # discard the hand-edited version
npm install --package-lock-only           # npm 11.16 re-resolves cleanly
git diff package-lock.json                 # should show ONLY the @testcontainers/mosquitto entry

If that diff shows just the new @testcontainers/mosquitto block (plus your module's workspace entry) and nothing about sharp/couchbase/lightningcss/libc, it's correct — commit it.

For background on why it was happening before: the disappearing packages are platform-specific native binaries (Linux/Windows/musl), and older npm versions rewrite the lockfile from what's installed locally, dropping everything that doesn't match your Mac. npm 11.x fixes that, so you're good now. 👍

@cristianrgreco cristianrgreco changed the title Adding module mosquitto Add Mosquitto module Jun 29, 2026
@cristianrgreco cristianrgreco merged commit b118d2c into testcontainers:main Jun 29, 2026
529 of 531 checks passed
@cristianrgreco

Copy link
Copy Markdown
Collaborator

Thanks for your contribution and for the fast feedback @ChxGuillaume

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request minor Backward compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants