Allow configuring the AlwaysPullPolicy by sebastian-steiner · Pull Request #10188 · testcontainers/testcontainers-java
This PR fixes a bug that did not allow configuring the default provided AlwaysPullPolicy through the properties files.
Previous behavior
When trying to configure the following testcontainers.properties:
pull.policy=org.testcontainers.images.CustomAlwaysPullPolicy
Running tests would fail with the following exception, because the configuration couldn't access the package-private constructor:
Configured ImagePullPolicy could not be loaded: org.testcontainers.images.AlwaysPullPolicy
java.lang.IllegalArgumentException: Configured ImagePullPolicy could not be loaded: org.testcontainers.images.AlwaysPullPolicy
at org.testcontainers.images.PullPolicy.defaultPolicy(PullPolicy.java:46)
at org.testcontainers.images.RemoteDockerImage.<init>(RemoteDockerImage.java:47)
at org.testcontainers.containers.GenericContainer.<init>(GenericContainer.java:245)
...
Caused by: java.lang.NoSuchMethodException: org.testcontainers.images.AlwaysPullPolicy.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3761)
at java.base/java.lang.Class.getConstructor(Class.java:2442)
at org.testcontainers.images.PullPolicy.defaultPolicy(PullPolicy.java:43)
... 8 more
Expected behavior
With this fix, the AlwaysPullPolicy can be configured directly in withImagePullPolicy(PullPolicy.alwaysPull()) and through the properties files.
Docs change
I would also propose a small change to the docs to contain an example that is functioning without users needing to provide their own implementation for testing purposes. I'm not sure though if this is something that fits the overall docs, so feel free to not include it.