summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>2019-04-30 18:00:46 +0100
committerRaoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>2019-05-14 11:20:32 +0100
commit7ad87c75bdf7c1961189bc92f271fcaf4aa75019 (patch)
tree4c9c71e8e8fb3877624a002fc953bbf6122154b0
parent0c33a3e14b65754717f4bac9c160c198b2b72744 (diff)
downloadbuildstream-raoul/982-individual-source-caching.tar.gz
Add tests for BST_REQUIRES_PREVIOUS_SOURCES_STAGEraoul/982-individual-source-caching
Tests that sources are cached seperately where appropriate. Part of #982
-rw-r--r--tests/sourcecache/cache.py123
-rw-r--r--tests/sourcecache/project/elements/source-with-patches-1.bst8
-rw-r--r--tests/sourcecache/project/elements/source-with-patches-2.bst10
-rw-r--r--tests/sourcecache/project/elements/source-without-patches.bst8
-rw-r--r--tests/sourcecache/project/files/hello-patch.diff7
5 files changed, 156 insertions, 0 deletions
diff --git a/tests/sourcecache/cache.py b/tests/sourcecache/cache.py
new file mode 100644
index 000000000..20faaa64e
--- /dev/null
+++ b/tests/sourcecache/cache.py
@@ -0,0 +1,123 @@
+#
+# Copyright (C) 2019 Bloomberg Finance LP
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+#
+# Authors:
+# Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>
+#
+
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+import os
+import pytest
+
+from buildstream.testing.runcli import cli # pylint: disable=unused-import
+from buildstream import _yaml
+
+DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project")
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_patch_sources_cached_1(cli, datafiles):
+ project_dir = str(datafiles)
+
+ res = cli.run(project=project_dir, args=["build", "source-with-patches-1.bst"])
+ res.assert_success()
+
+ # as we have a local, patch, local config, the first local and patch should
+ # be cached together, and the last local on it's own
+ source_dir = os.path.join(project_dir, 'cache', 'cas', 'refs', 'heads', '@sources')
+
+ assert len(os.listdir(os.path.join(source_dir, 'patch'))) == 1
+ assert len(os.listdir(os.path.join(source_dir, 'local'))) == 2
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_patch_sources_cached_2(cli, datafiles):
+ project_dir = str(datafiles)
+
+ res = cli.run(project=project_dir, args=["build", "source-with-patches-2.bst"])
+ res.assert_success()
+
+ # As everything is before the patch it should all be cached together
+ source_dir = os.path.join(project_dir, 'cache', 'cas', 'refs', 'heads', '@sources')
+
+ assert len(os.listdir(os.path.join(source_dir, 'patch'))) == 1
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_sources_without_patch(cli, datafiles):
+ project_dir = str(datafiles)
+
+ res = cli.run(project=project_dir, args=["build", "source-without-patches.bst"])
+ res.assert_success()
+
+ # No patches so everything should be cached seperately
+ source_dir = os.path.join(project_dir, 'cache', 'cas', 'refs', 'heads', '@sources')
+
+ assert len(os.listdir(os.path.join(source_dir, 'local'))) == 3
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_source_cache_key(cli, datafiles):
+ project_dir = str(datafiles)
+
+ file_path = os.path.join(project_dir, 'files')
+ file_url = 'file://' + file_path
+ element_path = os.path.join(project_dir, 'elements')
+ element_name = 'key_check.bst'
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ {
+ 'kind': 'remote',
+ 'url': os.path.join(file_url, 'bin-files', 'usr', 'bin', 'hello'),
+ 'directory': 'usr/bin'
+ }, {
+ 'kind': 'remote',
+ 'url': os.path.join(file_url, 'dev-files', 'usr', 'include', 'pony.h'),
+ 'directory': 'usr/include'
+ }, {
+ 'kind': 'patch',
+ 'path': 'files/hello-patch.diff'
+ }
+ ]
+ }
+ _yaml.dump(element, os.path.join(element_path, element_name))
+
+ res = cli.run(project=project_dir, args=["source", "track", element_name])
+ res.assert_success()
+
+ res = cli.run(project=project_dir, args=["build", element_name])
+ res.assert_success()
+
+ # Should have one source ref
+ patch_refs = os.path.join(project_dir, 'cache', 'cas', 'refs', 'heads', '@sources', 'patch')
+ assert len(os.listdir(patch_refs)) == 1
+
+ # modify hello-patch file and check tracking updates refs
+ with open(os.path.join(file_path, 'dev-files', 'usr', 'include', 'pony.h'), 'a') as f:
+ f.write("\nappending nonsense")
+
+ res = cli.run(project=project_dir, args=["source", "track", element_name])
+ res.assert_success()
+ assert "Found new revision: " in res.stderr
+
+ res = cli.run(project=project_dir, args=["source", "fetch", element_name])
+ res.assert_success()
+
+ # We should have a new source ref
+ assert len(os.listdir(patch_refs)) == 2
diff --git a/tests/sourcecache/project/elements/source-with-patches-1.bst b/tests/sourcecache/project/elements/source-with-patches-1.bst
new file mode 100644
index 000000000..95ab7c7f8
--- /dev/null
+++ b/tests/sourcecache/project/elements/source-with-patches-1.bst
@@ -0,0 +1,8 @@
+kind: import
+sources:
+- kind: local
+ path: files/bin-files
+- kind: patch
+ path: files/hello-patch.diff
+- kind: local
+ path: files/dev-files
diff --git a/tests/sourcecache/project/elements/source-with-patches-2.bst b/tests/sourcecache/project/elements/source-with-patches-2.bst
new file mode 100644
index 000000000..ef4fa3a02
--- /dev/null
+++ b/tests/sourcecache/project/elements/source-with-patches-2.bst
@@ -0,0 +1,10 @@
+kind: import
+sources:
+- kind: local
+ path: files/bin-files
+- kind: local
+ path: files/dev-files
+- kind: local
+ path: files/hello-patch.diff
+- kind: patch
+ path: files/hello-patch.diff
diff --git a/tests/sourcecache/project/elements/source-without-patches.bst b/tests/sourcecache/project/elements/source-without-patches.bst
new file mode 100644
index 000000000..f35583e02
--- /dev/null
+++ b/tests/sourcecache/project/elements/source-without-patches.bst
@@ -0,0 +1,8 @@
+kind: import
+sources:
+- kind: local
+ path: files/bin-files
+- kind: local
+ path: files/dev-files
+- kind: local
+ path: files/hello-patch.diff
diff --git a/tests/sourcecache/project/files/hello-patch.diff b/tests/sourcecache/project/files/hello-patch.diff
new file mode 100644
index 000000000..fc0416c0e
--- /dev/null
+++ b/tests/sourcecache/project/files/hello-patch.diff
@@ -0,0 +1,7 @@
+--- a/usr/bin/hello
++++ b/usr/bin/hello
+@@ -1,3 +1,3 @@
+ #!/bin/bash
+
+-echo "Hello !"
++echo "Patched hello !"