This is an automated email from the ASF dual-hosted git repository.

akitouni pushed a commit to branch abderrahim/nested-reapi
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 95fe67fa6f3a3a1b46805e85a2272b5b6002c8d3
Author: Jürg Billeter <[email protected]>
AuthorDate: Fri Jul 25 16:18:59 2025 +0200

    tests/integration: Add tests for `digest-environment`
---
 tests/integration/digest-environment.py            | 106 +++++++++++++++++++++
 .../elements/digest-environment/base-buildtree.bst |  12 +++
 .../digest-environment/base-plus-extra-dep.bst     |  14 +++
 .../project/elements/digest-environment/base.bst   |  12 +++
 .../project/elements/digest-environment/merge.bst  |  16 ++++
 .../project/elements/digest-environment/two.bst    |  17 ++++
 6 files changed, 177 insertions(+)

diff --git a/tests/integration/digest-environment.py 
b/tests/integration/digest-environment.py
new file mode 100644
index 000000000..ec132f221
--- /dev/null
+++ b/tests/integration/digest-environment.py
@@ -0,0 +1,106 @@
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+import os
+import pytest
+
+from buildstream._testing import cli_integration as cli  # pylint: 
disable=unused-import
+from buildstream._testing._utils.site import HAVE_SANDBOX
+
+pytestmark = pytest.mark.integration
+
+
+DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project")
+
+
+# Test that the digest environment variable is set correctly during a build
[email protected](not HAVE_SANDBOX, reason="Only available with a 
functioning sandbox")
[email protected](DATA_DIR)
+def test_build_base(cli, datafiles):
+    project = str(datafiles)
+    element_name = "digest-environment/base.bst"
+
+    result = cli.run(project=project, args=["build", element_name])
+    assert result.exit_code == 0
+
+
+# Test that the digest environment variable is not affected by unrelated build 
dependencies
[email protected](not HAVE_SANDBOX, reason="Only available with a 
functioning sandbox")
[email protected](DATA_DIR)
+def test_build_base_plus_extra_dep(cli, datafiles):
+    project = str(datafiles)
+    element_name = "digest-environment/base-plus-extra-dep.bst"
+
+    result = cli.run(project=project, args=["build", element_name])
+    assert result.exit_code == 0
+
+
+# Test that multiple dependencies can be merged into a single digest 
environment variable
[email protected](not HAVE_SANDBOX, reason="Only available with a 
functioning sandbox")
[email protected](DATA_DIR)
+def test_build_merge(cli, datafiles):
+    project = str(datafiles)
+    element_name = "digest-environment/merge.bst"
+
+    result = cli.run(project=project, args=["build", element_name])
+    assert result.exit_code == 0
+
+
+# Test that multiple digest environment variables can be configured in a 
single element
[email protected](not HAVE_SANDBOX, reason="Only available with a 
functioning sandbox")
[email protected](DATA_DIR)
+def test_build_two(cli, datafiles):
+    project = str(datafiles)
+    element_name = "digest-environment/two.bst"
+
+    result = cli.run(project=project, args=["build", element_name])
+    assert result.exit_code == 0
+
+
+# Test that the digest environment variable is also set in a build shell
[email protected](not HAVE_SANDBOX, reason="Only available with a 
functioning sandbox")
[email protected](DATA_DIR)
+def test_build_shell(cli, datafiles):
+    project = str(datafiles)
+    element_name = "digest-environment/base.bst"
+
+    # Ensure artifacts of build dependencies are available for build shell
+    result = cli.run(project=project, args=["build", "--deps", "build", 
element_name])
+    assert result.exit_code == 0
+
+    result = cli.run(project=project, args=["shell", "--build", element_name, 
"--", "sh", "-c", "echo $BASE_DIGEST"])
+    assert result.exit_code == 0
+    assert result.output.strip() == 
"63450d93eab71f525d08378fe50960aff92b0ec8f1b0be72b2ac4b8259d09833/1227"
+
+
+# Test that the digest environment variable is also set in a build shell 
staged from a buildtree
[email protected](not HAVE_SANDBOX, reason="Only available with a 
functioning sandbox")
[email protected](DATA_DIR)
+def test_build_shell_buildtree(cli, datafiles):
+    project = str(datafiles)
+    element_name = "digest-environment/base-buildtree.bst"
+
+    # Generate buildtree
+    result = cli.run(project=project, args=["--cache-buildtrees", "always", 
"build", element_name])
+    assert result.exit_code == 0
+
+    result = cli.run(
+        project=project,
+        args=["shell", "--build", "--use-buildtree", element_name, "--", "sh", 
"-c", "echo $BASE_DIGEST"],
+    )
+    assert result.exit_code == 0
+    assert result.output.strip() == 
"63450d93eab71f525d08378fe50960aff92b0ec8f1b0be72b2ac4b8259d09833/1227"
diff --git 
a/tests/integration/project/elements/digest-environment/base-buildtree.bst 
b/tests/integration/project/elements/digest-environment/base-buildtree.bst
new file mode 100644
index 000000000..19161e806
--- /dev/null
+++ b/tests/integration/project/elements/digest-environment/base-buildtree.bst
@@ -0,0 +1,12 @@
+kind: manual
+
+depends:
+  - filename: base.bst
+    type: build
+    config:
+      digest-environment: BASE_DIGEST
+
+config:
+  build-commands:
+    - env
+    - test "$BASE_DIGEST" = 
"63450d93eab71f525d08378fe50960aff92b0ec8f1b0be72b2ac4b8259d09833/1227"
diff --git 
a/tests/integration/project/elements/digest-environment/base-plus-extra-dep.bst 
b/tests/integration/project/elements/digest-environment/base-plus-extra-dep.bst
new file mode 100644
index 000000000..87bd0c61d
--- /dev/null
+++ 
b/tests/integration/project/elements/digest-environment/base-plus-extra-dep.bst
@@ -0,0 +1,14 @@
+kind: manual
+
+depends:
+  - filename: base.bst
+    type: build
+    config:
+      digest-environment: BASE_DIGEST
+  - filename: manual/import-file.bst
+    type: build
+
+config:
+  build-commands:
+    - env
+    - test "$BASE_DIGEST" = 
"63450d93eab71f525d08378fe50960aff92b0ec8f1b0be72b2ac4b8259d09833/1227"
diff --git a/tests/integration/project/elements/digest-environment/base.bst 
b/tests/integration/project/elements/digest-environment/base.bst
new file mode 100644
index 000000000..19161e806
--- /dev/null
+++ b/tests/integration/project/elements/digest-environment/base.bst
@@ -0,0 +1,12 @@
+kind: manual
+
+depends:
+  - filename: base.bst
+    type: build
+    config:
+      digest-environment: BASE_DIGEST
+
+config:
+  build-commands:
+    - env
+    - test "$BASE_DIGEST" = 
"63450d93eab71f525d08378fe50960aff92b0ec8f1b0be72b2ac4b8259d09833/1227"
diff --git a/tests/integration/project/elements/digest-environment/merge.bst 
b/tests/integration/project/elements/digest-environment/merge.bst
new file mode 100644
index 000000000..a6bfdb5b6
--- /dev/null
+++ b/tests/integration/project/elements/digest-environment/merge.bst
@@ -0,0 +1,16 @@
+kind: manual
+
+depends:
+  - filename: base.bst
+    type: build
+    config:
+      digest-environment: MERGED_DIGEST
+  - filename: manual/import-file.bst
+    type: build
+    config:
+      digest-environment: MERGED_DIGEST
+
+config:
+  build-commands:
+    - env
+    - test "$MERGED_DIGEST" = 
"469369597f4faa56c4b8338d6a948c8c1d4f29e6ea8f4d4d261cac4182bcef48/1389"
diff --git a/tests/integration/project/elements/digest-environment/two.bst 
b/tests/integration/project/elements/digest-environment/two.bst
new file mode 100644
index 000000000..7619e6ac0
--- /dev/null
+++ b/tests/integration/project/elements/digest-environment/two.bst
@@ -0,0 +1,17 @@
+kind: manual
+
+depends:
+  - filename: base.bst
+    type: build
+    config:
+      digest-environment: BASE_DIGEST
+  - filename: manual/import-file.bst
+    type: build
+    config:
+      digest-environment: IMPORT_DIGEST
+
+config:
+  build-commands:
+    - env
+    - test "$BASE_DIGEST" = 
"63450d93eab71f525d08378fe50960aff92b0ec8f1b0be72b2ac4b8259d09833/1227"
+    - test "$IMPORT_DIGEST" = 
"eec5ed9053acb296a8e7a30ab7ee173abf4f7392b8228ba7644cd5b51a5cfdeb/162"

Reply via email to