testcontainers / testcontainers-dotnet

A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
https://dotnet.testcontainers.org
MIT License
3.65k stars 250 forks source link

chore: Ensure that stderr is empty after executing scripts #1116

Closed 0xced closed 3 months ago

0xced commented 4 months ago

What does this PR do?

This pull request add assertions to all tests that call ExecScriptAsync asserting that no error was written to stderr.

Adding these assertions found two issues, in the MySQL and MongoDB implementations.

MySQL would produce the following warning on stderr:

mysql: [Warning] Using a password on the command line interface can be insecure.

This has been addressed in 925f426081d8188dcc510898692f37db6e2933b2 by writing the configuration into /etc/mysql/my.cnf instead of passing it on the command line.

MongoDB would produce the following error on stderr (when using the mongo:4.4 image in the MongoDbV4Configuration test):

/bin/sh: 1: mongosh: not found

This has been addressed in 3ceeb4b02272d1f9d444fbc35e408e4fc2127192 by verifying if the mongosh binary exists and choosing the proper binary instead of running mongosh || mongo through /bin/sh. This also simplified the mongosh command implementation.

Finally, I also fixed some typos: // When should be // Then in the assertion part of the tests.

Why is it important?

Having stderr empty after successfully executing a script ensures that stderr will only contain actual errors and not spurious warnings or errors that are implementation detail errors that don't actually matter.

netlify[bot] commented 4 months ago

Deploy Preview for testcontainers-dotnet ready!

Name Link
Latest commit 4955a4ac385c61261088d9ffff70277c2911606b
Latest deploy log https://app.netlify.com/sites/testcontainers-dotnet/deploys/65f3417091b3610008b7d062
Deploy Preview https://deploy-preview-1116--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 site configuration.

HofmeisterAn commented 3 months ago

Thanks again.