kopia lustrzana https://github.com/jupyterhub/repo2docker
Expand test cases to cover current Docker handling
Examination of docker's handling showed a few additional cases were needed.pull/874/head
rodzic
6f59fdb20f
commit
a09e523fd4
|
@ -11,26 +11,39 @@ from getpass import getuser
|
|||
def test_env():
|
||||
"""
|
||||
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())
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
username = getuser()
|
||||
os.environ["SPAM"] = "eggs"
|
||||
os.environ["SPAM_2"] = "ham"
|
||||
result = subprocess.run(
|
||||
[
|
||||
"repo2docker",
|
||||
# 'key=value' are exported as is in docker
|
||||
"-e",
|
||||
"FOO={}".format(ts),
|
||||
"--env",
|
||||
"BAR=baz",
|
||||
# 'key' is exported with the currently exported value
|
||||
"--env",
|
||||
"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,
|
||||
"/bin/bash",
|
||||
"-c",
|
||||
# Docker exports all passed env variables, so we can
|
||||
# just look at that output
|
||||
# just look at exported variables.
|
||||
"export",
|
||||
],
|
||||
universal_newlines=True,
|
||||
|
@ -38,9 +51,12 @@ def test_env():
|
|||
stderr=subprocess.PIPE,
|
||||
)
|
||||
assert result.returncode == 0
|
||||
|
||||
# all docker output is returned by repo2docker on stderr
|
||||
# extract just the declare for better failure message formatting
|
||||
declares = [x for x in result.stderr.split("\n") if x.startswith("declare")]
|
||||
assert 'declare -x FOO="{}"'.format(ts) in declares
|
||||
assert 'declare -x BAR="baz"' in declares
|
||||
assert 'declare -x SPAM="eggs"' in declares
|
||||
assert "declare -x NO_SPAM" not in declares
|
||||
assert 'declare -x SPAM_2=""' in declares
|
||||
|
|
Ładowanie…
Reference in New Issue