diff options
-rw-r--r-- | tests/integration/artifact.py | 75 | ||||
-rw-r--r-- | tests/integration/project/elements/echo-env-var.bst | 10 | ||||
-rw-r--r-- | tests/integration/project/elements/echo-target.bst | 3 | ||||
-rw-r--r-- | tests/integration/project/project.conf | 2 |
4 files changed, 90 insertions, 0 deletions
diff --git a/tests/integration/artifact.py b/tests/integration/artifact.py index e21dd4296..f7d62a57c 100644 --- a/tests/integration/artifact.py +++ b/tests/integration/artifact.py @@ -138,3 +138,78 @@ def test_cache_buildtrees(cli, tmpdir, datafiles): with cli.artifact.extract_buildtree(cwd, cwd, artifact_name) as buildtreedir: assert os.path.isdir(buildtreedir) assert os.listdir(buildtreedir) + + +# +# This test asserts that the environment variables are indeed preserved in +# generated artifacts, and asserts that local project state is not erronously +# observed when checking out and integrating an artifact by artifact name. +# +@pytest.mark.datafiles(DATA_DIR) +@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox") +def test_preserve_environment(datafiles, cli): + project = str(datafiles) + checkout = os.path.join(cli.directory, "checkout") + + # + # First build the target, this will create the echo-env-var.bst artifact + # and cache an integration command which uses it's build environment + # to create /etc/test.conf + # + result = cli.run(project=project, args=["build", "echo-target.bst"]) + result.assert_success() + + # + # Now preserve the cache key of the toplevel + # + key = cli.get_element_key(project, "echo-target.bst") + + # + # From here on out, we will augment the project.conf with a modified + # environment, causing the definition of the element to change and + # consequently the cache key. + # + project_config = {"environment": {"TEST_VAR": "horsy"}} + + # + # This should changed the cache key such that a different artifact + # would be produced, as the environment has changed. + # + result = cli.run_project_config( + project=project, + project_config=project_config, + args=["show", "--deps", "none", "--format", "%{full-key}", "echo-target.bst"], + ) + result.assert_success() + assert result.output.strip() != key + + # + # Now checkout the originally built artifact and request that it be integrated, + # this will run integration commands encoded into the artifact. + # + checkout_args = [ + "artifact", + "checkout", + "--directory", + checkout, + "--deps", + "build", + "--integrate", + "test/echo-target/" + key, + ] + result = cli.run_project_config(project=project, args=checkout_args, project_config=project_config) + result.assert_success() + + # + # Now observe the file generated by echo-env-var.bst's integration command. + # + # Here we assert that the actual environment from the artifact is being + # used to run the integration command, and not the irrelevant project + # data in the local project directory. + # + filename = os.path.join(checkout, "etc", "test.conf") + assert os.path.exists(filename) + with open(filename, "r") as f: + data = f.read() + data = data.strip() + assert data == "pony" diff --git a/tests/integration/project/elements/echo-env-var.bst b/tests/integration/project/elements/echo-env-var.bst new file mode 100644 index 000000000..692d5de90 --- /dev/null +++ b/tests/integration/project/elements/echo-env-var.bst @@ -0,0 +1,10 @@ +kind: manual +depends: +- base.bst + +public: + bst: + integration-commands: + - | + echo $TEST_VAR > /etc/test.conf + diff --git a/tests/integration/project/elements/echo-target.bst b/tests/integration/project/elements/echo-target.bst new file mode 100644 index 000000000..8d4d7e15b --- /dev/null +++ b/tests/integration/project/elements/echo-target.bst @@ -0,0 +1,3 @@ +kind: manual +depends: +- echo-env-var.bst diff --git a/tests/integration/project/project.conf b/tests/integration/project/project.conf index 2d3da467b..521b80184 100644 --- a/tests/integration/project/project.conf +++ b/tests/integration/project/project.conf @@ -17,6 +17,8 @@ options: values: - x86-64 - aarch64 +environment: + TEST_VAR: pony split-rules: test: - | |