mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-23 14:10:50 -05:00
fix(doctor): fail -o json on a failed check and name each product in its hints
doctor -o json now exits 1 when a check fails, as text output does; hints and HTTP errors name the product's own command (floci gcp start, ...) and the port check falls back to the product's default port; a warnings-only run no longer reads as '0 issue(s) found'; an https AWS_ENDPOINT_URL without a port means 443.
This commit is contained in:
20 files changed
+203
-33
No files matched your search
@@ -68,11 +68,11 @@ public class DoctorCommand implements Callable<Integer> {
|
||||
new DockerDaemonCheck(docker),
|
||||
new DockerSocketCheck(),
|
||||
new DockerVersionCheck(docker),
|
||||
new PortAvailableCheck(docker),
|
||||
new ImagePresentCheck(profile.image(), docker),
|
||||
new ImageVersionCheck(profile.image(), docker),
|
||||
new ContainerRunningCheck(docker),
|
||||
new EndpointReachableCheck(profile.controlPrefix())
|
||||
new PortAvailableCheck(docker, profile),
|
||||
new ImagePresentCheck(profile, docker),
|
||||
new ImageVersionCheck(profile, docker),
|
||||
new ContainerRunningCheck(docker, profile),
|
||||
new EndpointReachableCheck(profile)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -167,7 +167,8 @@ public class DoctorCommand implements Callable<Integer> {
|
||||
structured.add(m);
|
||||
}
|
||||
printer.structured(structured);
|
||||
return 0;
|
||||
// Same contract as text output: scripts read the exit code, whatever the format.
|
||||
return results.stream().anyMatch(r -> r.status() == CheckStatus.fail) ? 1 : 0;
|
||||
}
|
||||
|
||||
long fails = results.stream().filter(r -> r.status() == CheckStatus.fail).count();
|
||||
@@ -176,6 +177,9 @@ public class DoctorCommand implements Callable<Integer> {
|
||||
printer.println("");
|
||||
if (fails == 0 && warns == 0) {
|
||||
printer.println(Ansi.green("All checks passed."));
|
||||
} else if (fails == 0) {
|
||||
// Nothing failed: say so, rather than "0 issue(s) found" next to the warnings.
|
||||
printer.println(Ansi.green("No failures") + ", " + warns + " warning(s) to review.");
|
||||
} else {
|
||||
printer.println(fails + " issue(s) found (" + fails + " fail, " + warns + " warn)."
|
||||
+ (fix ? "" : " Run with --fix to auto-resolve fixable issues."));
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ServicesCommand implements Callable<Integer> {
|
||||
// Resolve the endpoint from the container's port mapping, like status/wait/env do,
|
||||
// so a container started with --port <n> is still found without --endpoint.
|
||||
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile);
|
||||
|
||||
List<String> services;
|
||||
try {
|
||||
|
||||
@@ -62,7 +62,7 @@ public class StatusCommand implements Callable<Integer> {
|
||||
String serverVersion = "unavailable";
|
||||
String serverEdition = "";
|
||||
boolean reachable = false;
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile);
|
||||
try {
|
||||
var health = client.health();
|
||||
serverVersion = health.version();
|
||||
|
||||
@@ -46,7 +46,7 @@ public class VersionCommand implements Callable<Integer> {
|
||||
var docker = new io.floci.cli.docker.DockerClient();
|
||||
String effectiveEndpoint = global.resolvedEndpoint(docker);
|
||||
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile);
|
||||
try {
|
||||
var info = client.info();
|
||||
serverVersion = info.version();
|
||||
|
||||
@@ -72,7 +72,7 @@ public class WaitCommand implements Callable<Integer> {
|
||||
// The deadline starts now, so the container lookup below counts against --timeout too.
|
||||
Instant deadline = Instant.now().plusMillis(timeoutMillis);
|
||||
String effectiveEndpoint = knownEndpoint != null ? knownEndpoint : endpointWithin(deadline);
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile);
|
||||
|
||||
// Poll soon after a start, then back off; never let a request or a pause run past the
|
||||
// deadline, so --timeout is a real upper bound.
|
||||
|
||||
@@ -73,7 +73,7 @@ public class AzEnvCommand implements Callable<Integer> {
|
||||
|
||||
public AzEnvCommand() {
|
||||
this(InstanceState.defaultRoot(),
|
||||
endpoint -> new FlociHttpClient(endpoint, ProductProfile.AZ.controlPrefix()).tlsCert());
|
||||
endpoint -> new FlociHttpClient(endpoint, ProductProfile.AZ).tlsCert());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -96,7 +96,7 @@ public class AzSetupCommand implements Callable<Integer> {
|
||||
|
||||
public AzSetupCommand() {
|
||||
this(InstanceState.defaultRoot(), new ProcessAzCli(),
|
||||
endpoint -> new FlociHttpClient(endpoint, ProductProfile.AZ.controlPrefix()).tlsCert(),
|
||||
endpoint -> new FlociHttpClient(endpoint, ProductProfile.AZ).tlsCert(),
|
||||
new DockerClient(), Duration.ofSeconds(2));
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class SnapshotDeleteCommand implements Callable<Integer> {
|
||||
// Resolve the endpoint from the container's port mapping, like status/services/wait do,
|
||||
// so a container started with --port <n> is still found without --endpoint.
|
||||
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile);
|
||||
try {
|
||||
client.deleteSnapshot(name);
|
||||
printer.println(Ansi.green("Snapshot deleted:") + " " + name);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SnapshotListCommand implements Callable<Integer> {
|
||||
// Resolve the endpoint from the container's port mapping, like status/services/wait do,
|
||||
// so a container started with --port <n> is still found without --endpoint.
|
||||
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile);
|
||||
try {
|
||||
var node = client.listSnapshots();
|
||||
if (printer.format() != OutputFormat.text) {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class SnapshotLoadCommand implements Callable<Integer> {
|
||||
// Resolve the endpoint from the container's port mapping, like status/services/wait do,
|
||||
// so a container started with --port <n> is still found without --endpoint.
|
||||
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile);
|
||||
try {
|
||||
client.loadSnapshot(name);
|
||||
printer.println(Ansi.green("Snapshot loaded:") + " " + name);
|
||||
|
||||
@@ -44,7 +44,7 @@ public class SnapshotSaveCommand implements Callable<Integer> {
|
||||
// Resolve the endpoint from the container's port mapping, like status/services/wait do,
|
||||
// so a container started with --port <n> is still found without --endpoint.
|
||||
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile.controlPrefix());
|
||||
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile);
|
||||
try {
|
||||
client.postSnapshot(name);
|
||||
printer.println(Ansi.green("Snapshot saved:") + " " + name);
|
||||
|
||||
@@ -37,10 +37,13 @@ public class AwsCliEndpointCheck implements Check {
|
||||
ShellExport.formatExport("bash", "AWS_ENDPOINT_URL", suggested));
|
||||
}
|
||||
|
||||
private int extractPort(String url) {
|
||||
/** The URL's port, or the scheme default (443 for https, 80 otherwise); -1 if unparseable. */
|
||||
public static int extractPort(String url) {
|
||||
try {
|
||||
int port = URI.create(url).getPort();
|
||||
return port == -1 ? 80 : port;
|
||||
URI uri = URI.create(url);
|
||||
int port = uri.getPort();
|
||||
if (port != -1) return port;
|
||||
return "https".equalsIgnoreCase(uri.getScheme()) ? 443 : 80;
|
||||
} catch (Exception e) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.cli.doctor.checks;
|
||||
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.doctor.Check;
|
||||
@@ -15,9 +16,19 @@ public class ContainerRunningCheck implements Check {
|
||||
|
||||
/** {@code docker} is shared across one doctor run so each docker fact is fetched once. */
|
||||
public ContainerRunningCheck(DockerClient docker) {
|
||||
this.docker = docker;
|
||||
this(docker, ProductProfile.AWS);
|
||||
}
|
||||
|
||||
/** Hints name {@code product}'s tree ({@code floci gcp start}, ...). */
|
||||
public ContainerRunningCheck(DockerClient docker, ProductProfile product) {
|
||||
this.docker = docker;
|
||||
this.start = product.commandPrefix() + " start";
|
||||
this.stop = product.commandPrefix() + " stop";
|
||||
}
|
||||
|
||||
private final String start;
|
||||
private final String stop;
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "container.running";
|
||||
@@ -30,7 +41,7 @@ public class ContainerRunningCheck implements Check {
|
||||
if (info.isEmpty()) {
|
||||
return CheckResult.warn("container.running",
|
||||
"Container '" + container + "' not found",
|
||||
"floci start");
|
||||
start);
|
||||
}
|
||||
String state = info.get().state();
|
||||
if ("running".equals(state)) {
|
||||
@@ -38,7 +49,7 @@ public class ContainerRunningCheck implements Check {
|
||||
}
|
||||
return CheckResult.fail("container.running",
|
||||
"Container '" + container + "' exists but state is '" + state + "'",
|
||||
"floci start (or 'floci stop && floci start' to restart)");
|
||||
start + " (or '" + stop + " && " + start + "' to restart)");
|
||||
} catch (DockerException e) {
|
||||
return CheckResult.warn("container.running", "Could not inspect container: " + e.getMessage(), null);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.cli.doctor.checks;
|
||||
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.doctor.Check;
|
||||
import io.floci.cli.doctor.CheckResult;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
@@ -14,13 +15,24 @@ public class EndpointReachableCheck implements Check {
|
||||
}
|
||||
|
||||
private final String controlPrefix;
|
||||
private final String commandPrefix;
|
||||
|
||||
public EndpointReachableCheck() {
|
||||
this(FlociHttpClient.DEFAULT_CONTROL_PREFIX);
|
||||
}
|
||||
|
||||
public EndpointReachableCheck(String controlPrefix) {
|
||||
this(controlPrefix, "floci");
|
||||
}
|
||||
|
||||
/** {@code product}'s health endpoint, with a hint that names its tree. */
|
||||
public EndpointReachableCheck(ProductProfile product) {
|
||||
this(product.controlPrefix(), product.commandPrefix());
|
||||
}
|
||||
|
||||
private EndpointReachableCheck(String controlPrefix, String commandPrefix) {
|
||||
this.controlPrefix = controlPrefix;
|
||||
this.commandPrefix = commandPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,6 +51,6 @@ public class EndpointReachableCheck implements Check {
|
||||
}
|
||||
return CheckResult.fail("endpoint.reachable",
|
||||
"GET " + controlPrefix + "/health at " + endpoint + " did not return 200",
|
||||
"Is Floci running? Try 'floci start'.");
|
||||
"Is Floci running? Try '" + commandPrefix + " start'.");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.cli.doctor.checks;
|
||||
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.doctor.Check;
|
||||
@@ -25,10 +26,22 @@ public class ImagePresentCheck implements Check {
|
||||
|
||||
/** {@code docker} is shared across one doctor run so each docker fact is fetched once. */
|
||||
public ImagePresentCheck(String image, DockerClient docker) {
|
||||
this(image, docker, "floci");
|
||||
}
|
||||
|
||||
/** {@code product}'s image, with hints that name its tree. */
|
||||
public ImagePresentCheck(ProductProfile product, DockerClient docker) {
|
||||
this(product.image(), docker, product.commandPrefix());
|
||||
}
|
||||
|
||||
private ImagePresentCheck(String image, DockerClient docker, String commandPrefix) {
|
||||
this.image = image;
|
||||
this.docker = docker;
|
||||
this.pullHint = commandPrefix + " start --pull always";
|
||||
}
|
||||
|
||||
private final String pullHint;
|
||||
|
||||
@Override
|
||||
public CheckResult run(String endpoint, String container) {
|
||||
try {
|
||||
@@ -37,7 +50,7 @@ public class ImagePresentCheck implements Check {
|
||||
}
|
||||
return CheckResult.fail("image.present",
|
||||
image + " not pulled locally",
|
||||
"floci start --pull always");
|
||||
pullHint);
|
||||
} catch (DockerException e) {
|
||||
return CheckResult.warn("image.present", "Could not check image presence: " + e.getMessage(), null);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.cli.doctor.checks;
|
||||
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.doctor.Check;
|
||||
@@ -26,16 +27,28 @@ public class ImageVersionCheck implements Check {
|
||||
|
||||
/** {@code docker} is shared across one doctor run so each docker fact is fetched once. */
|
||||
public ImageVersionCheck(String image, DockerClient docker) {
|
||||
this(image, docker, "floci");
|
||||
}
|
||||
|
||||
/** {@code product}'s image, with hints that name its tree. */
|
||||
public ImageVersionCheck(ProductProfile product, DockerClient docker) {
|
||||
this(product.image(), docker, product.commandPrefix());
|
||||
}
|
||||
|
||||
private ImageVersionCheck(String image, DockerClient docker, String commandPrefix) {
|
||||
this.image = image;
|
||||
this.docker = docker;
|
||||
this.pullHint = commandPrefix + " start --pull always";
|
||||
}
|
||||
|
||||
private final String pullHint;
|
||||
|
||||
@Override
|
||||
public CheckResult run(String endpoint, String container) {
|
||||
try {
|
||||
if (!docker.isImagePresent(image)) {
|
||||
return CheckResult.warn("image.version", image + " not present — version cannot be checked",
|
||||
"floci start --pull always");
|
||||
pullHint);
|
||||
}
|
||||
// Try reading version label from the image
|
||||
String version = readImageLabel(docker, image);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.cli.doctor.checks;
|
||||
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.doctor.Check;
|
||||
@@ -19,9 +20,19 @@ public class PortAvailableCheck implements Check {
|
||||
|
||||
/** {@code docker} is shared across one doctor run so each docker fact is fetched once. */
|
||||
public PortAvailableCheck(DockerClient docker) {
|
||||
this.docker = docker;
|
||||
this(docker, ProductProfile.AWS);
|
||||
}
|
||||
|
||||
/** Falls back to {@code product}'s default port and names its tree in the hint. */
|
||||
public PortAvailableCheck(DockerClient docker, ProductProfile product) {
|
||||
this.docker = docker;
|
||||
this.defaultPort = product.defaultPort();
|
||||
this.startCommand = product.commandPrefix() + " start";
|
||||
}
|
||||
|
||||
private final int defaultPort;
|
||||
private final String startCommand;
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "port.available";
|
||||
@@ -29,7 +40,7 @@ public class PortAvailableCheck implements Check {
|
||||
|
||||
@Override
|
||||
public CheckResult run(String endpoint, String container) {
|
||||
int port = extractPort(endpoint);
|
||||
int port = extractPort(endpoint, defaultPort);
|
||||
// If a Floci container is already listening on the port, that's fine
|
||||
try {
|
||||
var info = docker.inspectContainer(container);
|
||||
@@ -43,7 +54,7 @@ public class PortAvailableCheck implements Check {
|
||||
}
|
||||
return CheckResult.fail("port.available",
|
||||
"Port " + port + " is occupied by another process",
|
||||
"Run 'lsof -i :" + port + "' to identify the process, or start Floci with --port <other>");
|
||||
"Run 'lsof -i :" + port + "' to identify the process, or '" + startCommand + " --port <other>'.");
|
||||
}
|
||||
|
||||
private static boolean isPortFree(int port) {
|
||||
@@ -55,11 +66,16 @@ public class PortAvailableCheck implements Check {
|
||||
}
|
||||
|
||||
public static int extractPort(String endpoint) {
|
||||
return extractPort(endpoint, ProductProfile.AWS.defaultPort());
|
||||
}
|
||||
|
||||
/** The endpoint's port, or {@code fallback} when it names none or cannot be parsed. */
|
||||
public static int extractPort(String endpoint, int fallback) {
|
||||
try {
|
||||
int port = URI.create(endpoint).getPort();
|
||||
return port > 0 ? port : 4566;
|
||||
return port > 0 ? port : fallback;
|
||||
} catch (Exception e) {
|
||||
return 4566;
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package io.floci.cli.http;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.floci.cli.ProductProfile;
|
||||
|
||||
import java.net.ConnectException;
|
||||
import java.net.URI;
|
||||
@@ -28,6 +29,7 @@ public class FlociHttpClient {
|
||||
private final String endpoint;
|
||||
private final String query;
|
||||
private final String controlPrefix;
|
||||
private final String commandPrefix;
|
||||
private final HttpClient http;
|
||||
|
||||
public FlociHttpClient(String endpoint) {
|
||||
@@ -39,6 +41,16 @@ public class FlociHttpClient {
|
||||
* (e.g. {@code /_floci} for AWS/Azure, {@code /_floci-gcp} for GCP).
|
||||
*/
|
||||
public FlociHttpClient(String endpoint, String controlPrefix) {
|
||||
this(endpoint, controlPrefix, "floci");
|
||||
}
|
||||
|
||||
/** A client for {@code product}'s emulator: its control prefix, and hints that name its tree. */
|
||||
public FlociHttpClient(String endpoint, ProductProfile product) {
|
||||
this(endpoint, product.controlPrefix(), product.commandPrefix());
|
||||
}
|
||||
|
||||
private FlociHttpClient(String endpoint, String controlPrefix, String commandPrefix) {
|
||||
this.commandPrefix = commandPrefix;
|
||||
// Request paths go before an endpoint's query: http://h:1/?x=1 + /health is http://h:1/health?x=1.
|
||||
// A fragment is never sent, so it is dropped.
|
||||
int fragment = endpoint.indexOf('#');
|
||||
@@ -152,7 +164,7 @@ public class FlociHttpClient {
|
||||
} catch (FlociException e) {
|
||||
throw e;
|
||||
} catch (ConnectException e) {
|
||||
throw new FlociException("Connection refused at " + endpoint + ". Is Floci running? Try 'floci status' or 'floci start'.");
|
||||
throw new FlociException("Connection refused at " + endpoint + ". Is Floci running? Try '" + commandPrefix + " status' or '" + commandPrefix + " start'.");
|
||||
} catch (Exception e) {
|
||||
throw new FlociException("Request failed: " + e.getMessage());
|
||||
}
|
||||
@@ -210,7 +222,7 @@ public class FlociHttpClient {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new FlociException("Request interrupted.\nRe-run the command.");
|
||||
} catch (ConnectException e) {
|
||||
throw new FlociException("Connection refused at " + endpoint + ". Is Floci running? Try 'floci status' or 'floci start'.");
|
||||
throw new FlociException("Connection refused at " + endpoint + ". Is Floci running? Try '" + commandPrefix + " status' or '" + commandPrefix + " start'.");
|
||||
} catch (Exception e) {
|
||||
throw new FlociException("Request failed: " + e.getMessage());
|
||||
}
|
||||
@@ -234,7 +246,7 @@ public class FlociHttpClient {
|
||||
} catch (FlociException e) {
|
||||
throw e;
|
||||
} catch (ConnectException e) {
|
||||
throw new FlociException("Connection refused at " + endpoint + ". Is Floci running? Try 'floci start'.");
|
||||
throw new FlociException("Connection refused at " + endpoint + ". Is Floci running? Try '" + commandPrefix + " start'.");
|
||||
} catch (Exception e) {
|
||||
throw new FlociException("Request failed: " + e.getMessage());
|
||||
}
|
||||
|
||||
@@ -192,4 +192,27 @@ class DoctorCommandTest {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
/** BL-036: -o json reports a failed check through the exit code, as text output does. */
|
||||
@Test
|
||||
void jsonOutputExitsOneWhenACheckFails() {
|
||||
Named failing = new Named("bad.check", (e, c) -> CheckResult.fail("bad.check", "broken", "fix it"));
|
||||
|
||||
Run r = doctor(List.of(ok("a.check"), failing), "-o", "json");
|
||||
|
||||
assertEquals(1, r.exit(), r.out());
|
||||
assertTrue(r.out().contains("\"bad.check\""), r.out());
|
||||
}
|
||||
|
||||
/** BL-038: warnings alone are not reported as "0 issue(s) found". */
|
||||
@Test
|
||||
void warningsOnlyDoNotReadAsZeroIssues() {
|
||||
Named warning = new Named("warn.check", (e, c) -> CheckResult.warn("warn.check", "hmm", null));
|
||||
|
||||
Run r = doctor(List.of(ok("a.check"), warning));
|
||||
|
||||
assertEquals(0, r.exit());
|
||||
assertFalse(r.out().contains("0 issue(s)"), r.out());
|
||||
assertTrue(r.out().contains("1 warning(s) to review"), r.out());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package io.floci.cli.unit;
|
||||
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.doctor.CheckResult;
|
||||
import io.floci.cli.doctor.checks.AwsCliEndpointCheck;
|
||||
import io.floci.cli.doctor.checks.ContainerRunningCheck;
|
||||
import io.floci.cli.doctor.checks.EndpointReachableCheck;
|
||||
import io.floci.cli.doctor.checks.PortAvailableCheck;
|
||||
import io.floci.cli.http.FlociException;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** BL-037/BL-038: doctor's hints and fallbacks belong to the product being diagnosed. */
|
||||
class DoctorHintsTest {
|
||||
|
||||
private static final DockerClient NO_CONTAINER = new DockerClient() {
|
||||
@Override
|
||||
public Optional<ContainerInfo> inspectContainer(String name) {
|
||||
return Optional.empty();
|
||||
}
|
||||
};
|
||||
|
||||
@Test
|
||||
void containerHintNamesTheProductTree() {
|
||||
CheckResult r = new ContainerRunningCheck(NO_CONTAINER, ProductProfile.GCP).run("http://localhost:4588", "floci-gcp");
|
||||
|
||||
assertEquals("floci gcp start", r.fix());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointHintNamesTheProductTree() {
|
||||
// Port 9 refuses connections at once.
|
||||
CheckResult r = new EndpointReachableCheck(ProductProfile.OCI).run("http://127.0.0.1:9", "floci-oci");
|
||||
|
||||
assertTrue(r.fix().contains("floci oci start"), r.fix());
|
||||
}
|
||||
|
||||
@Test
|
||||
void portFallbackIsTheProductsDefaultPort() {
|
||||
assertEquals(4588, PortAvailableCheck.extractPort("not a url", ProductProfile.GCP.defaultPort()));
|
||||
assertEquals(4566, PortAvailableCheck.extractPort("not a url"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void httpClientErrorsNameTheProductTree() {
|
||||
FlociException e = assertThrows(FlociException.class,
|
||||
() -> new FlociHttpClient("http://127.0.0.1:9", ProductProfile.AZ).health());
|
||||
|
||||
assertTrue(e.getMessage().contains("floci az start"), e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void httpsWithoutAPortMeans443() {
|
||||
assertEquals(443, AwsCliEndpointCheck.extractPort("https://floci.example"));
|
||||
assertEquals(80, AwsCliEndpointCheck.extractPort("http://floci.example"));
|
||||
assertEquals(4566, AwsCliEndpointCheck.extractPort("https://floci.example:4566"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user