How to check if a valid container environment is available? #1130
-
I would like to skip tests instead of failing them if the environment does not have a valid environment for running the containers. Essentially a check on whether the socket is available. Is this something that the library supports with some static property somewhere? How else can I achieve this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
There is nothing built in like this in Testcontainers. I am not quite sure if that is really the responsibility of Testcontainers, rather than the responsibility of the test framework (although we can provide features that help to determine whether tests should be skipped). But we do something similar in our tests to distinguish between container platforms. In xUnit.net, you can either implement a custom FactAttribute or use a Trait annotation. Then you can use the --filter flag to distinguish between the tests. Does that help? |
Beta Was this translation helpful? Give feedback.
What do you mean by that? The host OS, the contianer OS, the enabled engine (Linux/Windows)?
I am not sure if I understood what you are trying to achieve (maybe you need to elaborate on that), but if you would like to run tests depending on the supported container OS (enabled Docker engine), you can use a similar approach to ours. We check the
docker version --format '{{.Server.Os}}'
response to determine whether the container runtime (host) supports Linux or Windows containers.testcontainers-dotnet/tests/Testcontainers.Commons/DockerCli.cs
Lines…