summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim MacArthur <jim.macarthur@codethink.co.uk>2018-08-06 18:02:06 +0100
committerJim MacArthur <jim.macarthur@codethink.co.uk>2018-08-15 15:33:05 +0100
commit136deb2e75a18e2a7c4e79e07ddaf3de9965b397 (patch)
treeaffbb2d0ec2695f9960413dfd926e3b32c9033fa
parent0213f68daef57be6745a0d554d31bfc8e9ee1271 (diff)
downloadbuildstream-jmac/cas_virtual_directory.tar.gz
Add basic storage test 'storage-test.py'jmac/cas_virtual_directory
-rw-r--r--tests/sandboxes/storage-test/original/bin/bash1
-rw-r--r--tests/sandboxes/storage-test/original/bin/hello1
-rw-r--r--tests/sandboxes/storage-test/overlay/bin/bash1
-rw-r--r--tests/sandboxes/storage-tests.py57
4 files changed, 60 insertions, 0 deletions
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())