Search in sources :

Example 1 with ContainerState

use of org.testcontainers.containers.ContainerState in project testcontainers-java by testcontainers.

the class DockerComposePassthroughTest method testContainerInstanceProperties.

@Test
public void testContainerInstanceProperties() {
    final ContainerState container = waitStrategy.getContainer();
    // check environment variable was set
    assertThat("Environment variable set correctly", Arrays.asList(Objects.requireNonNull(container.getContainerInfo().getConfig().getEnv())), hasItem("bar=bar"));
    // check other container properties
    assertNotNull("Container id is not null", container.getContainerId());
    assertNotNull("Port mapped", container.getMappedPort(3000));
    assertThat("Exposed Ports", container.getExposedPorts(), hasItem(3000));
}
Also used : ContainerState(org.testcontainers.containers.ContainerState) Test(org.junit.Test)

Example 2 with ContainerState

use of org.testcontainers.containers.ContainerState in project testcontainers-java by testcontainers.

the class AuthenticatedImagePullTest method testThatAuthLocatorIsUsedForDockerComposePull.

@Test
public void testThatAuthLocatorIsUsedForDockerComposePull() throws IOException {
    // Prepare a simple temporary Docker Compose manifest which requires our custom private image
    Path tempFile = getLocalTempFile(".docker-compose.yml");
    @Language("yaml") String composeFileContent = "version: '2.0'\n" + "services:\n" + "  privateservice:\n" + "      command: /bin/sh -c 'sleep 60'\n" + "      image: " + testImageName.asCanonicalNameString();
    Files.write(tempFile, composeFileContent.getBytes());
    // Start the docker compose project, which will require an authenticated pull
    try (final DockerComposeContainer<?> compose = new DockerComposeContainer<>(tempFile.toFile())) {
        compose.start();
        assertTrue("container started following an authenticated pull", compose.getContainerByServiceName("privateservice_1").map(ContainerState::isRunning).orElse(false));
    }
}
Also used : Path(java.nio.file.Path) Language(org.intellij.lang.annotations.Language) DockerComposeContainer(org.testcontainers.containers.DockerComposeContainer) ContainerState(org.testcontainers.containers.ContainerState) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ContainerState (org.testcontainers.containers.ContainerState)2 Path (java.nio.file.Path)1 Language (org.intellij.lang.annotations.Language)1 DockerComposeContainer (org.testcontainers.containers.DockerComposeContainer)1