summaryrefslogtreecommitdiff
path: root/buildstream/testing/integration.py
diff options
context:
space:
mode:
authorPhil Dawson <phil.dawson@codethink.co.uk>2019-04-18 17:34:35 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-04-26 13:26:26 +0000
commit956ae30d56693555dc19ff81cc6f2a8a3ffe6560 (patch)
tree621b6f231749fccec912390d82b28bb086f6d54c /buildstream/testing/integration.py
parent140a9eb9f4ce2c3547e9f61262460dcc34f758c2 (diff)
downloadbuildstream-956ae30d56693555dc19ff81cc6f2a8a3ffe6560.tar.gz
testing: make Integration cache fixture available in testing module
The cli_integration fixture provided in testing.runcli depends on the integration cache fixture. This was missed when cli_integration was originally exposed.
Diffstat (limited to 'buildstream/testing/integration.py')
-rw-r--r--buildstream/testing/integration.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/buildstream/testing/integration.py b/buildstream/testing/integration.py
index e29f480ea..01635de74 100644
--- a/buildstream/testing/integration.py
+++ b/buildstream/testing/integration.py
@@ -23,6 +23,10 @@ integration tests.
"""
import os
+import shutil
+import tempfile
+
+import pytest
# Return a list of files relative to the given directory
@@ -49,3 +53,45 @@ def assert_contains(directory, expected):
if missing:
raise AssertionError("Missing {} expected elements from list: {}"
.format(len(missing), missing))
+
+
+class IntegrationCache:
+
+ def __init__(self, cache):
+ self.root = os.path.abspath(cache)
+ os.makedirs(cache, exist_ok=True)
+
+ # Use the same sources every time
+ self.sources = os.path.join(self.root, 'sources')
+
+ # Create a temp directory for the duration of the test for
+ # the artifacts directory
+ try:
+ self.cachedir = tempfile.mkdtemp(dir=self.root, prefix='cache-')
+ except OSError as e:
+ raise AssertionError("Unable to create test directory !") from e
+
+
+@pytest.fixture(scope='session')
+def integration_cache(request):
+ # Set the cache dir to the INTEGRATION_CACHE variable, or the
+ # default if that is not set.
+ if 'INTEGRATION_CACHE' in os.environ:
+ cache_dir = os.environ['INTEGRATION_CACHE']
+ else:
+ cache_dir = os.path.abspath('./integration-cache')
+
+ cache = IntegrationCache(cache_dir)
+
+ yield cache
+
+ # Clean up the artifacts after each test session - we only want to
+ # cache sources between tests
+ try:
+ shutil.rmtree(cache.cachedir)
+ except FileNotFoundError:
+ pass
+ try:
+ shutil.rmtree(os.path.join(cache.root, 'cas'))
+ except FileNotFoundError:
+ pass