summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Maw <jonathan.maw@codethink.co.uk>2018-08-08 18:23:52 +0100
committerJonathan Maw <jonathan.maw@codethink.co.uk>2018-08-08 18:23:52 +0100
commit6ef51eb61daf2447f4039ecc35b5f86a67028a47 (patch)
treed07f9c1e7b62b3783e69003ad785a7fedc3c8ec8
parenta80bd2dc6d7968d2685405c2fee8a40cd0467c70 (diff)
downloadbuildstream-6ef51eb61daf2447f4039ecc35b5f86a67028a47.tar.gz
tests: Add a test of the git source with submodules
-rw-r--r--tests/frontend/mirror.py79
-rw-r--r--tests/frontend/project/files/bar0
-rw-r--r--tests/frontend/project/files/foo0
3 files changed, 79 insertions, 0 deletions
diff --git a/tests/frontend/mirror.py b/tests/frontend/mirror.py
index bcc4e1b11..7a664d1f5 100644
--- a/tests/frontend/mirror.py
+++ b/tests/frontend/mirror.py
@@ -616,3 +616,82 @@ def test_mirror_junction_from_includes(cli, tmpdir, datafiles, kind):
os.rename('{}.bak'.format(upstream_repo.repo), upstream_repo.repo)
result = cli.run(project=project_dir, args=['fetch', element_name])
result.assert_success()
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_mirror_git_submodule_fetch(cli, tmpdir, datafiles):
+ # Test that it behaves as expected with submodules, both defined in config
+ # and discovered when fetching.
+ foo_file = os.path.join(str(datafiles), 'files', 'foo')
+ bar_file = os.path.join(str(datafiles), 'files', 'bar')
+ bin_files_path = os.path.join(str(datafiles), 'files', 'bin-files', 'usr')
+ dev_files_path = os.path.join(str(datafiles), 'files', 'dev-files', 'usr')
+ mirror_dir = os.path.join(str(datafiles), 'mirror')
+
+ defined_subrepo = create_repo('git', str(tmpdir), 'defined_subrepo')
+ defined_mirror_ref = defined_subrepo.create(bin_files_path)
+ defined_mirror = defined_subrepo.copy(mirror_dir)
+ defined_subref = defined_subrepo.add_file(foo_file)
+
+ found_subrepo = create_repo('git', str(tmpdir), 'found_subrepo')
+ found_subref = found_subrepo.create(dev_files_path)
+
+ main_repo = create_repo('git', str(tmpdir))
+ main_mirror_ref = main_repo.create(bin_files_path)
+ main_repo.add_submodule('defined', 'file://' + defined_subrepo.repo)
+ main_repo.add_submodule('found', 'file://' + found_subrepo.repo)
+ main_mirror = main_repo.copy(mirror_dir)
+ main_ref = main_repo.add_file(bar_file)
+
+ project_dir = os.path.join(str(tmpdir), 'project')
+ os.makedirs(project_dir)
+ element_dir = os.path.join(project_dir, 'elements')
+ os.makedirs(element_dir)
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ main_repo.source_config(ref=main_mirror_ref)
+ ]
+ }
+ element_name = 'test.bst'
+ element_path = os.path.join(element_dir, element_name)
+
+ # Alias the main repo
+ full_repo = element['sources'][0]['url']
+ _, repo_name = os.path.split(full_repo)
+ alias = 'foo'
+ aliased_repo = alias + ':' + repo_name
+ element['sources'][0]['url'] = aliased_repo
+
+ # Hide the found subrepo
+ del element['sources'][0]['submodules']['found']
+
+ # Alias the defined subrepo
+ subrepo = element['sources'][0]['submodules']['defined']['url']
+ _, repo_name = os.path.split(subrepo)
+ aliased_repo = alias + ':' + repo_name
+ element['sources'][0]['submodules']['defined']['url'] = aliased_repo
+
+ _yaml.dump(element, element_path)
+
+ full_mirror = main_mirror.source_config()['url']
+ mirror_map, _ = os.path.split(full_mirror)
+ project = {
+ 'name': 'test',
+ 'element-path': 'elements',
+ 'aliases': {
+ alias: 'http://www.example.com/'
+ },
+ 'mirrors': [
+ {
+ 'name': 'middle-earth',
+ 'aliases': {
+ alias: [mirror_map + "/"],
+ },
+ },
+ ]
+ }
+ project_file = os.path.join(project_dir, 'project.conf')
+ _yaml.dump(project, project_file)
+
+ result = cli.run(project=project_dir, args=['fetch', element_name])
+ result.assert_success()
diff --git a/tests/frontend/project/files/bar b/tests/frontend/project/files/bar
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/frontend/project/files/bar
diff --git a/tests/frontend/project/files/foo b/tests/frontend/project/files/foo
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/frontend/project/files/foo