summaryrefslogtreecommitdiff
path: root/tests/artifactcache
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2016-11-29 16:08:09 +0100
committerJürg Billeter <j@bitron.ch>2016-12-01 15:03:32 +0100
commit5541e88a211b6460ae14d815291652c68acf715c (patch)
treea5c06b57555f14c5ff6d82683606e092bd4d489d /tests/artifactcache
parentb4855ff7d13a798fb30539726d1a878295a04546 (diff)
downloadbuildstream-5541e88a211b6460ae14d815291652c68acf715c.tar.gz
Add ArtifactCache tests
As OSTree requires xattrs, basetemp must point to a directory with xattrs support.
Diffstat (limited to 'tests/artifactcache')
-rw-r--r--tests/artifactcache/basics.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/artifactcache/basics.py b/tests/artifactcache/basics.py
new file mode 100644
index 000000000..e63318ba9
--- /dev/null
+++ b/tests/artifactcache/basics.py
@@ -0,0 +1,47 @@
+import os
+import pytest
+import tempfile
+
+from buildstream import Context
+from buildstream._artifactcache import ArtifactCache
+
+@pytest.fixture()
+def context(tmpdir):
+ context = Context('x86_64')
+ context.load()
+
+ context.deploydir = os.path.join(str(tmpdir), 'deploy')
+ context.artifactdir = os.path.join(str(tmpdir), 'artifact')
+
+ return context
+
+@pytest.fixture()
+def artifactcache(context):
+ return ArtifactCache(context)
+
+def test_empty_contains(context, artifactcache):
+ assert(not artifactcache.contains('foo', 'bar', 'a1b2c3'))
+
+@pytest.mark.xfail()
+def test_empty_extract(context, artifactcache):
+ artifactcache.extract('foo', 'bar', 'a1b2c3')
+
+def test_commit_extract(context, artifactcache):
+ os.makedirs(context.deploydir, exist_ok=True)
+ with tempfile.TemporaryDirectory(dir=context.deploydir) as deploydir:
+ # create file as mock build output
+ bindir = os.path.join(deploydir, 'bin')
+ os.mkdir(bindir)
+ with open(os.path.join(bindir, 'baz'), 'w') as f:
+ f.write('hello, world')
+
+ # commit build output to artifact cache
+ artifactcache.commit('foo', 'bar', 'a1b2c3', deploydir)
+
+ assert(artifactcache.contains('foo', 'bar', 'a1b2c3'))
+
+ # extract artifact and verify the content
+ extractdir = artifactcache.extract('foo', 'bar', 'a1b2c3')
+ with open(os.path.join(extractdir, 'bin', 'baz'), 'r') as f:
+ content = f.read()
+ assert(content == 'hello, world')