testcontainers / testcontainers-python

Testcontainers is a Python library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.
https://testcontainers-python.readthedocs.io/en/latest/
Apache License 2.0
1.44k stars 270 forks source link

fix(mqtt): Add mqtt.MosquittoContainer (#568) #599

Closed f18m closed 1 month ago

f18m commented 1 month ago

This PR is adding a new MosquittoContainer class that helps creating integration tests for MQTT clients. The MosquittoContainer class contains a bunch of methods to help with testing:

This PR lacks tests. I can add them if there is interest in this PR...

f18m commented 1 month ago

interest is there, would merge a more generic and simpler/smaller version

ok thanks for the review! let me try to address the various points you raised

f18m commented 1 month ago

@alexanderankin please note that I also checked in the "integration-test-mosquitto.conf" that is bind-mounted in the init ctor. I'm not sure what's the best way to deliver this kind of resources (the conf file) inside the project... so I just dropped it in the same folder of the init.py file, which is what the init ctor uses for creating the bind-mount...

alexanderankin commented 1 month ago

mounting files is probably the most straight forward way to do it but I would move it into the _configure (or start if you want ultimate backwards compatibility) method rather than the constructor. there is a concept of a transferable interface which can be implemented for strings and bytes/io but it is not merged, there is a couple commits here which should eventually make it into the project - https://github.com/testcontainers/testcontainers-python/compare/2bd20c6a9ab811343beee150a4816711848fb9ea...alexanderankin:testcontainers-python:TCP-393_transferable - the code in the kafka container which does the some thing is even more concise. i think there may be some chance that this transferable thing is going to make it into the project through one of the PR's that are doing database seeding (helpers around init-db.d)

I misread. yes checking the files in the same directory is what i typically do also, and reference with relative path via:

from pathlib import Path
Path(__file__).parent / 'adjacent-folder' / 'the-file.ext'
codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Please upload report for BASE (main@ec76df2). Learn more about missing BASE report.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #599 +/- ## ======================================= Coverage ? 75.18% ======================================= Files ? 10 Lines ? 548 Branches ? 77 ======================================= Hits ? 412 Misses ? 110 Partials ? 26 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

f18m commented 1 month ago
Path(__file__).parent

moved into start() the volume mapping bind!

f18m commented 1 month ago

@alexanderankin just take a look again when you have time, thanks

alexanderankin commented 1 month ago

this is probably what id like to merge, lmk if this works for you:

https://github.com/testcontainers/testcontainers-python/compare/feature/mosquitto

f18m commented 1 month ago

this is probably what id like to merge, lmk if this works for you:

https://github.com/testcontainers/testcontainers-python/compare/feature/mosquitto

super! I see you added support also for Mosquitto 1.x, which is something I never used. I think it's good to have.

I think it's just good. Once merged I will rework my project to make use of the MosquittoContainer class and report back any possible issue. Thanks

alexanderankin commented 1 month ago

if you want you can pip install into your project from the branch and do some testing before it is released as well

alexanderankin commented 1 month ago

ok ill merge at some point today.

f18m commented 1 month ago

ok ill merge at some point today.

yeah I don't think I will manage to adapt my project that relies on MosquittoContainer fast enough. But next week I think I will have some time to do that and will report back

alexanderankin commented 1 month ago

gonna merge because it modifies the poetry lock file and dont wanna have conflicts, still a chance to try it before it gets released

f18m commented 1 month ago

hi @alexanderankin , I'm trying to understand how to test an unreleased version of testcontainers-python. However I see that the CI/CD step 'Release Please / publish (push) ' is Skipped... are testcontainers-python artifacts published somewhere after every commit?

f18m commented 1 month ago

hi @alexanderankin , I'm trying to understand how to test an unreleased version of testcontainers-python. However I see that the CI/CD step 'Release Please / publish (push) ' is Skipped... are testcontainers-python artifacts published somewhere after every commit?

Never mind: I installed the main branch locally from git into my python path. So far so good. I have tested successfully the MosquittoContainer inside my pre-existing integration tests. I actually have a MosquittoContainerEnhanced class adding on top of MosquittoContainer the ability to 'watch' topics. All good so far! Watching for next release of testcontainers-python, thanks!