Refactor to eliminate need for volume mount

This change allows, imo, the test to be clearer, and should also speed
up the test.
pull/874/head
Hal Wine 2020-04-19 08:53:01 -07:00
rodzic 2c9027eb80
commit 6f59fdb20f
1 zmienionych plików z 15 dodań i 12 usunięć

Wyświetl plik

@ -16,11 +16,9 @@ def test_env():
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
username = getuser() username = getuser()
os.environ["SPAM"] = "eggs" os.environ["SPAM"] = "eggs"
subprocess.check_call( result = subprocess.run(
[ [
"repo2docker", "repo2docker",
"-v",
"{}:/home/{}".format(tmpdir, username),
"-e", "-e",
"FOO={}".format(ts), "FOO={}".format(ts),
"--env", "--env",
@ -31,13 +29,18 @@ def test_env():
tmpdir, tmpdir,
"/bin/bash", "/bin/bash",
"-c", "-c",
"echo -n $FOO > ts && echo -n $BAR > bar && echo -n $SPAM > eggs", # Docker exports all passed env variables, so we can
] # just look at that output
"export",
],
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
) )
assert result.returncode == 0
with open(os.path.join(tmpdir, "ts")) as f: # all docker output is returned by repo2docker on stderr
assert f.read().strip() == ts # extract just the declare for better failure message formatting
with open(os.path.join(tmpdir, "bar")) as f: declares = [x for x in result.stderr.split("\n") if x.startswith("declare")]
assert f.read().strip() == "baz" assert 'declare -x FOO="{}"'.format(ts) in declares
with open(os.path.join(tmpdir, "eggs")) as f: assert 'declare -x BAR="baz"' in declares
assert f.read().strip() == "eggs" assert 'declare -x SPAM="eggs"' in declares