Expand test cases to cover current Docker handling

Examination of docker's handling showed a few additional cases were
needed.
pull/874/head
Hal Wine 2020-04-19 15:58:16 -07:00
rodzic 6f59fdb20f
commit a09e523fd4
1 zmienionych plików z 17 dodań i 1 usunięć

Wyświetl plik

@ -11,26 +11,39 @@ from getpass import getuser
def test_env(): def test_env():
""" """
Validate that you can define environment variables Validate that you can define environment variables
See https://gist.github.com/hwine/9f5b02c894427324fafcf12f772b27b7
for how docker handles its -e & --env argument values
""" """
ts = str(time.time()) ts = str(time.time())
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
username = getuser() username = getuser()
os.environ["SPAM"] = "eggs" os.environ["SPAM"] = "eggs"
os.environ["SPAM_2"] = "ham"
result = subprocess.run( result = subprocess.run(
[ [
"repo2docker", "repo2docker",
# 'key=value' are exported as is in docker
"-e", "-e",
"FOO={}".format(ts), "FOO={}".format(ts),
"--env", "--env",
"BAR=baz", "BAR=baz",
# 'key' is exported with the currently exported value
"--env", "--env",
"SPAM", "SPAM",
# 'key' is not exported if it is not exported.
"-e",
"NO_SPAM",
# 'key=' is exported in docker with an empty string as
# value
"--env",
"SPAM_2=",
"--", "--",
tmpdir, tmpdir,
"/bin/bash", "/bin/bash",
"-c", "-c",
# Docker exports all passed env variables, so we can # Docker exports all passed env variables, so we can
# just look at that output # just look at exported variables.
"export", "export",
], ],
universal_newlines=True, universal_newlines=True,
@ -38,9 +51,12 @@ def test_env():
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
) )
assert result.returncode == 0 assert result.returncode == 0
# all docker output is returned by repo2docker on stderr # all docker output is returned by repo2docker on stderr
# extract just the declare for better failure message formatting # extract just the declare for better failure message formatting
declares = [x for x in result.stderr.split("\n") if x.startswith("declare")] declares = [x for x in result.stderr.split("\n") if x.startswith("declare")]
assert 'declare -x FOO="{}"'.format(ts) in declares assert 'declare -x FOO="{}"'.format(ts) in declares
assert 'declare -x BAR="baz"' in declares assert 'declare -x BAR="baz"' in declares
assert 'declare -x SPAM="eggs"' in declares assert 'declare -x SPAM="eggs"' in declares
assert "declare -x NO_SPAM" not in declares
assert 'declare -x SPAM_2=""' in declares