diff options
author | Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk> | 2019-03-07 14:49:35 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-03-25 11:46:44 +0000 |
commit | fff2eed8d5e5dd1161e5f339fae5cd1f072e5cfe (patch) | |
tree | f094fed17c4f7a8fdfbc4ac9c892ef689d2eaaed /tests/sourcecache/push.py | |
parent | af35c82365d1ec9333efbe28b52aa6e04811c04f (diff) | |
download | buildstream-fff2eed8d5e5dd1161e5f339fae5cd1f072e5cfe.tar.gz |
tests: Add source cache push test
Part of #440
Diffstat (limited to 'tests/sourcecache/push.py')
-rw-r--r-- | tests/sourcecache/push.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/tests/sourcecache/push.py b/tests/sourcecache/push.py new file mode 100644 index 000000000..b95ac2dda --- /dev/null +++ b/tests/sourcecache/push.py @@ -0,0 +1,96 @@ +# +# 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._context import Context +from buildstream._project import Project +from buildstream import _yaml +from buildstream.plugintestutils import cli # pylint: disable=unused-import + +from tests.testutils import create_artifact_share, create_repo + +DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project") + + +def message_handler(message, context): + pass + + +@pytest.mark.datafiles(DATA_DIR) +def test_source_push(cli, tmpdir, datafiles): + cache_dir = os.path.join(str(tmpdir), 'cache') + project_dir = str(datafiles) + + with create_artifact_share(os.path.join(str(tmpdir), 'sourceshare')) as share: + user_config_file = str(tmpdir.join('buildstream.conf')) + user_config = { + 'scheduler': { + 'pushers': 1 + }, + 'source-caches': { + 'url': share.repo, + 'push': True, + }, + 'cachedir': cache_dir, + } + _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file) + cli.configure(user_config) + + repo = create_repo('git', str(tmpdir)) + ref = repo.create(os.path.join(project_dir, 'files')) + element_path = os.path.join(project_dir, 'elements') + element_name = 'push.bst' + element = { + 'kind': 'import', + 'sources': [repo.source_config(ref=ref)] + } + _yaml.dump(element, os.path.join(element_path, element_name)) + + # get the source object + context = Context() + context.load(config=user_config_file) + context.set_message_handler(message_handler) + project = Project(project_dir, context) + project.ensure_fully_loaded() + + element = project.load_elements(['push.bst'])[0] + assert not element._source_cached() + source = list(element.sources())[0] + + # check we don't have it in the current cache + cas = context.get_cascache() + assert not cas.contains(source._get_source_name()) + + # build the element, this should fetch and then push the source to the + # remote + res = cli.run(project=project_dir, args=['build', 'push.bst']) + res.assert_success() + assert "Pushed source" in res.stderr + + # check that we've got the remote locally now + sourcecache = context.sourcecache + assert sourcecache.contains(source) + + # check that's the remote CAS now has it + digest = share.cas.resolve_ref(source._get_source_name()) + assert share.has_object(digest) |