mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
77 lines
2.4 KiB
Java
77 lines
2.4 KiB
Java
package io.floci.aws.services.batch;
|
|
|
|
import com.github.dockerjava.api.DockerClient;
|
|
import io.floci.aws.config.EmulatorConfig;
|
|
import io.floci.aws.core.common.dns.EmbeddedDnsServer;
|
|
import io.floci.aws.core.common.docker.ContainerDetector;
|
|
import io.floci.aws.services.batch.model.BatchJob;
|
|
import io.floci.aws.services.batch.model.BatchRunResult;
|
|
import io.floci.aws.testing.TestImages;
|
|
import io.quarkus.test.junit.QuarkusTest;
|
|
import jakarta.inject.Inject;
|
|
import org.junit.jupiter.api.Assumptions;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.util.List;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
@QuarkusTest
|
|
class BatchDockerRunnerDockerIntegrationTest {
|
|
|
|
private static final String IMAGE = TestImages.BUSYBOX;
|
|
|
|
@Inject
|
|
BatchDockerRunner runner;
|
|
|
|
@Inject
|
|
DockerClient dockerClient;
|
|
|
|
@Inject
|
|
EmulatorConfig config;
|
|
|
|
@Inject
|
|
ContainerDetector containerDetector;
|
|
|
|
@BeforeEach
|
|
void requireDocker() {
|
|
Assumptions.assumeTrue(isDockerAvailable(), "Docker daemon must be available for Batch Docker runner tests");
|
|
}
|
|
|
|
@Test
|
|
void dockerRunnerInjectsContainerReachableEndpoint() {
|
|
String suffix = Long.toString(System.nanoTime(), 36);
|
|
String expectedHostname = containerDetector.isRunningInContainer()
|
|
? config.hostname().orElse(EmbeddedDnsServer.DEFAULT_SUFFIX)
|
|
: "host.docker.internal";
|
|
String expectedEndpoint = "http://" + expectedHostname + ":" + config.port();
|
|
|
|
BatchJob job = new BatchJob();
|
|
job.setJobId("docker-env-" + suffix);
|
|
job.setJobName("docker-env-" + suffix);
|
|
job.setJobDefinitionName("docker-env-test");
|
|
job.setJobQueueName("docker-env-test-queue");
|
|
job.setRegion(config.defaultRegion());
|
|
job.setContainerImage(IMAGE);
|
|
job.setResolvedCommand(List.of("sh", "-c", """
|
|
test "$AWS_ENDPOINT_URL" = "%s" &&
|
|
test "$FLOCI_ENDPOINT" = "%s" &&
|
|
test "$FLOCI_HOSTNAME" = "%s"
|
|
""".formatted(expectedEndpoint, expectedEndpoint, expectedHostname)));
|
|
|
|
BatchRunResult result = runner.run(job, 1, null);
|
|
|
|
assertEquals(0, result.exitCode(), result.reason());
|
|
}
|
|
|
|
private boolean isDockerAvailable() {
|
|
try {
|
|
dockerClient.pingCmd().exec();
|
|
return true;
|
|
} catch (Exception e) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|