From 136deb2e75a18e2a7c4e79e07ddaf3de9965b397 Mon Sep 17 00:00:00 2001 From: Jim MacArthur Date: Mon, 6 Aug 2018 18:02:06 +0100 Subject: Add basic storage test 'storage-test.py' --- tests/sandboxes/storage-test/original/bin/bash | 1 + tests/sandboxes/storage-test/original/bin/hello | 1 + tests/sandboxes/storage-test/overlay/bin/bash | 1 + tests/sandboxes/storage-tests.py | 57 +++++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 tests/sandboxes/storage-test/original/bin/bash create mode 100644 tests/sandboxes/storage-test/original/bin/hello create mode 100644 tests/sandboxes/storage-test/overlay/bin/bash create mode 100644 tests/sandboxes/storage-tests.py diff --git a/tests/sandboxes/storage-test/original/bin/bash b/tests/sandboxes/storage-test/original/bin/bash new file mode 100644 index 000000000..a221b564c --- /dev/null +++ b/tests/sandboxes/storage-test/original/bin/bash @@ -0,0 +1 @@ +This is the original /bin/bash. diff --git a/tests/sandboxes/storage-test/original/bin/hello b/tests/sandboxes/storage-test/original/bin/hello new file mode 100644 index 000000000..5524e9677 --- /dev/null +++ b/tests/sandboxes/storage-test/original/bin/hello @@ -0,0 +1 @@ +This is the original /bin/hello. diff --git a/tests/sandboxes/storage-test/overlay/bin/bash b/tests/sandboxes/storage-test/overlay/bin/bash new file mode 100644 index 000000000..b639d94ec --- /dev/null +++ b/tests/sandboxes/storage-test/overlay/bin/bash @@ -0,0 +1 @@ +This is the replacement /bin/bash. diff --git a/tests/sandboxes/storage-tests.py b/tests/sandboxes/storage-tests.py new file mode 100644 index 000000000..553da2ba7 --- /dev/null +++ b/tests/sandboxes/storage-tests.py @@ -0,0 +1,57 @@ +import os +import pytest + +from buildstream._exceptions import ErrorDomain + +from buildstream._context import Context +from buildstream.storage._casbaseddirectory import CasBasedDirectory +from buildstream.storage._filebaseddirectory import FileBasedDirectory + +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "storage-test" +) + + +def setup_backend(backend_class, tmpdir): + if backend_class == FileBasedDirectory: + return backend_class(os.path.join(tmpdir, "vdir")) + else: + context = Context() + context.artifactdir = os.path.join(tmpdir, "cas") + return backend_class(context) + + +@pytest.mark.parametrize("backend", [ + FileBasedDirectory, CasBasedDirectory]) +@pytest.mark.datafiles(DATA_DIR) +def test_import(tmpdir, datafiles, backend): + original = os.path.join(str(datafiles), "original") + + c = setup_backend(backend, str(tmpdir)) + + c.import_files(original) + + assert("bin/bash" in c.list_relative_paths()) + assert("bin/hello" in c.list_relative_paths()) + + +@pytest.mark.parametrize("backend", [ + FileBasedDirectory, CasBasedDirectory]) +@pytest.mark.datafiles(DATA_DIR) +def test_modified_file_list(tmpdir, datafiles, backend): + original = os.path.join(str(datafiles), "original") + overlay = os.path.join(str(datafiles), "overlay") + + c = setup_backend(backend, str(tmpdir)) + + c.import_files(original) + + c.mark_unmodified() + + c.import_files(overlay) + + print("List of all paths in imported results: {}".format(c.list_relative_paths())) + assert("bin/bash" in c.list_relative_paths()) + assert("bin/bash" in c.list_modified_paths()) + assert("bin/hello" not in c.list_modified_paths()) -- cgit v1.2.1