summaryrefslogtreecommitdiff
path: root/tests/frontend
diff options
context:
space:
mode:
authorRebecca Grayson <becky.grayson1@hotmail.co.uk>2019-06-27 11:55:18 +0100
committerRebecca Grayson <becky.grayson1@hotmail.co.uk>2019-07-16 15:35:42 +0000
commitd14ce3cacdb5c1dfce396b64061bb4b8b554a1dc (patch)
tree3a622c45e16bbe077d31ae9a133655a3ec1bd9a1 /tests/frontend
parentcf3a1f6248fa6c2784020ab8d91b42fe5ed29779 (diff)
downloadbuildstream-d14ce3cacdb5c1dfce396b64061bb4b8b554a1dc.tar.gz
Allowing tar files to be compressedbecky/tar_compression
Changes made to cli.py and _stream.py in order to support tar compression. Compression flag has been added, which overrides any file extensions given. Where no compression or file extension provided, default to uncompressed .tar.
Diffstat (limited to 'tests/frontend')
-rw-r--r--tests/frontend/buildcheckout.py95
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/frontend/buildcheckout.py b/tests/frontend/buildcheckout.py
index aadefc2ab..a3f68c031 100644
--- a/tests/frontend/buildcheckout.py
+++ b/tests/frontend/buildcheckout.py
@@ -211,6 +211,76 @@ def test_build_checkout_unbuilt(datafiles, cli):
@pytest.mark.datafiles(DATA_DIR)
+def test_build_checkout_compression_no_tar(datafiles, cli):
+ project = str(datafiles)
+ checkout = os.path.join(cli.directory, 'checkout.tar')
+
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_success()
+
+ checkout_args = ['artifact', 'checkout', '--directory', checkout, '--compression', 'gz', 'target.bst']
+
+ result = cli.run(project=project, args=checkout_args)
+ assert "ERROR: --compression can only be provided if --tar is provided" in result.stderr
+ assert result.exit_code != 0
+
+# If we don't support the extension, we default to an uncompressed tarball
+@pytest.mark.datafiles(DATA_DIR)
+def test_build_checkout_tar_with_unconventional_name(datafiles, cli):
+ project = str(datafiles)
+ checkout = os.path.join(cli.directory, 'checkout.foo')
+
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_success()
+
+ checkout_args = ['artifact', 'checkout', '--tar', checkout, 'target.bst']
+
+ result = cli.run(project=project, args=checkout_args)
+ result.assert_success()
+
+ tar = tarfile.open(name=checkout, mode='r')
+ assert os.path.join('.', 'usr', 'bin', 'hello') in tar.getnames()
+ assert os.path.join('.', 'usr', 'include', 'pony.h') in tar.getnames()
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_build_checkout_tar_with_unsupported_ext(datafiles, cli):
+ project = str(datafiles)
+ checkout = os.path.join(cli.directory, 'checkout.tar.foo')
+
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_success()
+
+ checkout_args = ['artifact', 'checkout', '--tar', checkout, 'target.bst']
+
+ result = cli.run(project=project, args=checkout_args)
+ assert "Invalid file extension given with '--tar': Expected compression with unknown file extension ('.foo'), " \
+ "supported extensions are ('.tar'), ('.gz'), ('.xz'), ('.bz2')" in result.stderr
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_build_checkout_tar_no_compression(datafiles, cli):
+ project = str(datafiles)
+ checkout = os.path.join(cli.directory, 'checkout.tar.gz')
+
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_success()
+
+ builddir = os.path.join(cli.directory, 'build')
+ assert os.path.isdir(builddir)
+ assert not os.listdir(builddir)
+
+ checkout_args = ['artifact', 'checkout', '--tar', checkout, 'target.bst']
+
+ result = cli.run(project=project, args=checkout_args)
+ result.assert_success()
+
+ tar = tarfile.open(name=checkout, mode='r:gz')
+ assert os.path.join('.', 'usr', 'bin', 'hello') in tar.getnames()
+ assert os.path.join('.', 'usr', 'include', 'pony.h') in tar.getnames()
+
+
+@pytest.mark.datafiles(DATA_DIR)
def test_build_checkout_tarball(datafiles, cli):
project = str(datafiles)
checkout = os.path.join(cli.directory, 'checkout.tar')
@@ -251,6 +321,31 @@ def test_build_checkout_no_tar_no_directory(datafiles, cli, tmpdir):
@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("compression", [("gz"), ("xz"), ("bz2")])
+def test_build_checkout_tarball_compression(datafiles, cli, compression):
+ project = str(datafiles)
+ checkout = os.path.join(cli.directory, 'checkout.tar')
+
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_success()
+
+ builddir = os.path.join(cli.directory, 'build')
+ assert os.path.isdir(builddir)
+ assert not os.listdir(builddir)
+
+ checkout_args = ['artifact', 'checkout', '--tar', checkout, '--compression', compression, 'target.bst']
+
+ result = cli.run(project=project, args=checkout_args)
+ result.assert_success()
+
+ # Docs say not to use TarFile class directly, using .open seems to work.
+ # https://docs.python.org/3/library/tarfile.html#tarfile.TarFile
+ tar = tarfile.open(name=checkout, mode='r:' + compression)
+ assert os.path.join('.', 'usr', 'bin', 'hello') in tar.getnames()
+ assert os.path.join('.', 'usr', 'include', 'pony.h') in tar.getnames()
+
+
+@pytest.mark.datafiles(DATA_DIR)
def test_build_checkout_tarball_stdout(datafiles, cli):
project = str(datafiles)
tarball = os.path.join(cli.directory, 'tarball.tar')