From 0393cc08b8697f729e3f9dd8b470e1b267006e5b Mon Sep 17 00:00:00 2001 From: Hector Ventura Date: Wed, 4 Nov 2026 00:38:42 -0600 Subject: [PATCH] fix(cli): keep an environment endpoint on the default port known to status status reported endpoint null and exited 1 for a healthy server when FLOCI_ENDPOINT equalled the product default, because its check ignored the environment while the published port was skipped in favour of it. Addresses the review of #75. Signed-off-by: Hector Ventura --- src/main/java/io/floci/cli/GlobalOptions.java | 3 ++- .../cli/unit/MissingInstanceEndpointTest.java | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/floci/cli/GlobalOptions.java b/src/main/java/io/floci/cli/GlobalOptions.java index f3a86fa..4393f2f 100644 --- a/src/main/java/io/floci/cli/GlobalOptions.java +++ b/src/main/java/io/floci/cli/GlobalOptions.java @@ -168,7 +168,8 @@ public class GlobalOptions { /** Whether a configured endpoint can identify this instance without a container lookup. */ public boolean canUseConfiguredEndpoint() { - return typed("--endpoint") || !product.defaultEndpoint().equals(endpoint) + return typed("--endpoint") || endpoint.equals(endpointFromEnv) + || !product.defaultEndpoint().equals(endpoint) || product.defaultContainer().equals(container); } diff --git a/src/test/java/io/floci/cli/unit/MissingInstanceEndpointTest.java b/src/test/java/io/floci/cli/unit/MissingInstanceEndpointTest.java index 1669773..95cf4d9 100644 --- a/src/test/java/io/floci/cli/unit/MissingInstanceEndpointTest.java +++ b/src/test/java/io/floci/cli/unit/MissingInstanceEndpointTest.java @@ -95,6 +95,25 @@ class MissingInstanceEndpointTest { assertEquals("http://localhost:9999", global.resolvedEndpoint(running)); } + @ParameterizedTest + @MethodSource("products") + void anEnvironmentEndpointOnTheDefaultPortIsStillAKnownEndpoint(ProductProfile product) { + GlobalOptions fromEnv = new GlobalOptions(product, + key -> key.equals(product.envVar("ENDPOINT")) ? product.defaultEndpoint() : null); + StatusCommand status = new StatusCommand(product, missing) { + { global = fromEnv; } + }; + PrintStream original = System.out; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try { + System.setOut(new PrintStream(out)); + new CommandLine(status).execute("--container", "other", "--json"); + } finally { + System.setOut(original); + } + assertTrue(out.toString().contains("\"endpoint\" : \"" + product.defaultEndpoint() + "\""), out.toString()); + } + @Test void aProfileEndpointOnAnotherHostBeatsALocalContainer() throws Exception { Files.writeString(temp.resolve("other.yaml"), "container: other\nendpoint: http://remote:9000\n");