mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-22 21:50:47 -05:00
test: add an opt-in integration suite against the real emulator images (#44)
mvn test -Pintegration drives start, wait, status, env and stop for all four products through the CLI's own command tree, plus two AWS instances side by side, each container uniquely named on a free port and removed afterwards. Tests tagged integration are excluded from the default build. A new Integration workflow runs the suite on main, weekly and on demand.
This commit is contained in:
1 parent
a813a23785
commit
030d468fd3
4 files changed
+193
No files matched your search
@@ -0,0 +1,38 @@
|
||||
name: Integration
|
||||
|
||||
# Drives the CLI against the real emulator images (start, wait, status, env, stop for each product,
|
||||
# and two instances side by side). It pulls four images, so it runs on main and on demand rather
|
||||
# than on every pull request.
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
schedule:
|
||||
- cron: '0 6 * * 1'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
integration:
|
||||
name: CLI against the emulator images
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '25'
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
|
||||
- name: Pull emulator images
|
||||
run: |
|
||||
for image in floci/floci floci/floci-gcp floci/floci-az floci/floci-oci; do
|
||||
docker pull "$image:latest"
|
||||
done
|
||||
|
||||
- name: Run integration tests
|
||||
run: mvn test -Pintegration -B
|
||||
@@ -23,6 +23,7 @@ mvn compile # compile only
|
||||
mvn test # run all unit tests
|
||||
mvn test -Dtest=WaitCommandParseTest # run a single test class
|
||||
mvn test -Dtest=DockerVersionCheckTest#testVersionParsing # run a single test method
|
||||
mvn test -Pintegration # integration suite: the CLI against real emulator images (needs Docker)
|
||||
mvn package # compile + test + produce target/floci.jar (fat JAR)
|
||||
mvn package -DskipTests # skip tests
|
||||
mvn package -Pnative -DskipTests # build native binary → target/floci (requires GraalVM)
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
<jackson.version>2.18.3</jackson.version>
|
||||
<junit.version>5.11.4</junit.version>
|
||||
<main.class>io.floci.cli.FlociCli</main.class>
|
||||
<floci.test.groups></floci.test.groups>
|
||||
<floci.test.excludedGroups>integration</floci.test.excludedGroups>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -96,6 +98,12 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.5</version>
|
||||
<configuration>
|
||||
<!-- Tests tagged "integration" need Docker and the emulator images; they run
|
||||
only with -Pintegration. -->
|
||||
<groups>${floci.test.groups}</groups>
|
||||
<excludedGroups>${floci.test.excludedGroups}</excludedGroups>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Fat JAR — JVM fallback when native binary is unavailable -->
|
||||
@@ -126,6 +134,13 @@
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>integration</id>
|
||||
<properties>
|
||||
<floci.test.groups>integration</floci.test.groups>
|
||||
<floci.test.excludedGroups>none</floci.test.excludedGroups>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>native</id>
|
||||
<activation>
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
package io.floci.cli.integration;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.floci.cli.FlociCli;
|
||||
import io.floci.cli.config.ProfileStore;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* BL-075: the CLI against the real emulator images, through the same command tree a user runs.
|
||||
* Opt-in (needs Docker and the images): {@code mvn test -Pintegration}.
|
||||
*
|
||||
* <p>Every container gets a unique name and a free host port, so the suite never touches a
|
||||
* developer's own instances, and each test removes what it started.
|
||||
*/
|
||||
@Tag("integration")
|
||||
class EmulatorLifecycleIntegrationTest {
|
||||
|
||||
private static final ObjectMapper JSON = new ObjectMapper();
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
private final List<String> started = new ArrayList<>();
|
||||
|
||||
private record Run(int exit, String out, String err) {
|
||||
JsonNode json() {
|
||||
try {
|
||||
return JSON.readTree(out);
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError("not JSON: " + out + "\nstderr: " + err, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void removeWhatWasStarted() throws Exception {
|
||||
for (String container : started) {
|
||||
new ProcessBuilder("docker", "rm", "-f", "--", container)
|
||||
.redirectErrorStream(true)
|
||||
.redirectOutput(ProcessBuilder.Redirect.DISCARD)
|
||||
.start()
|
||||
.waitFor();
|
||||
}
|
||||
}
|
||||
|
||||
private Run floci(String... args) {
|
||||
PrintStream out = System.out;
|
||||
PrintStream err = System.err;
|
||||
ByteArrayOutputStream outBuf = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream errBuf = new ByteArrayOutputStream();
|
||||
System.setOut(new PrintStream(outBuf));
|
||||
System.setErr(new PrintStream(errBuf));
|
||||
try {
|
||||
int exit = FlociCli.buildCommandLine(new ProfileStore(tempDir)).execute(args);
|
||||
return new Run(exit, outBuf.toString(), errBuf.toString());
|
||||
} finally {
|
||||
System.setOut(out);
|
||||
System.setErr(err);
|
||||
}
|
||||
}
|
||||
|
||||
// The product's tree as args: AWS is the root tree.
|
||||
private static String[] cmd(String product, String... rest) {
|
||||
List<String> all = new ArrayList<>();
|
||||
if (!product.equals("aws")) all.add(product);
|
||||
all.addAll(List.of(rest));
|
||||
return all.toArray(String[]::new);
|
||||
}
|
||||
|
||||
private static int freePort() throws IOException {
|
||||
try (ServerSocket socket = new ServerSocket(0)) {
|
||||
return socket.getLocalPort();
|
||||
}
|
||||
}
|
||||
|
||||
private String startInstance(String product, String defaultContainer, int port) {
|
||||
String container = defaultContainer + "-it" + UUID.randomUUID().toString().substring(0, 6);
|
||||
started.add(container);
|
||||
Run start = floci(cmd(product, "start", "--container", container, "--port", String.valueOf(port), "--detach"));
|
||||
assertEquals(0, start.exit(), "start " + container + ": " + start.err());
|
||||
Run wait = floci(cmd(product, "wait", "--container", container, "--timeout", "120s"));
|
||||
assertEquals(0, wait.exit(), "wait " + container + ": " + wait.err());
|
||||
return container;
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@CsvSource({"aws, floci", "gcp, floci-gcp", "az, floci-az", "oci, floci-oci"})
|
||||
void startWaitStatusEnvStop(String product, String defaultContainer) throws Exception {
|
||||
int port = freePort();
|
||||
String container = startInstance(product, defaultContainer, port);
|
||||
|
||||
JsonNode status = floci(cmd(product, "status", "--container", container, "-o", "json")).json();
|
||||
assertEquals("running", status.path("state").asText(), status.toString());
|
||||
assertTrue(status.path("reachable").asBoolean(), status.toString());
|
||||
assertTrue(status.path("endpoint").asText().endsWith(":" + port), status.toString());
|
||||
|
||||
Run env = floci(cmd(product, "env", "--container", container, "-o", "json"));
|
||||
assertEquals(0, env.exit(), env.err());
|
||||
assertTrue(env.out().contains(String.valueOf(port)), "env names the instance's port: " + env.out());
|
||||
|
||||
Run stop = floci(cmd(product, "stop", "--container", container, "--remove"));
|
||||
assertEquals(0, stop.exit(), stop.err());
|
||||
JsonNode after = floci(cmd(product, "status", "--container", container, "-o", "json")).json();
|
||||
assertNotEquals("running", after.path("state").asText(), after.toString());
|
||||
}
|
||||
|
||||
/** Two instances of one product side by side: each is found by its container, on its own port. */
|
||||
@Test
|
||||
void twoInstancesRunSideBySide() throws Exception {
|
||||
int portA = freePort();
|
||||
String a = startInstance("aws", "floci", portA);
|
||||
int portB = freePort();
|
||||
String b = startInstance("aws", "floci", portB);
|
||||
|
||||
assertTrue(floci("status", "--container", a, "-o", "json").json().path("endpoint").asText().endsWith(":" + portA));
|
||||
assertTrue(floci("status", "--container", b, "-o", "json").json().path("endpoint").asText().endsWith(":" + portB));
|
||||
|
||||
assertEquals(0, floci("stop", "--container", a, "--remove").exit());
|
||||
JsonNode still = floci("status", "--container", b, "-o", "json").json();
|
||||
assertTrue(still.path("reachable").asBoolean(), "stopping one instance leaves the other up: " + still);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user