mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-25 06:47:41 -05:00
feat(start): give each instance its own Docker resource namespace and base URL (#31)
This commit is contained in:
1 parent
788eb470fb
commit
bf9ee4037b
14 files changed
+310
-8
No files matched your search
@@ -7,7 +7,9 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import picocli.CommandLine.ParseResult;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
@@ -54,6 +56,8 @@ class StartCommandArgsTest {
|
||||
"-v", "/tmp/floci-persist-test:/app/data",
|
||||
"-e", "FLOCI_STORAGE_MODE=persistent",
|
||||
"-e", "FLOCI_SERVICES=s3,lambda",
|
||||
"-e", "FLOCI_BASE_URL=http://localhost:4599",
|
||||
"-e", "FLOCI_DOCKER_RESOURCE_NAMESPACE=probe",
|
||||
"floci/floci:enforced"),
|
||||
parse("start", "--profile", "probe").dockerRunArgs(SOCKET));
|
||||
}
|
||||
@@ -107,6 +111,86 @@ class StartCommandArgsTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Two instances of one emulator must not share a resource namespace, or each one's startup
|
||||
* sweep removes the other's Lambda/ECS/Cloud Run children. The default instance passes none,
|
||||
* so its child container names stay what they were.
|
||||
*/
|
||||
@Test
|
||||
void theDefaultContainerPassesNoResourceNamespace() {
|
||||
for (String tree : new String[]{"aws", "gcp", "az", "oci"}) {
|
||||
assertFalse(parse(tree, "start").dockerRunArgs(SOCKET).stream()
|
||||
.anyMatch(a -> a.contains("RESOURCE_NAMESPACE")), tree);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aNonDefaultContainerNamesItsOwnNamespaceInEveryTree() {
|
||||
// The emulator prefixes child names with floci-<cloud>- itself, so the default-container
|
||||
// prefix is dropped: floci-gcp-b -> b, not floci-gcp-floci-gcp-b-...
|
||||
assertTrue(parse("start", "--container", "floci-b").dockerRunArgs(SOCKET)
|
||||
.contains("FLOCI_DOCKER_RESOURCE_NAMESPACE=b"));
|
||||
assertTrue(parse("gcp", "start", "--container", "floci-gcp-b").dockerRunArgs(SOCKET)
|
||||
.contains("FLOCI_GCP_DOCKER_RESOURCE_NAMESPACE=b"));
|
||||
assertTrue(parse("az", "start", "--container", "floci-az-b").dockerRunArgs(SOCKET)
|
||||
.contains("FLOCI_AZ_DOCKER_RESOURCE_NAMESPACE=b"));
|
||||
assertTrue(parse("oci", "start", "--container", "team-oci").dockerRunArgs(SOCKET)
|
||||
.contains("FLOCI_OCI_DOCKER_RESOURCE_NAMESPACE=team-oci"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anExplicitNamespaceBeatsTheContainerName() {
|
||||
assertTrue(parse("start", "--container", "floci-b", "--namespace", "team-b")
|
||||
.dockerRunArgs(SOCKET).contains("FLOCI_DOCKER_RESOURCE_NAMESPACE=team-b"));
|
||||
assertTrue(parse("start", "--namespace", "team-a")
|
||||
.dockerRunArgs(SOCKET).contains("FLOCI_DOCKER_RESOURCE_NAMESPACE=team-a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theProfileNamespaceAppliesAndTheFlagStillWins() throws Exception {
|
||||
writeProfile("probe", "container: floci-probe\nnamespace: from-profile\n");
|
||||
assertTrue(parse("start", "--container", "floci-probe", "--namespace", "floci-probe")
|
||||
.dockerRunArgs(SOCKET).contains("FLOCI_DOCKER_RESOURCE_NAMESPACE=floci-probe"),
|
||||
"an explicit namespace is passed verbatim");
|
||||
|
||||
assertTrue(parse("start", "--profile", "probe").dockerRunArgs(SOCKET)
|
||||
.contains("FLOCI_DOCKER_RESOURCE_NAMESPACE=from-profile"));
|
||||
assertTrue(parse("start", "--profile", "probe", "--namespace", "from-flag").dockerRunArgs(SOCKET)
|
||||
.contains("FLOCI_DOCKER_RESOURCE_NAMESPACE=from-flag"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInvalidNamespaceIsRejectedBeforeDockerIsTouched() {
|
||||
StartCommand start = parse("start", "--namespace", "bad/name");
|
||||
PrintStream err = System.err;
|
||||
System.setErr(new PrintStream(new ByteArrayOutputStream()));
|
||||
try {
|
||||
assertEquals(2, start.call());
|
||||
} finally {
|
||||
System.setErr(err);
|
||||
}
|
||||
}
|
||||
|
||||
/** Response URLs (SQS QueueUrl, OCI invoke endpoint) must name the port this instance owns. */
|
||||
@Test
|
||||
void aNonDefaultPortMovesTheBaseUrlWithIt() {
|
||||
assertTrue(parse("start", "--port", "14566").dockerRunArgs(SOCKET)
|
||||
.contains("FLOCI_BASE_URL=http://localhost:14566"));
|
||||
assertTrue(parse("oci", "start", "--port", "14599").dockerRunArgs(SOCKET)
|
||||
.contains("FLOCI_OCI_BASE_URL=http://localhost:14599"));
|
||||
for (String tree : new String[]{"aws", "gcp", "az", "oci"}) {
|
||||
assertFalse(parse(tree, "start").dockerRunArgs(SOCKET).stream()
|
||||
.anyMatch(a -> a.contains("BASE_URL")), tree);
|
||||
}
|
||||
}
|
||||
|
||||
/** Returned URLs must reach the emulator, so a remote endpoint's host is kept. */
|
||||
@Test
|
||||
void theBaseUrlKeepsTheEndpointsHost() {
|
||||
assertTrue(parse("start", "--endpoint", "http://floci.internal:4566", "--port", "14566")
|
||||
.dockerRunArgs(SOCKET).contains("FLOCI_BASE_URL=http://floci.internal:14566"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void readinessPollKeepsTheHostFromTheEndpointWhenSwappingThePort() {
|
||||
assertEquals("http://floci.internal:4599", StartCommand.withPort("http://floci.internal:4566", 4599));
|
||||
|
||||
Reference in new issue
Block a user