summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Maw <jonathan.maw@codethink.co.uk>2018-02-02 16:28:10 +0000
committerJürg Billeter <j@bitron.ch>2018-02-19 15:17:01 +0000
commitc81776249ac245ba0cea57de3fa5f625e57ee918 (patch)
tree232045773bd0be6d6559d1fef5f498890bc9b50d
parent6498020e1e0414f7e235421ddf68400da32f55a2 (diff)
downloadbuildstream-c81776249ac245ba0cea57de3fa5f625e57ee918.tar.gz
tests: Add tests to verify git sources obey submodule checkout config
-rw-r--r--tests/sources/git.py207
-rw-r--r--tests/sources/git/template/othersubrepofiles/unicornfile.txt1
2 files changed, 208 insertions, 0 deletions
diff --git a/tests/sources/git.py b/tests/sources/git.py
index 1af5e712b..e96d6b4ce 100644
--- a/tests/sources/git.py
+++ b/tests/sources/git.py
@@ -76,3 +76,210 @@ def test_submodule_fetch_checkout(cli, tmpdir, datafiles):
# Assert we checked out both files at their expected location
assert os.path.exists(os.path.join(checkoutdir, 'file.txt'))
assert os.path.exists(os.path.join(checkoutdir, 'subdir', 'ponyfile.txt'))
+
+
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
+def test_submodule_fetch_source_enable_explicit(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ checkoutdir = os.path.join(str(tmpdir), "checkout")
+
+ # Create the submodule first from the 'subrepofiles' subdir
+ subrepo = create_repo('git', str(tmpdir), 'subrepo')
+ subrepo.create(os.path.join(project, 'subrepofiles'))
+
+ # Create the repo from 'repofiles' subdir
+ repo = create_repo('git', str(tmpdir))
+ ref = repo.create(os.path.join(project, 'repofiles'))
+
+ # Add a submodule pointing to the one we created
+ ref = repo.add_submodule('subdir', 'file://' + subrepo.repo)
+
+ # Write out our test target
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ repo.source_config(ref=ref, checkout_submodules=True)
+ ]
+ }
+ _yaml.dump(element, os.path.join(project, 'target.bst'))
+
+ # Fetch, build, checkout
+ result = cli.run(project=project, args=['fetch', 'target.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
+ result.assert_success()
+
+ # Assert we checked out both files at their expected location
+ assert os.path.exists(os.path.join(checkoutdir, 'file.txt'))
+ assert os.path.exists(os.path.join(checkoutdir, 'subdir', 'ponyfile.txt'))
+
+
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
+def test_submodule_fetch_source_disable(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ checkoutdir = os.path.join(str(tmpdir), "checkout")
+
+ # Create the submodule first from the 'subrepofiles' subdir
+ subrepo = create_repo('git', str(tmpdir), 'subrepo')
+ subrepo.create(os.path.join(project, 'subrepofiles'))
+
+ # Create the repo from 'repofiles' subdir
+ repo = create_repo('git', str(tmpdir))
+ ref = repo.create(os.path.join(project, 'repofiles'))
+
+ # Add a submodule pointing to the one we created
+ ref = repo.add_submodule('subdir', 'file://' + subrepo.repo)
+
+ # Write out our test target
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ repo.source_config(ref=ref, checkout_submodules=False)
+ ]
+ }
+ _yaml.dump(element, os.path.join(project, 'target.bst'))
+
+ # Fetch, build, checkout
+ result = cli.run(project=project, args=['fetch', 'target.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
+ result.assert_success()
+
+ # Assert we checked out both files at their expected location
+ assert os.path.exists(os.path.join(checkoutdir, 'file.txt'))
+ assert not os.path.exists(os.path.join(checkoutdir, 'subdir', 'ponyfile.txt'))
+
+
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
+def test_submodule_fetch_submodule_does_override(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ checkoutdir = os.path.join(str(tmpdir), "checkout")
+
+ # Create the submodule first from the 'subrepofiles' subdir
+ subrepo = create_repo('git', str(tmpdir), 'subrepo')
+ subrepo.create(os.path.join(project, 'subrepofiles'))
+
+ # Create the repo from 'repofiles' subdir
+ repo = create_repo('git', str(tmpdir))
+ ref = repo.create(os.path.join(project, 'repofiles'))
+
+ # Add a submodule pointing to the one we created
+ ref = repo.add_submodule('subdir', 'file://' + subrepo.repo, checkout=True)
+
+ # Write out our test target
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ repo.source_config(ref=ref, checkout_submodules=False)
+ ]
+ }
+ _yaml.dump(element, os.path.join(project, 'target.bst'))
+
+ # Fetch, build, checkout
+ result = cli.run(project=project, args=['fetch', 'target.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
+ result.assert_success()
+
+ # Assert we checked out both files at their expected location
+ assert os.path.exists(os.path.join(checkoutdir, 'file.txt'))
+ assert os.path.exists(os.path.join(checkoutdir, 'subdir', 'ponyfile.txt'))
+
+
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
+def test_submodule_fetch_submodule_individual_checkout(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ checkoutdir = os.path.join(str(tmpdir), "checkout")
+
+ # Create the submodule first from the 'subrepofiles' subdir
+ subrepo = create_repo('git', str(tmpdir), 'subrepo')
+ subrepo.create(os.path.join(project, 'subrepofiles'))
+
+ # Create another submodule from the 'othersubrepofiles' subdir
+ other_subrepo = create_repo('git', str(tmpdir), 'othersubrepo')
+ other_subrepo.create(os.path.join(project, 'othersubrepofiles'))
+
+ # Create the repo from 'repofiles' subdir
+ repo = create_repo('git', str(tmpdir))
+ ref = repo.create(os.path.join(project, 'repofiles'))
+
+ # Add a submodule pointing to the one we created
+ ref = repo.add_submodule('subdir', 'file://' + subrepo.repo, checkout=False)
+ ref = repo.add_submodule('othersubdir', 'file://' + other_subrepo.repo)
+
+ # Write out our test target
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ repo.source_config(ref=ref, checkout_submodules=True)
+ ]
+ }
+ _yaml.dump(element, os.path.join(project, 'target.bst'))
+
+ # Fetch, build, checkout
+ result = cli.run(project=project, args=['fetch', 'target.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
+ result.assert_success()
+
+ # Assert we checked out files at their expected location
+ assert os.path.exists(os.path.join(checkoutdir, 'file.txt'))
+ assert not os.path.exists(os.path.join(checkoutdir, 'subdir', 'ponyfile.txt'))
+ assert os.path.exists(os.path.join(checkoutdir, 'othersubdir', 'unicornfile.txt'))
+
+
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
+def test_submodule_fetch_submodule_individual_checkout_explicit(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ checkoutdir = os.path.join(str(tmpdir), "checkout")
+
+ # Create the submodule first from the 'subrepofiles' subdir
+ subrepo = create_repo('git', str(tmpdir), 'subrepo')
+ subrepo.create(os.path.join(project, 'subrepofiles'))
+
+ # Create another submodule from the 'othersubrepofiles' subdir
+ other_subrepo = create_repo('git', str(tmpdir), 'othersubrepo')
+ other_subrepo.create(os.path.join(project, 'othersubrepofiles'))
+
+ # Create the repo from 'repofiles' subdir
+ repo = create_repo('git', str(tmpdir))
+ ref = repo.create(os.path.join(project, 'repofiles'))
+
+ # Add a submodule pointing to the one we created
+ ref = repo.add_submodule('subdir', 'file://' + subrepo.repo, checkout=False)
+ ref = repo.add_submodule('othersubdir', 'file://' + other_subrepo.repo, checkout=True)
+
+ # Write out our test target
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ repo.source_config(ref=ref, checkout_submodules=True)
+ ]
+ }
+ _yaml.dump(element, os.path.join(project, 'target.bst'))
+
+ # Fetch, build, checkout
+ result = cli.run(project=project, args=['fetch', 'target.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
+ result.assert_success()
+
+ # Assert we checked out files at their expected location
+ assert os.path.exists(os.path.join(checkoutdir, 'file.txt'))
+ assert not os.path.exists(os.path.join(checkoutdir, 'subdir', 'ponyfile.txt'))
+ assert os.path.exists(os.path.join(checkoutdir, 'othersubdir', 'unicornfile.txt'))
diff --git a/tests/sources/git/template/othersubrepofiles/unicornfile.txt b/tests/sources/git/template/othersubrepofiles/unicornfile.txt
new file mode 100644
index 000000000..f73f3093f
--- /dev/null
+++ b/tests/sources/git/template/othersubrepofiles/unicornfile.txt
@@ -0,0 +1 @@
+file