From 5541e88a211b6460ae14d815291652c68acf715c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Tue, 29 Nov 2016 16:08:09 +0100 Subject: Add ArtifactCache tests As OSTree requires xattrs, basetemp must point to a directory with xattrs support. --- tests/artifactcache/basics.py | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/artifactcache/basics.py (limited to 'tests/artifactcache') 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') -- cgit v1.2.1