summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/sources/tar.py46
-rw-r--r--tests/sources/tar/fetch/target-lz.bst6
-rw-r--r--tests/testutils/site.py6
3 files changed, 58 insertions, 0 deletions
diff --git a/tests/sources/tar.py b/tests/sources/tar.py
index 07d44be9e..b90a5c5ab 100644
--- a/tests/sources/tar.py
+++ b/tests/sources/tar.py
@@ -1,10 +1,13 @@
import os
import pytest
import tarfile
+import tempfile
+import subprocess
from buildstream._pipeline import PipelineError
from buildstream import utils, _yaml
from tests.testutils import cli
+from tests.testutils.site import HAVE_LZIP
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
@@ -20,6 +23,20 @@ def _assemble_tar(workingdir, srcdir, dstfile):
os.chdir(old_dir)
+def _assemble_tar_lz(workingdir, srcdir, dstfile):
+ old_dir = os.getcwd()
+ os.chdir(workingdir)
+ with tempfile.TemporaryFile() as uncompressed:
+ with tarfile.open(fileobj=uncompressed, mode="w:") as tar:
+ tar.add(srcdir)
+ uncompressed.seek(0, 0)
+ with open(dstfile, 'wb') as dst:
+ subprocess.call(['lzip'],
+ stdin=uncompressed,
+ stdout=dst)
+ os.chdir(old_dir)
+
+
def generate_project(project_dir, tmpdir):
project_file = os.path.join(project_dir, "project.conf")
_yaml.dump({
@@ -221,3 +238,32 @@ def test_stage_contains_links(cli, tmpdir, datafiles):
original_contents = _list_dir_contents(original_dir)
checkout_contents = _list_dir_contents(checkoutdir)
assert(checkout_contents == original_contents)
+
+
+@pytest.mark.skipif(not HAVE_LZIP, reason='lzip is not available')
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'fetch'))
+@pytest.mark.parametrize("srcdir", ["a", "./a"])
+def test_stage_default_basedir_lzip(cli, tmpdir, datafiles, srcdir):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ generate_project(project, tmpdir)
+ checkoutdir = os.path.join(str(tmpdir), "checkout")
+
+ # Create a local tar
+ src_tar = os.path.join(str(tmpdir), "a.tar.lz")
+ _assemble_tar_lz(os.path.join(str(datafiles), "content"), srcdir, src_tar)
+
+ # Track, fetch, build, checkout
+ result = cli.run(project=project, args=['track', 'target-lz.bst'])
+ assert result.exit_code == 0
+ result = cli.run(project=project, args=['fetch', 'target-lz.bst'])
+ assert result.exit_code == 0
+ result = cli.run(project=project, args=['build', 'target-lz.bst'])
+ assert result.exit_code == 0
+ result = cli.run(project=project, args=['checkout', 'target-lz.bst', checkoutdir])
+ assert result.exit_code == 0
+
+ # Check that the content of the first directory is checked out (base-dir: '*')
+ original_dir = os.path.join(str(datafiles), "content", "a")
+ original_contents = _list_dir_contents(original_dir)
+ checkout_contents = _list_dir_contents(checkoutdir)
+ assert(checkout_contents == original_contents)
diff --git a/tests/sources/tar/fetch/target-lz.bst b/tests/sources/tar/fetch/target-lz.bst
new file mode 100644
index 000000000..b0569129e
--- /dev/null
+++ b/tests/sources/tar/fetch/target-lz.bst
@@ -0,0 +1,6 @@
+kind: import
+description: The kind of this element is irrelevant.
+sources:
+- kind: tar
+ url: tmpdir:/a.tar.lz
+ ref: foo
diff --git a/tests/testutils/site.py b/tests/testutils/site.py
index 79538efbf..456f6ec15 100644
--- a/tests/testutils/site.py
+++ b/tests/testutils/site.py
@@ -37,6 +37,12 @@ try:
except ProgramNotFoundError:
HAVE_BWRAP = False
+try:
+ utils.get_host_tool('lzip')
+ HAVE_LZIP = True
+except ProgramNotFoundError:
+ HAVE_LZIP = False
+
IS_LINUX = os.getenv('BST_FORCE_BACKEND', sys.platform).startswith('linux')
HAVE_ROOT = HAVE_BWRAP or os.geteuid() == 0