You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2022/04/05 10:04:47 UTC

[buildstream-plugins] 32/49: tests/elements/make.py: Adding tests for make element

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

tvb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/buildstream-plugins.git

commit 2ee84628a867f5ca15996a8d5533cb97dfc3a41a
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Mon Mar 21 16:29:39 2022 +0900

    tests/elements/make.py: Adding tests for make element
---
 tests/elements/make.py                             |  48 +++++++++++++++++++++
 tests/elements/make/elements/base.bst              |   3 ++
 tests/elements/make/elements/base/alpine-image.bst |   6 +++
 tests/elements/make/elements/makehello.bst         |  10 +++++
 tests/elements/make/files/makehello.tar.gz         | Bin 0 -> 432 bytes
 tests/elements/make/project.conf                   |  15 +++++++
 6 files changed, 82 insertions(+)

diff --git a/tests/elements/make.py b/tests/elements/make.py
new file mode 100644
index 0000000..4edb513
--- /dev/null
+++ b/tests/elements/make.py
@@ -0,0 +1,48 @@
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+import os
+import pytest
+
+from buildstream._testing.integration import assert_contains
+from buildstream._testing.integration import integration_cache  # pylint: disable=unused-import
+from buildstream._testing.runcli 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__)), "make")
+
+
+# Test that a make build 'works' - we use the make sample
+# makehello project for this.
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
+def test_make_build(cli, datafiles):
+    project = str(datafiles)
+    checkout = os.path.join(cli.directory, "checkout")
+    element_name = "makehello.bst"
+
+    result = cli.run(project=project, args=["build", element_name])
+    assert result.exit_code == 0
+
+    result = cli.run(project=project, args=["artifact", "checkout", element_name, "--directory", checkout],)
+    assert result.exit_code == 0
+
+    assert_contains(checkout, ["/usr", "/usr/bin", "/usr/bin/hello"])
+
+
+# Test running an executable built with make
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
+def test_make_run(cli, datafiles):
+    project = str(datafiles)
+    element_name = "makehello.bst"
+
+    result = cli.run(project=project, args=["build", element_name])
+    assert result.exit_code == 0
+
+    result = cli.run(project=project, args=["shell", element_name, "/usr/bin/hello"])
+    assert result.exit_code == 0
+    assert result.output == "Hello, world\n"
diff --git a/tests/elements/make/elements/base.bst b/tests/elements/make/elements/base.bst
new file mode 100644
index 0000000..da7c70b
--- /dev/null
+++ b/tests/elements/make/elements/base.bst
@@ -0,0 +1,3 @@
+kind: stack
+depends:
+- base/alpine-image.bst
diff --git a/tests/elements/make/elements/base/alpine-image.bst b/tests/elements/make/elements/base/alpine-image.bst
new file mode 100644
index 0000000..f8e00ba
--- /dev/null
+++ b/tests/elements/make/elements/base/alpine-image.bst
@@ -0,0 +1,6 @@
+kind: import
+description: Import an alpine image as the platform
+sources:
+- kind: tar
+  url: alpine:integration-tests-base.v1.x86_64.tar.xz
+  ref: 3eb559250ba82b64a68d86d0636a6b127aa5f6d25d3601a79f79214dc9703639
diff --git a/tests/elements/make/elements/makehello.bst b/tests/elements/make/elements/makehello.bst
new file mode 100644
index 0000000..4b5c5ac
--- /dev/null
+++ b/tests/elements/make/elements/makehello.bst
@@ -0,0 +1,10 @@
+kind: make
+description: make test
+
+depends:
+- base.bst
+
+sources:
+- kind: tar
+  url: project_dir:/files/makehello.tar.gz
+  ref: fd342a36503a0a0dd37b81ddb4d2b78bd398d912d813339e0de44a6b6c393b8e
diff --git a/tests/elements/make/files/makehello.tar.gz b/tests/elements/make/files/makehello.tar.gz
new file mode 100644
index 0000000..d0edcb2
Binary files /dev/null and b/tests/elements/make/files/makehello.tar.gz differ
diff --git a/tests/elements/make/project.conf b/tests/elements/make/project.conf
new file mode 100644
index 0000000..039d500
--- /dev/null
+++ b/tests/elements/make/project.conf
@@ -0,0 +1,15 @@
+# test project config
+name: test
+min-version: 2.0
+
+element-path: elements
+
+plugins:
+- origin: pip
+  package-name: buildstream-plugins
+  elements:
+  - make
+
+aliases:
+  alpine: https://bst-integration-test-images.ams3.cdn.digitaloceanspaces.com/
+  project_dir: file://{project_dir}