Skip to content

Commit 73e0637

Browse files
Allow configuring the AlwaysPullPolicy (#10188)
1 parent 57b3402 commit 73e0637

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

core/src/main/java/org/testcontainers/images/PullPolicy.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static synchronized ImagePullPolicy defaultPolicy() {
4040
.currentThread()
4141
.getContextClassLoader()
4242
.loadClass(imagePullPolicyClassName)
43-
.getConstructor()
43+
.getDeclaredConstructor()
4444
.newInstance();
4545
} catch (Exception e) {
4646
throw new IllegalArgumentException(

core/src/test/java/org/testcontainers/images/OverrideImagePullPolicyTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,20 @@ public void simpleConfigurationTest() {
5151
container.stop();
5252
}
5353
}
54+
55+
@Test
56+
public void alwaysPullConfigurationTest() {
57+
Mockito
58+
.doReturn(AlwaysPullPolicy.class.getCanonicalName())
59+
.when(TestcontainersConfiguration.getInstance())
60+
.getImagePullPolicy();
61+
62+
try (DockerRegistryContainer registry = new DockerRegistryContainer()) {
63+
registry.start();
64+
GenericContainer<?> container = new GenericContainer<>(registry.createImage()).withExposedPorts(8080);
65+
container.start();
66+
assertThat(container.getImage().imagePullPolicy).isInstanceOf(AlwaysPullPolicy.class);
67+
container.stop();
68+
}
69+
}
5470
}

docs/features/advanced_options.md

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ You can also configure Testcontainers to use your custom implementation by using
3838
pull.policy=com.mycompany.testcontainers.ExampleImagePullPolicy
3939
```
4040

41+
You can also use the provided implementation to always pull images
42+
43+
=== "`src/test/resources/testcontainers.properties`"
44+
```text
45+
pull.policy=org.testcontainers.images.AlwaysPullPolicy
46+
```
47+
48+
4149
Please see [the documentation on configuration mechanisms](./configuration.md) for more information.
4250

4351
## Customizing the container

0 commit comments

Comments
 (0)