From 7ad82778f8c6afeb1252f1315d424714ac0eea3e Mon Sep 17 00:00:00 2001
From: Tristan Van Berkom <tristan.vanberkom@codethink.co.uk>
Date: Fri, 10 Mar 2017 18:12:23 +0900
Subject: Updated artifact cache test cases.

Now these load an actual (simple) pipeline, so there is
a fully qualified Element to use for testing the API.

Also we now expect a specific ArtifactError for failures
instead of using the xfail pytest decorator, which is a bit
nicer.
---
 tests/artifactcache/basics.py           | 44 +++++++++++++++++----------------
 tests/artifactcache/basics/project.conf |  3 +++
 tests/artifactcache/basics/simple.bst   |  5 ++++
 3 files changed, 31 insertions(+), 21 deletions(-)
 create mode 100644 tests/artifactcache/basics/project.conf
 create mode 100644 tests/artifactcache/basics/simple.bst

(limited to 'tests/artifactcache')

diff --git a/tests/artifactcache/basics.py b/tests/artifactcache/basics.py
index 4d20c9a92..d8c17618b 100644
--- a/tests/artifactcache/basics.py
+++ b/tests/artifactcache/basics.py
@@ -2,38 +2,40 @@ import os
 import pytest
 import tempfile
 
-from buildstream import Context
-from buildstream._artifactcache import ArtifactCache
+from buildstream import Context, Project
+from buildstream._artifactcache import ArtifactCache, ArtifactError
+from buildstream._pipeline import Pipeline
+
+DATA_DIR = os.path.join(
+    os.path.dirname(os.path.realpath(__file__)),
+    'basics',
+)
 
 
 @pytest.fixture()
-def context(tmpdir):
+def pipeline(tmpdir):
     context = Context('x86_64')
-    context.load()
+    project = Project(DATA_DIR, 'x86_64')
 
     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)
+    return Pipeline(context, project, "simple.bst", None)
 
 
-def test_empty_contains(context, artifactcache):
-    assert(not artifactcache.contains('foo', 'bar', 'a1b2c3'))
+def test_empty_contains(pipeline):
+    assert(not pipeline.artifacts.contains(pipeline.target))
 
 
-@pytest.mark.xfail()
-def test_empty_extract(context, artifactcache):
-    artifactcache.extract('foo', 'bar', 'a1b2c3')
+# Test that we get an ArtifactError when trying to extract a nonexistent artifact
+def test_empty_extract(pipeline):
+    with pytest.raises(ArtifactError) as exc:
+        pipeline.artifacts.extract(pipeline.target)
 
 
-def test_commit_extract(context, artifactcache):
-    os.makedirs(context.deploydir, exist_ok=True)
-    with tempfile.TemporaryDirectory(dir=context.deploydir) as deploydir:
+def test_commit_extract(pipeline):
+    os.makedirs(pipeline.context.deploydir, exist_ok=True)
+    with tempfile.TemporaryDirectory(dir=pipeline.context.deploydir) as deploydir:
         # create file as mock build output
         bindir = os.path.join(deploydir, 'bin')
         os.mkdir(bindir)
@@ -41,12 +43,12 @@ def test_commit_extract(context, artifactcache):
             f.write('hello, world')
 
         # commit build output to artifact cache
-        artifactcache.commit('foo', 'bar', 'a1b2c3', deploydir)
+        pipeline.artifacts.commit(pipeline.target, deploydir)
 
-    assert(artifactcache.contains('foo', 'bar', 'a1b2c3'))
+    assert(pipeline.artifacts.contains(pipeline.target))
 
     # extract artifact and verify the content
-    extractdir = artifactcache.extract('foo', 'bar', 'a1b2c3')
+    extractdir = pipeline.artifacts.extract(pipeline.target)
     with open(os.path.join(extractdir, 'bin', 'baz'), 'r') as f:
         content = f.read()
         assert(content == 'hello, world')
diff --git a/tests/artifactcache/basics/project.conf b/tests/artifactcache/basics/project.conf
new file mode 100644
index 000000000..2027cc27a
--- /dev/null
+++ b/tests/artifactcache/basics/project.conf
@@ -0,0 +1,3 @@
+# Basic project configuration that doesnt override anything
+#
+name: pony
diff --git a/tests/artifactcache/basics/simple.bst b/tests/artifactcache/basics/simple.bst
new file mode 100644
index 000000000..cd1f73968
--- /dev/null
+++ b/tests/artifactcache/basics/simple.bst
@@ -0,0 +1,5 @@
+kind: autotools
+description: Some kinda autotools element
+config:
+  configure-commands:
+  - pony
-- 
cgit v1.2.1