You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ro...@apache.org on 2020/12/29 13:38:36 UTC

[buildstream] 05/20: import_cas.py: The first, very simple, CAS import test

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

root pushed a commit to branch jmac/virtual_directory_tests
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit f46acc041868fedd3976d319e124203964e3c97f
Author: Jim MacArthur <ji...@codethink.co.uk>
AuthorDate: Fri Sep 14 14:46:06 2018 +0100

    import_cas.py: The first, very simple, CAS import test
---
 tests/storage/import_cas.py | 51 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/tests/storage/import_cas.py b/tests/storage/import_cas.py
new file mode 100644
index 0000000..e77328d
--- /dev/null
+++ b/tests/storage/import_cas.py
@@ -0,0 +1,51 @@
+import stat
+import os
+import pytest
+from tests.testutils import cli, create_repo, ALL_REPO_KINDS, generate_junction
+
+from buildstream.storage import CasBasedDirectory
+
+# Project directory
+TOP_DIR = os.path.dirname(os.path.realpath(__file__))
+
+
+class FakeContext():
+    def __init__(self):
+        self.config_cache_quota = "0"
+
+    def get_projects(self):
+        return []
+
+root_filesets = [
+    [('a/b/c/textfile1', 'This is textfile 1\n')],
+    [('a/b/c/textfile1', 'This is the replacement textfile 1\n')],
+]
+
+
+def generate_import_roots(directory):
+    for fileset in [1, 2]:
+        rootname = "root{}".format(fileset)
+
+        for (path, content) in root_filesets[fileset - 1]:
+            (dirnames, filename) = os.path.split(path)
+            os.path.mkdirs(dirnames)
+
+            with open(os.path.join(tmpdir, rootname, dirnames, filename), "wt") as f:
+                f.write(content)
+
+
+def test_cas_import(cli, tmpdir):
+    fake_context = FakeContext()
+    fake_context.artifactdir = tmpdir
+    # Create some fake content
+    d = CasBasedDirectory(fake_context)
+    d.import_files(os.path.join(tmpdir, "content", "root1"))
+
+    d2 = CasBasedDirectory(fake_context)
+    d2.import_files(os.path.join(tmpdir, "content", "root2"))
+
+    d.import_files(d2)
+
+    d.export_files(os.path.join(tmpdir, "output"))
+    assert os.path.exists(os.path.join(tmpdir, "output", "a", "b", "c", "textfile1"))
+    assert file_contents_are(os.path.join(tmpdir, "output", "a", "b", "c", "textfile1"), root_filesets[1][0][1])