From 57599f0075ccab859d4158f7ee891b9b971c731f Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Tue, 7 Nov 2017 10:03:46 -0500 Subject: Fix up handling of environment variables The way docker works is if a user specifies a non `-e Name=Value`, IE just a `-e Name`, then the environment variable Name from the clients OS.ENV is used. Also by default Docker containers run with the HOSTNAME environment set to the HOSTNAME specified for the container. Signed-off-by: Daniel J Walsh Closes: #21 Approved by: baude --- test/helpers.bash | 2 +- test/kpod_run.bats | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/helpers.bash b/test/helpers.bash index 3ec247e60..b760ec2cf 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -14,7 +14,7 @@ elif [[ ! -z "$TRAVIS" ]]; then elif [[ ! -z "$PAPR" ]]; then CRIO_ROOT="/var/tmp/checkout" else - CRIO_ROOT=$(cd "$INTEGRATION_ROOT/../.."; pwd -P)} + CRIO_ROOT=$(cd "$INTEGRATION_ROOT/.."; pwd -P) fi KPOD_BINARY=${KPOD_BINARY:-${CRIO_ROOT}/bin/kpod} diff --git a/test/kpod_run.bats b/test/kpod_run.bats index 56995316b..fa5fada55 100644 --- a/test/kpod_run.bats +++ b/test/kpod_run.bats @@ -60,3 +60,34 @@ ALPINE="docker.io/library/alpine:latest" [ "$status" -eq 0 ] } + +@test "run environment test" { + + ${KPOD_BINARY} ${KPOD_OPTIONS} pull ${ALPINE} + + run bash -c "${KPOD_BINARY} ${KPOD_OPTIONS} run -env FOO=BAR ${ALPINE} printenv FOO | tr -d '\r'" + echo "$output" + [ "$status" -eq 0 ] + [ $output = "BAR" ] + + run bash -c "${KPOD_BINARY} ${KPOD_OPTIONS} run -env PATH="/bin" ${ALPINE} printenv PATH | tr -d '\r'" + echo "$output" + [ "$status" -eq 0 ] + [ $output = "/bin" ] + + run bash -c "export FOO=BAR; ${KPOD_BINARY} ${KPOD_OPTIONS} run -env FOO ${ALPINE} printenv FOO | tr -d '\r'" + echo "$output" + [ "$status" -eq 0 ] + [ "$output" = "BAR" ] + + run ${KPOD_BINARY} ${KPOD_OPTIONS} run -env FOO ${ALPINE} printenv + echo "$output" + [ "$status" -ne 0 ] + +# We don't currently set the hostname in containers, since we are not setting up +# networking. As soon as kpod run gets network support we need to uncomment this +# test. +# run bash -c "${KPOD_BINARY} ${KPOD_OPTIONS} run ${ALPINE} sh -c printenv | grep HOSTNAME" +# echo "$output" +# [ "$status" -eq 0 ] +} -- cgit v1.2.3-54-g00ecf