|
1
|
+import os
|
|
2
|
+import pytest
|
|
3
|
+
|
|
4
|
+from buildstream._exceptions import ErrorDomain
|
|
5
|
+
|
|
6
|
+from buildstream._context import Context
|
|
7
|
+from buildstream.storage._casbaseddirectory import CasBasedDirectory
|
|
8
|
+from buildstream.storage._filebaseddirectory import FileBasedDirectory
|
|
9
|
+
|
|
10
|
+DATA_DIR = os.path.join(
|
|
11
|
+ os.path.dirname(os.path.realpath(__file__)),
|
|
12
|
+ "storage-test"
|
|
13
|
+)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+def setup_backend(backend_class, tmpdir):
|
|
17
|
+ if backend_class == FileBasedDirectory:
|
|
18
|
+ return backend_class(os.path.join(tmpdir, "vdir"))
|
|
19
|
+ else:
|
|
20
|
+ context = Context()
|
|
21
|
+ context.artifactdir = os.path.join(tmpdir, "cas")
|
|
22
|
+ return backend_class(context)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+@pytest.mark.parametrize("backend", [
|
|
26
|
+ FileBasedDirectory, CasBasedDirectory])
|
|
27
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
28
|
+def test_import(tmpdir, datafiles, backend):
|
|
29
|
+ original = os.path.join(str(datafiles), "original")
|
|
30
|
+
|
|
31
|
+ c = setup_backend(backend, str(tmpdir))
|
|
32
|
+
|
|
33
|
+ c.import_files(original)
|
|
34
|
+
|
|
35
|
+ assert("bin/bash" in c.list_relative_paths())
|
|
36
|
+ assert("bin/hello" in c.list_relative_paths())
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+@pytest.mark.parametrize("backend", [
|
|
40
|
+ FileBasedDirectory, CasBasedDirectory])
|
|
41
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
42
|
+def test_modified_file_list(tmpdir, datafiles, backend):
|
|
43
|
+ original = os.path.join(str(datafiles), "original")
|
|
44
|
+ overlay = os.path.join(str(datafiles), "overlay")
|
|
45
|
+
|
|
46
|
+ c = setup_backend(backend, str(tmpdir))
|
|
47
|
+
|
|
48
|
+ c.import_files(original)
|
|
49
|
+
|
|
50
|
+ c.mark_unmodified()
|
|
51
|
+
|
|
52
|
+ c.import_files(overlay)
|
|
53
|
+
|
|
54
|
+ print("List of all paths in imported results: {}".format(c.list_relative_paths()))
|
|
55
|
+ assert("bin/bash" in c.list_relative_paths())
|
|
56
|
+ assert("bin/bash" in c.list_modified_paths())
|
|
57
|
+ assert("bin/hello" not in c.list_modified_paths())
|