Skip to content
Snippets Groups Projects
Commit b325989e authored by Jürg Billeter's avatar Jürg Billeter
Browse files

tests/sources: Test that fetch() is not called for cached sources

parent 7a102144
No related branches found
No related tags found
Loading
Pipeline #40835932 passed
Hello World!
"""
always_cached
=============
This is a test source plugin that is always cached.
Used to test that BuildStream core does not call fetch() for cached sources.
"""
from buildstream import Consistency, Source
class AlwaysCachedSource(Source):
def configure(self, node):
pass
def preflight(self):
pass
def get_unique_key(self):
return None
def get_consistency(self):
return Consistency.CACHED
def load_ref(self, node):
pass
def get_ref(self):
return None
def set_ref(self, ref, node):
pass
def fetch(self):
# Source is always cached, so fetch() should never be called
assert False
def stage(self, directory):
pass
def setup():
return AlwaysCachedSource
# Project with local source plugins
name: no-fetch-cached
plugins:
- origin: local
path: plugins/sources
sources:
always_cached: 0
import os
import pytest
from buildstream import _yaml
from tests.testutils import cli, create_repo
from tests.testutils.site import HAVE_GIT
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'no-fetch-cached'
)
##################################################################
# Tests #
##################################################################
# Test that fetch() is not called for cached sources
@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
@pytest.mark.datafiles(DATA_DIR)
def test_no_fetch_cached(cli, tmpdir, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename)
# Create the repo from 'files' subdir
repo = create_repo('git', str(tmpdir))
ref = repo.create(os.path.join(project, 'files'))
# Write out test target with a cached and a non-cached source
element = {
'kind': 'import',
'sources': [
repo.source_config(ref=ref),
{
'kind': 'always_cached'
}
]
}
_yaml.dump(element, os.path.join(project, 'target.bst'))
# Test fetch of target with a cached and a non-cached source
result = cli.run(project=project, args=[
'source', 'fetch', 'target.bst'
])
result.assert_success()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment