mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-22 21:50:47 -05:00
fix(reset): require a configured container to be running and to agree with a configured endpoint
A container that a profile or FLOCI_CONTAINER supplies is selected even when it has the default name, so a missing or stopped one resets nothing instead of falling back to the endpoint. A configured container and endpoint must be the same server. For a remote Docker host the published port is on the daemon's machine, so the endpoint is compared with that host, and a remote container without an endpoint is not reset through localhost. Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
3 files changed
+225
-68
No files matched your search
@@ -724,12 +724,19 @@ It calls the emulator's `POST <prefix>/state/reset`. The AWS, GCP and OCI emulat
|
||||
server without it (currently floci-az) the command says reset is not available and exits 1. Without
|
||||
`--yes` and with no terminal to ask on, it exits 2.
|
||||
|
||||
Reset never guesses which server to wipe. An `--endpoint` you type is used as given. An endpoint
|
||||
that a profile or `FLOCI_ENDPOINT` supplies is used too, and a container that happens to run
|
||||
locally under the default name never takes its place: if that container is a different server
|
||||
than the endpoint, nothing is reset and you are asked to pass `--endpoint` or `--container`. A container you
|
||||
select (`--container`, a profile, or `FLOCI_CONTAINER`) has to be running: if it is missing or
|
||||
stopped, nothing is reset and the command exits 1 instead of falling back to the default instance.
|
||||
Reset never guesses which server to wipe:
|
||||
|
||||
- An `--endpoint` you type is used as given.
|
||||
- A container you select (`--container`, a profile's `container`, or `FLOCI_CONTAINER`) has to be
|
||||
running. If it is missing or stopped, nothing is reset.
|
||||
- An endpoint a profile or `FLOCI_ENDPOINT` supplies is used when no container is selected. A
|
||||
container that happens to run locally under the default name never takes its place.
|
||||
- When both a container and an endpoint are configured, they have to be the same server. If they
|
||||
are not, nothing is reset and you are asked to pass `--endpoint` or `--container`.
|
||||
- A container on a remote Docker host (`DOCKER_HOST=tcp://...` or `ssh://...`) is only reset
|
||||
through an endpoint, since its published port is not on this machine.
|
||||
|
||||
In each of those cases the command exits 1 without sending anything.
|
||||
|
||||
### `floci config`
|
||||
|
||||
@@ -939,7 +946,7 @@ Where a command's codes carry a specific meaning a script can rely on:
|
||||
| `update` | updated, or already up to date | the update failed, or `--version` is not a release version; the binary is unchanged | bad flag |
|
||||
| `start`, `restart` | started (and ready, unless `--detach`) | Docker, the image, the port or readiness failed | `--port`, `--pull` or the namespace is not valid |
|
||||
| `stop` | stopped, or was not running | no such container, or Docker failed | bad flag or profile |
|
||||
| `reset` | state reset | declined, not available on this server, or no running instance to reset | no terminal to ask on and no `--yes` |
|
||||
| `reset` | state reset | declined, not available on this server, no running instance to reset, or the configuration names two different servers | no terminal to ask on and no `--yes` |
|
||||
| `config validate` | no errors (warnings allowed) | errors found, or the file cannot be read | bad flag |
|
||||
| `config profile ...` | done | not found, already exists, cannot be read, `--port` is out of range, or (for `edit`) no editor is set, the editor failed or the file no longer parses | the profile name is not valid |
|
||||
| `config default-product` | saved | not `aws`, `gcp`, `az` or `oci`, or the file cannot be written | bad flag |
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.floci.cli.commands;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.ProductProfile;
|
||||
import io.floci.cli.config.ProfileDefaultValueProvider;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.http.FlociException;
|
||||
@@ -11,6 +12,7 @@ import io.floci.cli.output.Glyphs;
|
||||
import io.floci.cli.output.OutputFormat;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
import picocli.CommandLine.Model.CommandSpec;
|
||||
|
||||
import java.io.Console;
|
||||
import java.net.URI;
|
||||
@@ -19,6 +21,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
@Command(
|
||||
name = "reset",
|
||||
@@ -45,14 +48,24 @@ public class ResetCommand implements Callable<Integer> {
|
||||
|
||||
/** Test seam: {@code docker} answers the container lookup and {@code prompt} the confirmation. */
|
||||
public ResetCommand(ProductProfile profile, DockerClient docker, Prompt prompt) {
|
||||
this(profile, docker, prompt, System::getenv);
|
||||
}
|
||||
|
||||
/** Test seam: {@code env} answers whether {@code <PREFIX>_CONTAINER} selected the container. */
|
||||
public ResetCommand(ProductProfile profile, DockerClient docker, Prompt prompt, UnaryOperator<String> env) {
|
||||
this.profile = profile;
|
||||
this.global = new GlobalOptions(profile);
|
||||
this.global = new GlobalOptions(profile, env);
|
||||
this.docker = docker;
|
||||
this.prompt = prompt;
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
private final DockerClient docker;
|
||||
private final Prompt prompt;
|
||||
private final UnaryOperator<String> env;
|
||||
|
||||
@Spec
|
||||
CommandSpec spec;
|
||||
|
||||
/** The person at the terminal, when there is one. */
|
||||
public interface Prompt {
|
||||
@@ -84,23 +97,28 @@ public class ResetCommand implements Callable<Integer> {
|
||||
|
||||
/**
|
||||
* Where this reset acts. Reset deletes data, so unlike the read-only commands it never
|
||||
* guesses: an {@code --endpoint} the user typed is used as given, and a container the user
|
||||
* chose must be found running.
|
||||
*
|
||||
* <p>An endpoint that a profile or {@code <PREFIX>_ENDPOINT} supplies names a server just as
|
||||
* a typed one does, so with no container chosen it is not silently replaced by a container
|
||||
* that runs locally under the default name. But a profile carries a container name as well
|
||||
* (every created profile is seeded with the default one), so the two can point at different
|
||||
* servers. When they do, nothing is reset: the user has to say which one is meant. Only when
|
||||
* nothing at all was selected is the default container looked up, falling back to the
|
||||
* default endpoint, which names the same default instance.
|
||||
* guesses. In order:
|
||||
* <ol>
|
||||
* <li>A typed {@code --endpoint} is used as given.</li>
|
||||
* <li>A typed {@code --container} must be found running, and is reset.</li>
|
||||
* <li>A container that a profile or {@code <PREFIX>_CONTAINER} supplies must be found
|
||||
* running too. If the profile or environment also names an endpoint other than the
|
||||
* default, the two have to be the same server.</li>
|
||||
* <li>With no container supplied, an endpoint from a profile or the environment is used,
|
||||
* unless a container of the default name runs here and is a different server.</li>
|
||||
* <li>With nothing selected at all, the default container is looked up, falling back to
|
||||
* the default endpoint, which names the same default instance.</li>
|
||||
* </ol>
|
||||
* Whenever two things that were configured point at different servers, nothing is reset.
|
||||
*/
|
||||
public Target target() {
|
||||
if (global.typed("--endpoint")) return new Target(global.endpoint, null);
|
||||
boolean chosen = global.typed("--container") || !profile.defaultContainer().equals(global.container);
|
||||
if (!chosen && namesAServer(global.endpoint, profile)) return namedEndpoint();
|
||||
boolean typedContainer = global.typed("--container");
|
||||
boolean chosen = typedContainer || containerSupplied();
|
||||
boolean endpointNamed = namesAServer(global.endpoint, profile);
|
||||
String how = "\nRun '" + profile.commandPrefix() + " status" + global.instanceSelector()
|
||||
+ "' to check it, or pass --endpoint <url> to name the server to reset.";
|
||||
|
||||
Optional<DockerClient.ContainerInfo> info;
|
||||
try {
|
||||
info = docker.inspectContainer(global.container);
|
||||
@@ -108,61 +126,87 @@ public class ResetCommand implements Callable<Integer> {
|
||||
if (chosen) {
|
||||
return new Target(null, "Could not look up container '" + global.container + "': " + e.getMessage() + how);
|
||||
}
|
||||
info = Optional.empty();
|
||||
}
|
||||
if (info.isEmpty()) {
|
||||
return chosen
|
||||
? new Target(null, "Container '" + global.container + "' not found, so nothing was reset." + how)
|
||||
: new Target(global.endpoint, null);
|
||||
}
|
||||
if (chosen && !"running".equals(info.get().state())) {
|
||||
return new Target(null, "Container '" + global.container + "' is not running (state: "
|
||||
+ info.get().state() + "), so nothing was reset." + how);
|
||||
info = Optional.empty(); // nothing known to contradict what was configured
|
||||
}
|
||||
boolean running = info.isPresent() && "running".equals(info.get().state());
|
||||
// By the emulator's own port inside the container, which never changes; the configured
|
||||
// endpoint names the host port, and that differs on every instance but the default one.
|
||||
Optional<String> published = GlobalOptions.publishedEndpoint(info.get().ports(), profile.defaultPort());
|
||||
if (chosen && published.isEmpty()) {
|
||||
// No port to find it by: the configured endpoint may well be another instance.
|
||||
return new Target(null, "Container '" + global.container
|
||||
+ "' publishes no port for the emulator, so nothing was reset." + how);
|
||||
}
|
||||
return new Target(published.orElse(global.endpoint), null);
|
||||
}
|
||||
Optional<String> published = running
|
||||
? GlobalOptions.publishedEndpoint(info.get().ports(), profile.defaultPort())
|
||||
: Optional.empty();
|
||||
|
||||
// The configured endpoint names a server and the container name is only the default one. The
|
||||
// endpoint is used, unless a container of that name is running here and is a different
|
||||
// server: then the configuration is ambiguous, and a reset must not pick.
|
||||
private Target namedEndpoint() {
|
||||
Optional<String> local;
|
||||
try {
|
||||
local = docker.inspectContainer(global.container)
|
||||
.filter(info -> "running".equals(info.state()))
|
||||
.flatMap(info -> GlobalOptions.publishedEndpoint(info.ports(), profile.defaultPort()));
|
||||
} catch (DockerException e) {
|
||||
local = Optional.empty(); // nothing known to contradict the endpoint
|
||||
if (chosen) {
|
||||
if (info.isEmpty()) {
|
||||
return new Target(null, "Container '" + global.container + "' not found, so nothing was reset." + how);
|
||||
}
|
||||
if (!running) {
|
||||
return new Target(null, "Container '" + global.container + "' is not running (state: "
|
||||
+ info.get().state() + "), so nothing was reset." + how);
|
||||
}
|
||||
if (published.isEmpty()) {
|
||||
// No port to find it by: the configured endpoint may well be another instance.
|
||||
return new Target(null, "Container '" + global.container
|
||||
+ "' publishes no port for the emulator, so nothing was reset." + how);
|
||||
}
|
||||
}
|
||||
if (local.isEmpty() || sameLocalServer(local.get(), global.endpoint)) {
|
||||
if (published.isEmpty()) {
|
||||
// Nothing runs here under that name: the configured endpoint is all there is.
|
||||
return new Target(global.endpoint, null);
|
||||
}
|
||||
return new Target(null, "The configured endpoint is " + global.endpoint + ", but container '" + global.container
|
||||
+ "' is running at " + local.get() + ". They are different servers, so nothing was reset."
|
||||
+ "\nPass --endpoint <url> or --container <name> to say which one to reset.");
|
||||
|
||||
DockerClient.DockerHost daemon = docker.daemonHost();
|
||||
boolean remote = daemon.kind() == DockerClient.Kind.TCP;
|
||||
if (endpointNamed && !typedContainer) {
|
||||
// A container and an endpoint were both configured: they have to be one server.
|
||||
if (sameServer(published.get(), global.endpoint, daemon)) return new Target(global.endpoint, null);
|
||||
return new Target(null, "The configured endpoint is " + global.endpoint + ", but container '"
|
||||
+ global.container + "' is running at " + whereItRuns(published.get(), daemon)
|
||||
+ ". They are different servers, so nothing was reset."
|
||||
+ "\nPass --endpoint <url> or --container <name> to say which one to reset.");
|
||||
}
|
||||
if (remote) {
|
||||
// The port was published on the daemon's machine. 'localhost' here would be this
|
||||
// one, and whatever answers on that port here is not the container that was found.
|
||||
return new Target(null, "Container '" + global.container + "' runs on the remote Docker host "
|
||||
+ daemon.raw() + ", so its address is not known here and nothing was reset."
|
||||
+ "\nPass --endpoint <url> with the address the emulator is reached at.");
|
||||
}
|
||||
return new Target(published.get(), null);
|
||||
}
|
||||
|
||||
// Whether something other than the default name picked the container: a profile that sets
|
||||
// one (every created profile does), <PREFIX>_CONTAINER, or simply a different name.
|
||||
private boolean containerSupplied() {
|
||||
if (!profile.defaultContainer().equals(global.container)) return true;
|
||||
if (env.apply(profile.envVar("CONTAINER")) != null) return true;
|
||||
return global.profile != null
|
||||
&& ProfileDefaultValueProvider.of(spec).resolved().map(p -> p.container != null).orElse(false);
|
||||
}
|
||||
|
||||
private static String whereItRuns(String published, DockerClient.DockerHost daemon) {
|
||||
return daemon.kind() == DockerClient.Kind.TCP
|
||||
? "port " + URI.create(published).getPort() + " of the remote Docker host " + daemon.raw()
|
||||
: published;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether {@code configured} is the server a local container publishes at {@code published}
|
||||
* ({@code http://localhost:<port>}): the same port, on a host name that means this machine.
|
||||
* Whether {@code configured} is the server a container publishes at {@code published}
|
||||
* ({@code http://localhost:<port>} as docker reports it). The port has to match. For a local
|
||||
* daemon the configured host has to mean this machine; for a remote one it has to be the
|
||||
* daemon's host, since that is where the port was published.
|
||||
*/
|
||||
public static boolean sameLocalServer(String published, String configured) {
|
||||
public static boolean sameServer(String published, String configured, DockerClient.DockerHost daemon) {
|
||||
try {
|
||||
URI here = URI.create(published);
|
||||
URI there = URI.create(withoutTrailingSlashes(configured));
|
||||
if (URI.create(published).getPort() != there.getPort()) return false;
|
||||
String host = there.getHost() == null ? "" : there.getHost().toLowerCase(Locale.ROOT);
|
||||
boolean thisMachine = host.equals("localhost") || host.equals("127.0.0.1") || host.equals("[::1]")
|
||||
if (daemon.kind() == DockerClient.Kind.TCP) {
|
||||
String daemonHost = URI.create(daemon.raw()).getHost();
|
||||
return daemonHost != null && daemonHost.equalsIgnoreCase(host);
|
||||
}
|
||||
return host.equals("localhost") || host.equals("127.0.0.1") || host.equals("[::1]")
|
||||
|| host.equals("::1") || host.equals("0.0.0.0") || host.equals("localhost.floci.io");
|
||||
return thisMachine && here.getPort() == there.getPort();
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalArgumentException | NullPointerException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import io.floci.cli.commands.ResetCommand;
|
||||
import io.floci.cli.config.ProfileDefaultValueProvider;
|
||||
import io.floci.cli.config.ProfileStore;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerClient.DockerHost;
|
||||
import io.floci.cli.docker.DockerClient.Kind;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -27,6 +29,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -129,7 +132,14 @@ class ResetCommandTest {
|
||||
|
||||
// ---- which server a reset acts on -------------------------------------------------------
|
||||
|
||||
private static final DockerHost LOCAL = new DockerHost(Kind.UNIX, "/var/run/docker.sock", null);
|
||||
|
||||
private static DockerClient dockerWith(String name, String state, String ports) {
|
||||
return dockerWith(name, state, ports, LOCAL);
|
||||
}
|
||||
|
||||
/** A docker reached through {@code daemon} that holds one container. */
|
||||
private static DockerClient dockerWith(String name, String state, String ports, DockerHost daemon) {
|
||||
return new DockerClient() {
|
||||
@Override
|
||||
public Optional<ContainerInfo> inspectContainer(String asked) {
|
||||
@@ -137,6 +147,11 @@ class ResetCommandTest {
|
||||
? Optional.of(new ContainerInfo("abc", name, "floci/floci:latest", state, ports))
|
||||
: Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DockerHost daemonHost() {
|
||||
return daemon;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -232,12 +247,91 @@ class ResetCommandTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameLocalServerComparesPortAndWhetherTheHostIsThisMachine() {
|
||||
assertTrue(ResetCommand.sameLocalServer("http://localhost:4566", "http://127.0.0.1:4566"));
|
||||
assertTrue(ResetCommand.sameLocalServer("http://localhost:4566", "https://localhost:4566/"));
|
||||
assertFalse(ResetCommand.sameLocalServer("http://localhost:4566", "http://localhost:14566"));
|
||||
assertFalse(ResetCommand.sameLocalServer("http://localhost:4566", "http://remote-host:4566"));
|
||||
assertFalse(ResetCommand.sameLocalServer("http://localhost:4566", "not a url"));
|
||||
void forALocalDaemonTheSameServerIsTheSamePortOnThisMachine() {
|
||||
assertTrue(ResetCommand.sameServer("http://localhost:4566", "http://127.0.0.1:4566", LOCAL));
|
||||
assertTrue(ResetCommand.sameServer("http://localhost:4566", "https://localhost:4566/", LOCAL));
|
||||
assertFalse(ResetCommand.sameServer("http://localhost:4566", "http://localhost:14566", LOCAL));
|
||||
assertFalse(ResetCommand.sameServer("http://localhost:4566", "http://remote-host:4566", LOCAL));
|
||||
assertFalse(ResetCommand.sameServer("http://localhost:4566", "not a url", LOCAL));
|
||||
}
|
||||
|
||||
/** A remote daemon publishes the port on its own machine: that host, not this one, is the server's. */
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"ssh://deploy@remote-host, http://remote-host:14566, true",
|
||||
"tcp://remote-host:2375, http://remote-host:14566, true",
|
||||
"tcp://remote-host:2375, http://REMOTE-HOST:14566/, true",
|
||||
"ssh://deploy@remote-host, http://localhost:14566, false",
|
||||
"ssh://deploy@remote-host, http://other-host:14566, false",
|
||||
"ssh://deploy@remote-host, http://remote-host:4566, false"})
|
||||
void forARemoteDaemonTheSameServerIsTheSamePortOnTheDaemonsHost(String dockerHost, String endpoint, boolean same) {
|
||||
DockerHost remote = DockerClient.parseDockerHost(dockerHost, null, "Linux");
|
||||
|
||||
assertEquals(same, ResetCommand.sameServer("http://localhost:14566", endpoint, remote));
|
||||
}
|
||||
|
||||
/** A profile for an instance on a remote Docker host: its endpoint and its container are one server. */
|
||||
@Test
|
||||
void aRemoteInstanceWhoseEndpointMatchesIsReset() throws Exception {
|
||||
DockerHost remote = DockerClient.parseDockerHost("ssh://deploy@remote-host", null, "Linux");
|
||||
|
||||
ResetCommand.Target target = targetWithProfile(dockerWith("floci", "running", "14566->4566/tcp", remote),
|
||||
"container: floci\nport: 14566\nendpoint: http://remote-host:14566\n");
|
||||
|
||||
assertNull(target.error(), target.error());
|
||||
assertEquals("http://remote-host:14566", target.endpoint());
|
||||
}
|
||||
|
||||
/** On a remote daemon 'localhost:<port>' is this machine, not the container: without an endpoint nothing is reset. */
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"floci", "floci-b"})
|
||||
void aRemoteContainerWithoutAnEndpointResetsNothing(String container) {
|
||||
DockerHost remote = DockerClient.parseDockerHost("tcp://remote-host:2375", null, "Linux");
|
||||
List<String> args = container.equals("floci") ? List.of() : List.of("--container", container);
|
||||
|
||||
ResetCommand.Target target = targetOf(dockerWith(container, "running", "4566->4566/tcp", remote), args.toArray(String[]::new));
|
||||
|
||||
assertNull(target.endpoint());
|
||||
assertTrue(target.error().contains("runs on the remote Docker host tcp://remote-host:2375"), target.error());
|
||||
assertTrue(target.error().contains("Pass --endpoint <url>"), target.error());
|
||||
}
|
||||
|
||||
/**
|
||||
* A profile that names a container, even one with the default name, has selected it: when it is
|
||||
* not running, the profile's endpoint is not a fallback and nothing is reset.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@CsvSource({"something-else, running, not found", "floci, exited, is not running"})
|
||||
void aContainerFromAProfileMustBeRunningEvenWithTheDefaultName(String name, String state, String reason) throws Exception {
|
||||
ResetCommand.Target target = targetWithProfile(dockerWith(name, state, ""),
|
||||
"container: floci\nendpoint: http://remote-host:4566\n");
|
||||
|
||||
assertNull(target.endpoint());
|
||||
assertTrue(target.error().contains("Container 'floci' " + reason), target.error());
|
||||
assertTrue(target.error().contains("so nothing was reset."), target.error());
|
||||
}
|
||||
|
||||
/** The environment selects a container the same way a profile does. */
|
||||
@Test
|
||||
void aContainerFromTheEnvironmentMustBeRunningToo() {
|
||||
ResetCommand reset = new ResetCommand(ProductProfile.AWS, dockerWith("something-else", "running", ""), NOBODY,
|
||||
Map.of("FLOCI_CONTAINER", "floci", "FLOCI_ENDPOINT", "http://remote-host:4566")::get);
|
||||
new CommandLine(reset).parseArgs();
|
||||
|
||||
ResetCommand.Target target = reset.target();
|
||||
|
||||
assertNull(target.endpoint());
|
||||
assertTrue(target.error().contains("Container 'floci' not found, so nothing was reset."), target.error());
|
||||
}
|
||||
|
||||
/** FLOCI_ENDPOINT alone names a server, like an endpoint-only profile. */
|
||||
@Test
|
||||
void anEndpointFromTheEnvironmentIsUsedAsGiven() {
|
||||
ResetCommand reset = new ResetCommand(ProductProfile.AWS, dockerWith("something-else", "running", ""), NOBODY,
|
||||
Map.of("FLOCI_ENDPOINT", "http://remote-host:4566")::get);
|
||||
new CommandLine(reset).parseArgs();
|
||||
|
||||
assertEquals("http://remote-host:4566", reset.target().endpoint());
|
||||
}
|
||||
|
||||
/** When docker cannot be asked, nothing contradicts the endpoint the user configured. */
|
||||
@@ -253,12 +347,24 @@ class ResetCommandTest {
|
||||
assertEquals("http://remote-host:4566", targetWithProfile(broken, "endpoint: http://remote-host:4566\n").endpoint());
|
||||
}
|
||||
|
||||
/** A profile that names a container is found through the container, endpoint or not. */
|
||||
/** A profile's container and its endpoint have to be one server, whatever the container is called. */
|
||||
@Test
|
||||
void aProfileContainerStillDecidesOverItsEndpoint() throws Exception {
|
||||
void aProfileWhoseContainerAndEndpointDisagreeResetsNothing() throws Exception {
|
||||
ResetCommand.Target target = targetWithProfile(dockerWith("floci-b", "running", "24566->4566/tcp"),
|
||||
"container: floci-b\nendpoint: http://localhost:14566\n");
|
||||
|
||||
assertNull(target.endpoint());
|
||||
assertTrue(target.error().contains("container 'floci-b' is running at http://localhost:24566"), target.error());
|
||||
assertTrue(target.error().contains("They are different servers, so nothing was reset."), target.error());
|
||||
}
|
||||
|
||||
/** A profile made by 'config profile create --container --port' keeps the default endpoint: no conflict. */
|
||||
@Test
|
||||
void aProfileWithTheDefaultEndpointIsFoundThroughItsContainer() throws Exception {
|
||||
ResetCommand.Target target = targetWithProfile(dockerWith("floci-b", "running", "24566->4566/tcp"),
|
||||
"container: floci-b\nport: 24566\nendpoint: http://localhost:4566\n");
|
||||
|
||||
assertNull(target.error(), target.error());
|
||||
assertEquals("http://localhost:24566", target.endpoint());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user