From 58340203167f22e4b1c64961d7eca53b9694be62 Mon Sep 17 00:00:00 2001 From: Ivan Andreev Date: Wed, 17 Feb 2021 00:38:02 +0000 Subject: [PATCH] docker.bash: work correctly with multi-ip containers (#5028) Currently if container under test has multiple IP addresses, the `docker_ip` function from `docker.sh` will return a gibberish. This patch makes it return the first address found. Additionally, I apply shellcheck on `docker.sh`. --- fstest/testserver/init.d/docker.bash | 6 +++--- fstest/testserver/testserver.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fstest/testserver/init.d/docker.bash b/fstest/testserver/init.d/docker.bash index 2bd00643d..442738986 100644 --- a/fstest/testserver/init.d/docker.bash +++ b/fstest/testserver/init.d/docker.bash @@ -2,13 +2,13 @@ stop() { if status ; then - docker stop $NAME + docker stop "$NAME" echo "$NAME stopped" fi } status() { - if docker ps --format "{{.Names}}" | grep ^${NAME}$ >/dev/null ; then + if docker ps --format '{{.Names}}' | grep -q "^${NAME}$" ; then echo "$NAME running" else echo "$NAME not running" @@ -18,5 +18,5 @@ status() { } docker_ip() { - docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $NAME + docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{"\n"}}{{end}}' "$NAME" | head -1 } diff --git a/fstest/testserver/testserver.go b/fstest/testserver/testserver.go index 4ec5e0acb..8026b6d6e 100644 --- a/fstest/testserver/testserver.go +++ b/fstest/testserver/testserver.go @@ -91,7 +91,7 @@ func start(name string) error { continue } - // fs.Debugf(name, "key = %q, envKey = %q, value = %q", key, envKey, value) + // fs.Debugf(name, "key = %q, envKey = %q, value = %q", key, envKey(name, string(key)), value) err = os.Setenv(envKey(name, string(key)), string(value)) if err != nil { return err