summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRaman Tenneti <rtenneti@google.com>2021-01-14 19:17:50 -0800
committerRaman Tenneti <rtenneti@google.com>2021-01-21 19:41:52 +0000
commit6a872c9daeec58dda61786e6f65591330709f6ad (patch)
treedcd22dcc29c91de8a097cf7075400bb463ef40e0 /tests
parentdf6c506a8af47c19e853c96ba15e4446f93304b2 (diff)
downloadgit-repo-6a872c9daeec58dda61786e6f65591330709f6ad.tar.gz
sync: Added --use-superproject option and support for superproject.v2.12
Added "--use-superporject" option to sync.py to fetch project SHAs from superproject. If there are any missing projects in superprojects, it prints the missing entries and exits. If there are no missing entries, it will use SHAs from superproject to fetch the projects from git. Tested the code with the following commands. $ ./run_tests tests/test_manifest_xml.py $ ./run_tests -v tests/test_git_superproject.py $ ./run_tests -v Tested the sync code by copying all the repo changes into my Android AOSP checkout and adding <superporject> tag to default.xml. With local modification to the code to print the status, .../WORKING_DIRECTORY$ repo sync --use-superproject repo: executing 'git clone' url: sso://android/platform/superproject repo: executing 'git ls-tree' Success: [] Bug: https://crbug.com/gerrit/13709 Tested-by: Raman Tenneti <rtenneti@google.com> Change-Id: Id18665992428dd684c04b0e0b3a52f46316873a0 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/293822 Reviewed-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_git_superproject.py82
-rw-r--r--tests/test_manifest_xml.py14
2 files changed, 90 insertions, 6 deletions
diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py
new file mode 100644
index 00000000..67a75a17
--- /dev/null
+++ b/tests/test_git_superproject.py
@@ -0,0 +1,82 @@
1# Copyright (C) 2021 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Unittests for the git_superproject.py module."""
16
17import os
18import tempfile
19import unittest
20from unittest import mock
21
22from error import GitError
23import git_superproject
24import platform_utils
25
26
27class SuperprojectTestCase(unittest.TestCase):
28 """TestCase for the Superproject module."""
29
30 def setUp(self):
31 """Set up superproject every time."""
32 self.tempdir = tempfile.mkdtemp(prefix='repo_tests')
33 self.repodir = os.path.join(self.tempdir, '.repo')
34 os.mkdir(self.repodir)
35 self._superproject = git_superproject.Superproject(self.repodir)
36
37 def tearDown(self):
38 """Tear down superproject every time."""
39 platform_utils.rmtree(self.tempdir)
40
41 def test_superproject_get_project_shas_no_url(self):
42 """Test with no url."""
43 with self.assertRaises(ValueError):
44 self._superproject.GetAllProjectsSHAs(url=None)
45
46 def test_superproject_get_project_shas_invalid_url(self):
47 """Test with an invalid url."""
48 with self.assertRaises(GitError):
49 self._superproject.GetAllProjectsSHAs(url='localhost')
50
51 def test_superproject_get_project_shas_invalid_branch(self):
52 """Test with an invalid branch."""
53 with self.assertRaises(GitError):
54 self._superproject.GetAllProjectsSHAs(
55 url='sso://android/platform/superproject',
56 branch='junk')
57
58 def test_superproject_get_project_shas_mock_clone(self):
59 """Test with _Clone failing."""
60 with self.assertRaises(GitError):
61 with mock.patch.object(self._superproject, '_Clone', return_value=False):
62 self._superproject.GetAllProjectsSHAs(url='localhost')
63
64 def test_superproject_get_project_shas_mock_ls_tree(self):
65 """Test with LsTree being a mock."""
66 data = ('120000 blob 158258bdf146f159218e2b90f8b699c4d85b5804\tAndroid.bp\x00'
67 '160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00'
68 '160000 commit e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06\tbootable/recovery\x00'
69 '120000 blob acc2cbdf438f9d2141f0ae424cec1d8fc4b5d97f\tbootstrap.bash\x00'
70 '160000 commit ade9b7a0d874e25fff4bf2552488825c6f111928\tbuild/bazel\x00')
71 with mock.patch.object(self._superproject, '_Clone', return_value=True):
72 with mock.patch.object(self._superproject, '_LsTree', return_value=data):
73 shas = self._superproject.GetAllProjectsSHAs(url='localhost', branch='junk')
74 self.assertEqual(shas, {
75 'art': '2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea',
76 'bootable/recovery': 'e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06',
77 'build/bazel': 'ade9b7a0d874e25fff4bf2552488825c6f111928'
78 })
79
80
81if __name__ == '__main__':
82 unittest.main()
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py
index e2c83af9..370eb4f5 100644
--- a/tests/test_manifest_xml.py
+++ b/tests/test_manifest_xml.py
@@ -232,6 +232,7 @@ class XmlManifestTests(unittest.TestCase):
232""") 232""")
233 self.assertEqual(manifest.superproject['name'], 'superproject') 233 self.assertEqual(manifest.superproject['name'], 'superproject')
234 self.assertEqual(manifest.superproject['remote'].name, 'test-remote') 234 self.assertEqual(manifest.superproject['remote'].name, 'test-remote')
235 self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/superproject')
235 self.assertEqual( 236 self.assertEqual(
236 manifest.ToXml().toxml(), 237 manifest.ToXml().toxml(),
237 '<?xml version="1.0" ?><manifest>' + 238 '<?xml version="1.0" ?><manifest>' +
@@ -245,20 +246,21 @@ class XmlManifestTests(unittest.TestCase):
245 manifest = self.getXmlManifest(""" 246 manifest = self.getXmlManifest("""
246<manifest> 247<manifest>
247 <remote name="default-remote" fetch="http://localhost" /> 248 <remote name="default-remote" fetch="http://localhost" />
248 <remote name="test-remote" fetch="http://localhost" /> 249 <remote name="superproject-remote" fetch="http://localhost" />
249 <default remote="default-remote" revision="refs/heads/main" /> 250 <default remote="default-remote" revision="refs/heads/main" />
250 <superproject name="superproject" remote="test-remote"/> 251 <superproject name="platform/superproject" remote="superproject-remote"/>
251</manifest> 252</manifest>
252""") 253""")
253 self.assertEqual(manifest.superproject['name'], 'superproject') 254 self.assertEqual(manifest.superproject['name'], 'platform/superproject')
254 self.assertEqual(manifest.superproject['remote'].name, 'test-remote') 255 self.assertEqual(manifest.superproject['remote'].name, 'superproject-remote')
256 self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/platform/superproject')
255 self.assertEqual( 257 self.assertEqual(
256 manifest.ToXml().toxml(), 258 manifest.ToXml().toxml(),
257 '<?xml version="1.0" ?><manifest>' + 259 '<?xml version="1.0" ?><manifest>' +
258 '<remote name="default-remote" fetch="http://localhost"/>' + 260 '<remote name="default-remote" fetch="http://localhost"/>' +
259 '<remote name="test-remote" fetch="http://localhost"/>' + 261 '<remote name="superproject-remote" fetch="http://localhost"/>' +
260 '<default remote="default-remote" revision="refs/heads/main"/>' + 262 '<default remote="default-remote" revision="refs/heads/main"/>' +
261 '<superproject name="superproject" remote="test-remote"/>' + 263 '<superproject name="platform/superproject" remote="superproject-remote"/>' +
262 '</manifest>') 264 '</manifest>')
263 265
264 def test_superproject_with_defalut_remote(self): 266 def test_superproject_with_defalut_remote(self):