-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to define a custom ImagePullPolicy via configuration (#7520)
Use `pull.policy` in configuration file.
- Loading branch information
1 parent
c4d1240
commit 8b6776c
Showing
6 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
46 changes: 44 additions & 2 deletions
46
core/src/main/java/org/testcontainers/images/PullPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
core/src/test/java/org/testcontainers/images/OverrideImagePullPolicyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.testcontainers.images; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
import org.testcontainers.DockerRegistryContainer; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.utility.FakeImagePullPolicy; | ||
import org.testcontainers.utility.MockTestcontainersConfigurationRule; | ||
import org.testcontainers.utility.TestcontainersConfiguration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class OverrideImagePullPolicyTest { | ||
|
||
@Rule | ||
public MockTestcontainersConfigurationRule config = new MockTestcontainersConfigurationRule(); | ||
|
||
private ImagePullPolicy originalInstance; | ||
|
||
private ImagePullPolicy originalDefaultImplementation; | ||
|
||
@Before | ||
public void setUp() { | ||
this.originalInstance = PullPolicy.instance; | ||
this.originalDefaultImplementation = PullPolicy.defaultImplementation; | ||
PullPolicy.instance = null; | ||
PullPolicy.defaultImplementation = Mockito.mock(ImagePullPolicy.class); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
PullPolicy.instance = originalInstance; | ||
PullPolicy.defaultImplementation = originalDefaultImplementation; | ||
} | ||
|
||
@Test | ||
public void simpleConfigurationTest() { | ||
Mockito | ||
.doReturn(FakeImagePullPolicy.class.getCanonicalName()) | ||
.when(TestcontainersConfiguration.getInstance()) | ||
.getImagePullPolicy(); | ||
|
||
try (DockerRegistryContainer registry = new DockerRegistryContainer()) { | ||
registry.start(); | ||
GenericContainer<?> container = new GenericContainer<>(registry.createImage()).withExposedPorts(8080); | ||
container.start(); | ||
assertThat(container.getImage().imagePullPolicy).isInstanceOf(FakeImagePullPolicy.class); | ||
container.stop(); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
core/src/test/java/org/testcontainers/utility/FakeImagePullPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.testcontainers.utility; | ||
|
||
import org.testcontainers.images.AbstractImagePullPolicy; | ||
import org.testcontainers.images.ImageData; | ||
|
||
public class FakeImagePullPolicy extends AbstractImagePullPolicy { | ||
|
||
@Override | ||
protected boolean shouldPullCached(DockerImageName imageName, ImageData localImageData) { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters