diff options
Diffstat (limited to 'tests/test_git_superproject.py')
| -rw-r--r-- | tests/test_git_superproject.py | 782 |
1 files changed, 453 insertions, 329 deletions
diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py index b9b597a6..eb542c60 100644 --- a/tests/test_git_superproject.py +++ b/tests/test_git_superproject.py | |||
| @@ -28,297 +28,369 @@ from test_manifest_xml import sort_attributes | |||
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | class SuperprojectTestCase(unittest.TestCase): | 30 | class SuperprojectTestCase(unittest.TestCase): |
| 31 | """TestCase for the Superproject module.""" | 31 | """TestCase for the Superproject module.""" |
| 32 | 32 | ||
| 33 | PARENT_SID_KEY = 'GIT_TRACE2_PARENT_SID' | 33 | PARENT_SID_KEY = "GIT_TRACE2_PARENT_SID" |
| 34 | PARENT_SID_VALUE = 'parent_sid' | 34 | PARENT_SID_VALUE = "parent_sid" |
| 35 | SELF_SID_REGEX = r'repo-\d+T\d+Z-.*' | 35 | SELF_SID_REGEX = r"repo-\d+T\d+Z-.*" |
| 36 | FULL_SID_REGEX = r'^%s/%s' % (PARENT_SID_VALUE, SELF_SID_REGEX) | 36 | FULL_SID_REGEX = r"^%s/%s" % (PARENT_SID_VALUE, SELF_SID_REGEX) |
| 37 | 37 | ||
| 38 | def setUp(self): | 38 | def setUp(self): |
| 39 | """Set up superproject every time.""" | 39 | """Set up superproject every time.""" |
| 40 | self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests') | 40 | self.tempdirobj = tempfile.TemporaryDirectory(prefix="repo_tests") |
| 41 | self.tempdir = self.tempdirobj.name | 41 | self.tempdir = self.tempdirobj.name |
| 42 | self.repodir = os.path.join(self.tempdir, '.repo') | 42 | self.repodir = os.path.join(self.tempdir, ".repo") |
| 43 | self.manifest_file = os.path.join( | 43 | self.manifest_file = os.path.join( |
| 44 | self.repodir, manifest_xml.MANIFEST_FILE_NAME) | 44 | self.repodir, manifest_xml.MANIFEST_FILE_NAME |
| 45 | os.mkdir(self.repodir) | 45 | ) |
| 46 | self.platform = platform.system().lower() | 46 | os.mkdir(self.repodir) |
| 47 | 47 | self.platform = platform.system().lower() | |
| 48 | # By default we initialize with the expected case where | 48 | |
| 49 | # repo launches us (so GIT_TRACE2_PARENT_SID is set). | 49 | # By default we initialize with the expected case where |
| 50 | env = { | 50 | # repo launches us (so GIT_TRACE2_PARENT_SID is set). |
| 51 | self.PARENT_SID_KEY: self.PARENT_SID_VALUE, | 51 | env = { |
| 52 | } | 52 | self.PARENT_SID_KEY: self.PARENT_SID_VALUE, |
| 53 | self.git_event_log = git_trace2_event_log.EventLog(env=env) | 53 | } |
| 54 | 54 | self.git_event_log = git_trace2_event_log.EventLog(env=env) | |
| 55 | # The manifest parsing really wants a git repo currently. | 55 | |
| 56 | gitdir = os.path.join(self.repodir, 'manifests.git') | 56 | # The manifest parsing really wants a git repo currently. |
| 57 | os.mkdir(gitdir) | 57 | gitdir = os.path.join(self.repodir, "manifests.git") |
| 58 | with open(os.path.join(gitdir, 'config'), 'w') as fp: | 58 | os.mkdir(gitdir) |
| 59 | fp.write("""[remote "origin"] | 59 | with open(os.path.join(gitdir, "config"), "w") as fp: |
| 60 | fp.write( | ||
| 61 | """[remote "origin"] | ||
| 60 | url = https://localhost:0/manifest | 62 | url = https://localhost:0/manifest |
| 61 | """) | 63 | """ |
| 64 | ) | ||
| 62 | 65 | ||
| 63 | manifest = self.getXmlManifest(""" | 66 | manifest = self.getXmlManifest( |
| 67 | """ | ||
| 64 | <manifest> | 68 | <manifest> |
| 65 | <remote name="default-remote" fetch="http://localhost" /> | 69 | <remote name="default-remote" fetch="http://localhost" /> |
| 66 | <default remote="default-remote" revision="refs/heads/main" /> | 70 | <default remote="default-remote" revision="refs/heads/main" /> |
| 67 | <superproject name="superproject"/> | 71 | <superproject name="superproject"/> |
| 68 | <project path="art" name="platform/art" groups="notdefault,platform-""" + self.platform + """ | 72 | <project path="art" name="platform/art" groups="notdefault,platform-""" |
| 73 | + self.platform | ||
| 74 | + """ | ||
| 69 | " /></manifest> | 75 | " /></manifest> |
| 70 | """) | 76 | """ |
| 71 | self._superproject = git_superproject.Superproject( | 77 | ) |
| 72 | manifest, name='superproject', | 78 | self._superproject = git_superproject.Superproject( |
| 73 | remote=manifest.remotes.get('default-remote').ToRemoteSpec('superproject'), | 79 | manifest, |
| 74 | revision='refs/heads/main') | 80 | name="superproject", |
| 75 | 81 | remote=manifest.remotes.get("default-remote").ToRemoteSpec( | |
| 76 | def tearDown(self): | 82 | "superproject" |
| 77 | """Tear down superproject every time.""" | 83 | ), |
| 78 | self.tempdirobj.cleanup() | 84 | revision="refs/heads/main", |
| 79 | 85 | ) | |
| 80 | def getXmlManifest(self, data): | 86 | |
| 81 | """Helper to initialize a manifest for testing.""" | 87 | def tearDown(self): |
| 82 | with open(self.manifest_file, 'w') as fp: | 88 | """Tear down superproject every time.""" |
| 83 | fp.write(data) | 89 | self.tempdirobj.cleanup() |
| 84 | return manifest_xml.XmlManifest(self.repodir, self.manifest_file) | 90 | |
| 85 | 91 | def getXmlManifest(self, data): | |
| 86 | def verifyCommonKeys(self, log_entry, expected_event_name, full_sid=True): | 92 | """Helper to initialize a manifest for testing.""" |
| 87 | """Helper function to verify common event log keys.""" | 93 | with open(self.manifest_file, "w") as fp: |
| 88 | self.assertIn('event', log_entry) | 94 | fp.write(data) |
| 89 | self.assertIn('sid', log_entry) | 95 | return manifest_xml.XmlManifest(self.repodir, self.manifest_file) |
| 90 | self.assertIn('thread', log_entry) | 96 | |
| 91 | self.assertIn('time', log_entry) | 97 | def verifyCommonKeys(self, log_entry, expected_event_name, full_sid=True): |
| 92 | 98 | """Helper function to verify common event log keys.""" | |
| 93 | # Do basic data format validation. | 99 | self.assertIn("event", log_entry) |
| 94 | self.assertEqual(expected_event_name, log_entry['event']) | 100 | self.assertIn("sid", log_entry) |
| 95 | if full_sid: | 101 | self.assertIn("thread", log_entry) |
| 96 | self.assertRegex(log_entry['sid'], self.FULL_SID_REGEX) | 102 | self.assertIn("time", log_entry) |
| 97 | else: | 103 | |
| 98 | self.assertRegex(log_entry['sid'], self.SELF_SID_REGEX) | 104 | # Do basic data format validation. |
| 99 | self.assertRegex(log_entry['time'], r'^\d+-\d+-\d+T\d+:\d+:\d+\.\d+Z$') | 105 | self.assertEqual(expected_event_name, log_entry["event"]) |
| 100 | 106 | if full_sid: | |
| 101 | def readLog(self, log_path): | 107 | self.assertRegex(log_entry["sid"], self.FULL_SID_REGEX) |
| 102 | """Helper function to read log data into a list.""" | 108 | else: |
| 103 | log_data = [] | 109 | self.assertRegex(log_entry["sid"], self.SELF_SID_REGEX) |
| 104 | with open(log_path, mode='rb') as f: | 110 | self.assertRegex(log_entry["time"], r"^\d+-\d+-\d+T\d+:\d+:\d+\.\d+Z$") |
| 105 | for line in f: | 111 | |
| 106 | log_data.append(json.loads(line)) | 112 | def readLog(self, log_path): |
| 107 | return log_data | 113 | """Helper function to read log data into a list.""" |
| 108 | 114 | log_data = [] | |
| 109 | def verifyErrorEvent(self): | 115 | with open(log_path, mode="rb") as f: |
| 110 | """Helper to verify that error event is written.""" | 116 | for line in f: |
| 111 | 117 | log_data.append(json.loads(line)) | |
| 112 | with tempfile.TemporaryDirectory(prefix='event_log_tests') as tempdir: | 118 | return log_data |
| 113 | log_path = self.git_event_log.Write(path=tempdir) | 119 | |
| 114 | self.log_data = self.readLog(log_path) | 120 | def verifyErrorEvent(self): |
| 115 | 121 | """Helper to verify that error event is written.""" | |
| 116 | self.assertEqual(len(self.log_data), 2) | 122 | |
| 117 | error_event = self.log_data[1] | 123 | with tempfile.TemporaryDirectory(prefix="event_log_tests") as tempdir: |
| 118 | self.verifyCommonKeys(self.log_data[0], expected_event_name='version') | 124 | log_path = self.git_event_log.Write(path=tempdir) |
| 119 | self.verifyCommonKeys(error_event, expected_event_name='error') | 125 | self.log_data = self.readLog(log_path) |
| 120 | # Check for 'error' event specific fields. | 126 | |
| 121 | self.assertIn('msg', error_event) | 127 | self.assertEqual(len(self.log_data), 2) |
| 122 | self.assertIn('fmt', error_event) | 128 | error_event = self.log_data[1] |
| 123 | 129 | self.verifyCommonKeys(self.log_data[0], expected_event_name="version") | |
| 124 | def test_superproject_get_superproject_no_superproject(self): | 130 | self.verifyCommonKeys(error_event, expected_event_name="error") |
| 125 | """Test with no url.""" | 131 | # Check for 'error' event specific fields. |
| 126 | manifest = self.getXmlManifest(""" | 132 | self.assertIn("msg", error_event) |
| 133 | self.assertIn("fmt", error_event) | ||
| 134 | |||
| 135 | def test_superproject_get_superproject_no_superproject(self): | ||
| 136 | """Test with no url.""" | ||
| 137 | manifest = self.getXmlManifest( | ||
| 138 | """ | ||
| 127 | <manifest> | 139 | <manifest> |
| 128 | </manifest> | 140 | </manifest> |
| 129 | """) | 141 | """ |
| 130 | self.assertIsNone(manifest.superproject) | 142 | ) |
| 131 | 143 | self.assertIsNone(manifest.superproject) | |
| 132 | def test_superproject_get_superproject_invalid_url(self): | 144 | |
| 133 | """Test with an invalid url.""" | 145 | def test_superproject_get_superproject_invalid_url(self): |
| 134 | manifest = self.getXmlManifest(""" | 146 | """Test with an invalid url.""" |
| 147 | manifest = self.getXmlManifest( | ||
| 148 | """ | ||
| 135 | <manifest> | 149 | <manifest> |
| 136 | <remote name="test-remote" fetch="localhost" /> | 150 | <remote name="test-remote" fetch="localhost" /> |
| 137 | <default remote="test-remote" revision="refs/heads/main" /> | 151 | <default remote="test-remote" revision="refs/heads/main" /> |
| 138 | <superproject name="superproject"/> | 152 | <superproject name="superproject"/> |
| 139 | </manifest> | 153 | </manifest> |
| 140 | """) | 154 | """ |
| 141 | superproject = git_superproject.Superproject( | 155 | ) |
| 142 | manifest, name='superproject', | 156 | superproject = git_superproject.Superproject( |
| 143 | remote=manifest.remotes.get('test-remote').ToRemoteSpec('superproject'), | 157 | manifest, |
| 144 | revision='refs/heads/main') | 158 | name="superproject", |
| 145 | sync_result = superproject.Sync(self.git_event_log) | 159 | remote=manifest.remotes.get("test-remote").ToRemoteSpec( |
| 146 | self.assertFalse(sync_result.success) | 160 | "superproject" |
| 147 | self.assertTrue(sync_result.fatal) | 161 | ), |
| 148 | 162 | revision="refs/heads/main", | |
| 149 | def test_superproject_get_superproject_invalid_branch(self): | 163 | ) |
| 150 | """Test with an invalid branch.""" | 164 | sync_result = superproject.Sync(self.git_event_log) |
| 151 | manifest = self.getXmlManifest(""" | 165 | self.assertFalse(sync_result.success) |
| 166 | self.assertTrue(sync_result.fatal) | ||
| 167 | |||
| 168 | def test_superproject_get_superproject_invalid_branch(self): | ||
| 169 | """Test with an invalid branch.""" | ||
| 170 | manifest = self.getXmlManifest( | ||
| 171 | """ | ||
| 152 | <manifest> | 172 | <manifest> |
| 153 | <remote name="test-remote" fetch="localhost" /> | 173 | <remote name="test-remote" fetch="localhost" /> |
| 154 | <default remote="test-remote" revision="refs/heads/main" /> | 174 | <default remote="test-remote" revision="refs/heads/main" /> |
| 155 | <superproject name="superproject"/> | 175 | <superproject name="superproject"/> |
| 156 | </manifest> | 176 | </manifest> |
| 157 | """) | 177 | """ |
| 158 | self._superproject = git_superproject.Superproject( | 178 | ) |
| 159 | manifest, name='superproject', | 179 | self._superproject = git_superproject.Superproject( |
| 160 | remote=manifest.remotes.get('test-remote').ToRemoteSpec('superproject'), | 180 | manifest, |
| 161 | revision='refs/heads/main') | 181 | name="superproject", |
| 162 | with mock.patch.object(self._superproject, '_branch', 'junk'): | 182 | remote=manifest.remotes.get("test-remote").ToRemoteSpec( |
| 163 | sync_result = self._superproject.Sync(self.git_event_log) | 183 | "superproject" |
| 164 | self.assertFalse(sync_result.success) | 184 | ), |
| 165 | self.assertTrue(sync_result.fatal) | 185 | revision="refs/heads/main", |
| 166 | self.verifyErrorEvent() | 186 | ) |
| 167 | 187 | with mock.patch.object(self._superproject, "_branch", "junk"): | |
| 168 | def test_superproject_get_superproject_mock_init(self): | 188 | sync_result = self._superproject.Sync(self.git_event_log) |
| 169 | """Test with _Init failing.""" | 189 | self.assertFalse(sync_result.success) |
| 170 | with mock.patch.object(self._superproject, '_Init', return_value=False): | 190 | self.assertTrue(sync_result.fatal) |
| 171 | sync_result = self._superproject.Sync(self.git_event_log) | 191 | self.verifyErrorEvent() |
| 172 | self.assertFalse(sync_result.success) | 192 | |
| 173 | self.assertTrue(sync_result.fatal) | 193 | def test_superproject_get_superproject_mock_init(self): |
| 174 | 194 | """Test with _Init failing.""" | |
| 175 | def test_superproject_get_superproject_mock_fetch(self): | 195 | with mock.patch.object(self._superproject, "_Init", return_value=False): |
| 176 | """Test with _Fetch failing.""" | 196 | sync_result = self._superproject.Sync(self.git_event_log) |
| 177 | with mock.patch.object(self._superproject, '_Init', return_value=True): | 197 | self.assertFalse(sync_result.success) |
| 178 | os.mkdir(self._superproject._superproject_path) | 198 | self.assertTrue(sync_result.fatal) |
| 179 | with mock.patch.object(self._superproject, '_Fetch', return_value=False): | 199 | |
| 180 | sync_result = self._superproject.Sync(self.git_event_log) | 200 | def test_superproject_get_superproject_mock_fetch(self): |
| 181 | self.assertFalse(sync_result.success) | 201 | """Test with _Fetch failing.""" |
| 182 | self.assertTrue(sync_result.fatal) | 202 | with mock.patch.object(self._superproject, "_Init", return_value=True): |
| 183 | 203 | os.mkdir(self._superproject._superproject_path) | |
| 184 | def test_superproject_get_all_project_commit_ids_mock_ls_tree(self): | 204 | with mock.patch.object( |
| 185 | """Test with LsTree being a mock.""" | 205 | self._superproject, "_Fetch", return_value=False |
| 186 | data = ('120000 blob 158258bdf146f159218e2b90f8b699c4d85b5804\tAndroid.bp\x00' | 206 | ): |
| 187 | '160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00' | 207 | sync_result = self._superproject.Sync(self.git_event_log) |
| 188 | '160000 commit e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06\tbootable/recovery\x00' | 208 | self.assertFalse(sync_result.success) |
| 189 | '120000 blob acc2cbdf438f9d2141f0ae424cec1d8fc4b5d97f\tbootstrap.bash\x00' | 209 | self.assertTrue(sync_result.fatal) |
| 190 | '160000 commit ade9b7a0d874e25fff4bf2552488825c6f111928\tbuild/bazel\x00') | 210 | |
| 191 | with mock.patch.object(self._superproject, '_Init', return_value=True): | 211 | def test_superproject_get_all_project_commit_ids_mock_ls_tree(self): |
| 192 | with mock.patch.object(self._superproject, '_Fetch', return_value=True): | 212 | """Test with LsTree being a mock.""" |
| 193 | with mock.patch.object(self._superproject, '_LsTree', return_value=data): | 213 | data = ( |
| 194 | commit_ids_result = self._superproject._GetAllProjectsCommitIds() | 214 | "120000 blob 158258bdf146f159218e2b90f8b699c4d85b5804\tAndroid.bp\x00" |
| 195 | self.assertEqual(commit_ids_result.commit_ids, { | 215 | "160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00" |
| 196 | 'art': '2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea', | 216 | "160000 commit e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06\tbootable/recovery\x00" |
| 197 | 'bootable/recovery': 'e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06', | 217 | "120000 blob acc2cbdf438f9d2141f0ae424cec1d8fc4b5d97f\tbootstrap.bash\x00" |
| 198 | 'build/bazel': 'ade9b7a0d874e25fff4bf2552488825c6f111928' | 218 | "160000 commit ade9b7a0d874e25fff4bf2552488825c6f111928\tbuild/bazel\x00" |
| 199 | }) | 219 | ) |
| 200 | self.assertFalse(commit_ids_result.fatal) | 220 | with mock.patch.object(self._superproject, "_Init", return_value=True): |
| 201 | 221 | with mock.patch.object( | |
| 202 | def test_superproject_write_manifest_file(self): | 222 | self._superproject, "_Fetch", return_value=True |
| 203 | """Test with writing manifest to a file after setting revisionId.""" | 223 | ): |
| 204 | self.assertEqual(len(self._superproject._manifest.projects), 1) | 224 | with mock.patch.object( |
| 205 | project = self._superproject._manifest.projects[0] | 225 | self._superproject, "_LsTree", return_value=data |
| 206 | project.SetRevisionId('ABCDEF') | 226 | ): |
| 207 | # Create temporary directory so that it can write the file. | 227 | commit_ids_result = ( |
| 208 | os.mkdir(self._superproject._superproject_path) | 228 | self._superproject._GetAllProjectsCommitIds() |
| 209 | manifest_path = self._superproject._WriteManifestFile() | 229 | ) |
| 210 | self.assertIsNotNone(manifest_path) | 230 | self.assertEqual( |
| 211 | with open(manifest_path, 'r') as fp: | 231 | commit_ids_result.commit_ids, |
| 212 | manifest_xml_data = fp.read() | 232 | { |
| 213 | self.assertEqual( | 233 | "art": "2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea", |
| 214 | sort_attributes(manifest_xml_data), | 234 | "bootable/recovery": "e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06", |
| 215 | '<?xml version="1.0" ?><manifest>' | 235 | "build/bazel": "ade9b7a0d874e25fff4bf2552488825c6f111928", |
| 216 | '<remote fetch="http://localhost" name="default-remote"/>' | 236 | }, |
| 217 | '<default remote="default-remote" revision="refs/heads/main"/>' | 237 | ) |
| 218 | '<project groups="notdefault,platform-' + self.platform + '" ' | 238 | self.assertFalse(commit_ids_result.fatal) |
| 219 | 'name="platform/art" path="art" revision="ABCDEF" upstream="refs/heads/main"/>' | 239 | |
| 220 | '<superproject name="superproject"/>' | 240 | def test_superproject_write_manifest_file(self): |
| 221 | '</manifest>') | 241 | """Test with writing manifest to a file after setting revisionId.""" |
| 222 | 242 | self.assertEqual(len(self._superproject._manifest.projects), 1) | |
| 223 | def test_superproject_update_project_revision_id(self): | 243 | project = self._superproject._manifest.projects[0] |
| 224 | """Test with LsTree being a mock.""" | 244 | project.SetRevisionId("ABCDEF") |
| 225 | self.assertEqual(len(self._superproject._manifest.projects), 1) | 245 | # Create temporary directory so that it can write the file. |
| 226 | projects = self._superproject._manifest.projects | 246 | os.mkdir(self._superproject._superproject_path) |
| 227 | data = ('160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00' | 247 | manifest_path = self._superproject._WriteManifestFile() |
| 228 | '160000 commit e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06\tbootable/recovery\x00') | 248 | self.assertIsNotNone(manifest_path) |
| 229 | with mock.patch.object(self._superproject, '_Init', return_value=True): | 249 | with open(manifest_path, "r") as fp: |
| 230 | with mock.patch.object(self._superproject, '_Fetch', return_value=True): | ||
| 231 | with mock.patch.object(self._superproject, | ||
| 232 | '_LsTree', | ||
| 233 | return_value=data): | ||
| 234 | # Create temporary directory so that it can write the file. | ||
| 235 | os.mkdir(self._superproject._superproject_path) | ||
| 236 | update_result = self._superproject.UpdateProjectsRevisionId(projects, self.git_event_log) | ||
| 237 | self.assertIsNotNone(update_result.manifest_path) | ||
| 238 | self.assertFalse(update_result.fatal) | ||
| 239 | with open(update_result.manifest_path, 'r') as fp: | ||
| 240 | manifest_xml_data = fp.read() | 250 | manifest_xml_data = fp.read() |
| 241 | self.assertEqual( | 251 | self.assertEqual( |
| 242 | sort_attributes(manifest_xml_data), | 252 | sort_attributes(manifest_xml_data), |
| 243 | '<?xml version="1.0" ?><manifest>' | 253 | '<?xml version="1.0" ?><manifest>' |
| 244 | '<remote fetch="http://localhost" name="default-remote"/>' | 254 | '<remote fetch="http://localhost" name="default-remote"/>' |
| 245 | '<default remote="default-remote" revision="refs/heads/main"/>' | 255 | '<default remote="default-remote" revision="refs/heads/main"/>' |
| 246 | '<project groups="notdefault,platform-' + self.platform + '" ' | 256 | '<project groups="notdefault,platform-' + self.platform + '" ' |
| 247 | 'name="platform/art" path="art" ' | 257 | 'name="platform/art" path="art" revision="ABCDEF" upstream="refs/heads/main"/>' |
| 248 | 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" upstream="refs/heads/main"/>' | 258 | '<superproject name="superproject"/>' |
| 249 | '<superproject name="superproject"/>' | 259 | "</manifest>", |
| 250 | '</manifest>') | 260 | ) |
| 251 | 261 | ||
| 252 | def test_superproject_update_project_revision_id_no_superproject_tag(self): | 262 | def test_superproject_update_project_revision_id(self): |
| 253 | """Test update of commit ids of a manifest without superproject tag.""" | 263 | """Test with LsTree being a mock.""" |
| 254 | manifest = self.getXmlManifest(""" | 264 | self.assertEqual(len(self._superproject._manifest.projects), 1) |
| 265 | projects = self._superproject._manifest.projects | ||
| 266 | data = ( | ||
| 267 | "160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00" | ||
| 268 | "160000 commit e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06\tbootable/recovery\x00" | ||
| 269 | ) | ||
| 270 | with mock.patch.object(self._superproject, "_Init", return_value=True): | ||
| 271 | with mock.patch.object( | ||
| 272 | self._superproject, "_Fetch", return_value=True | ||
| 273 | ): | ||
| 274 | with mock.patch.object( | ||
| 275 | self._superproject, "_LsTree", return_value=data | ||
| 276 | ): | ||
| 277 | # Create temporary directory so that it can write the file. | ||
| 278 | os.mkdir(self._superproject._superproject_path) | ||
| 279 | update_result = self._superproject.UpdateProjectsRevisionId( | ||
| 280 | projects, self.git_event_log | ||
| 281 | ) | ||
| 282 | self.assertIsNotNone(update_result.manifest_path) | ||
| 283 | self.assertFalse(update_result.fatal) | ||
| 284 | with open(update_result.manifest_path, "r") as fp: | ||
| 285 | manifest_xml_data = fp.read() | ||
| 286 | self.assertEqual( | ||
| 287 | sort_attributes(manifest_xml_data), | ||
| 288 | '<?xml version="1.0" ?><manifest>' | ||
| 289 | '<remote fetch="http://localhost" name="default-remote"/>' | ||
| 290 | '<default remote="default-remote" revision="refs/heads/main"/>' | ||
| 291 | '<project groups="notdefault,platform-' | ||
| 292 | + self.platform | ||
| 293 | + '" ' | ||
| 294 | 'name="platform/art" path="art" ' | ||
| 295 | 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" upstream="refs/heads/main"/>' | ||
| 296 | '<superproject name="superproject"/>' | ||
| 297 | "</manifest>", | ||
| 298 | ) | ||
| 299 | |||
| 300 | def test_superproject_update_project_revision_id_no_superproject_tag(self): | ||
| 301 | """Test update of commit ids of a manifest without superproject tag.""" | ||
| 302 | manifest = self.getXmlManifest( | ||
| 303 | """ | ||
| 255 | <manifest> | 304 | <manifest> |
| 256 | <remote name="default-remote" fetch="http://localhost" /> | 305 | <remote name="default-remote" fetch="http://localhost" /> |
| 257 | <default remote="default-remote" revision="refs/heads/main" /> | 306 | <default remote="default-remote" revision="refs/heads/main" /> |
| 258 | <project name="test-name"/> | 307 | <project name="test-name"/> |
| 259 | </manifest> | 308 | </manifest> |
| 260 | """) | 309 | """ |
| 261 | self.maxDiff = None | 310 | ) |
| 262 | self.assertIsNone(manifest.superproject) | 311 | self.maxDiff = None |
| 263 | self.assertEqual( | 312 | self.assertIsNone(manifest.superproject) |
| 264 | sort_attributes(manifest.ToXml().toxml()), | 313 | self.assertEqual( |
| 265 | '<?xml version="1.0" ?><manifest>' | 314 | sort_attributes(manifest.ToXml().toxml()), |
| 266 | '<remote fetch="http://localhost" name="default-remote"/>' | 315 | '<?xml version="1.0" ?><manifest>' |
| 267 | '<default remote="default-remote" revision="refs/heads/main"/>' | 316 | '<remote fetch="http://localhost" name="default-remote"/>' |
| 268 | '<project name="test-name"/>' | 317 | '<default remote="default-remote" revision="refs/heads/main"/>' |
| 269 | '</manifest>') | 318 | '<project name="test-name"/>' |
| 270 | 319 | "</manifest>", | |
| 271 | def test_superproject_update_project_revision_id_from_local_manifest_group(self): | 320 | ) |
| 272 | """Test update of commit ids of a manifest that have local manifest no superproject group.""" | 321 | |
| 273 | local_group = manifest_xml.LOCAL_MANIFEST_GROUP_PREFIX + ':local' | 322 | def test_superproject_update_project_revision_id_from_local_manifest_group( |
| 274 | manifest = self.getXmlManifest(""" | 323 | self, |
| 324 | ): | ||
| 325 | """Test update of commit ids of a manifest that have local manifest no superproject group.""" | ||
| 326 | local_group = manifest_xml.LOCAL_MANIFEST_GROUP_PREFIX + ":local" | ||
| 327 | manifest = self.getXmlManifest( | ||
| 328 | """ | ||
| 275 | <manifest> | 329 | <manifest> |
| 276 | <remote name="default-remote" fetch="http://localhost" /> | 330 | <remote name="default-remote" fetch="http://localhost" /> |
| 277 | <remote name="goog" fetch="http://localhost2" /> | 331 | <remote name="goog" fetch="http://localhost2" /> |
| 278 | <default remote="default-remote" revision="refs/heads/main" /> | 332 | <default remote="default-remote" revision="refs/heads/main" /> |
| 279 | <superproject name="superproject"/> | 333 | <superproject name="superproject"/> |
| 280 | <project path="vendor/x" name="platform/vendor/x" remote="goog" | 334 | <project path="vendor/x" name="platform/vendor/x" remote="goog" |
| 281 | groups=\"""" + local_group + """ | 335 | groups=\"""" |
| 336 | + local_group | ||
| 337 | + """ | ||
| 282 | " revision="master-with-vendor" clone-depth="1" /> | 338 | " revision="master-with-vendor" clone-depth="1" /> |
| 283 | <project path="art" name="platform/art" groups="notdefault,platform-""" + self.platform + """ | 339 | <project path="art" name="platform/art" groups="notdefault,platform-""" |
| 340 | + self.platform | ||
| 341 | + """ | ||
| 284 | " /></manifest> | 342 | " /></manifest> |
| 285 | """) | 343 | """ |
| 286 | self.maxDiff = None | 344 | ) |
| 287 | self._superproject = git_superproject.Superproject( | 345 | self.maxDiff = None |
| 288 | manifest, name='superproject', | 346 | self._superproject = git_superproject.Superproject( |
| 289 | remote=manifest.remotes.get('default-remote').ToRemoteSpec('superproject'), | 347 | manifest, |
| 290 | revision='refs/heads/main') | 348 | name="superproject", |
| 291 | self.assertEqual(len(self._superproject._manifest.projects), 2) | 349 | remote=manifest.remotes.get("default-remote").ToRemoteSpec( |
| 292 | projects = self._superproject._manifest.projects | 350 | "superproject" |
| 293 | data = ('160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00') | 351 | ), |
| 294 | with mock.patch.object(self._superproject, '_Init', return_value=True): | 352 | revision="refs/heads/main", |
| 295 | with mock.patch.object(self._superproject, '_Fetch', return_value=True): | 353 | ) |
| 296 | with mock.patch.object(self._superproject, | 354 | self.assertEqual(len(self._superproject._manifest.projects), 2) |
| 297 | '_LsTree', | 355 | projects = self._superproject._manifest.projects |
| 298 | return_value=data): | 356 | data = "160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00" |
| 299 | # Create temporary directory so that it can write the file. | 357 | with mock.patch.object(self._superproject, "_Init", return_value=True): |
| 300 | os.mkdir(self._superproject._superproject_path) | 358 | with mock.patch.object( |
| 301 | update_result = self._superproject.UpdateProjectsRevisionId(projects, self.git_event_log) | 359 | self._superproject, "_Fetch", return_value=True |
| 302 | self.assertIsNotNone(update_result.manifest_path) | 360 | ): |
| 303 | self.assertFalse(update_result.fatal) | 361 | with mock.patch.object( |
| 304 | with open(update_result.manifest_path, 'r') as fp: | 362 | self._superproject, "_LsTree", return_value=data |
| 305 | manifest_xml_data = fp.read() | 363 | ): |
| 306 | # Verify platform/vendor/x's project revision hasn't changed. | 364 | # Create temporary directory so that it can write the file. |
| 307 | self.assertEqual( | 365 | os.mkdir(self._superproject._superproject_path) |
| 308 | sort_attributes(manifest_xml_data), | 366 | update_result = self._superproject.UpdateProjectsRevisionId( |
| 309 | '<?xml version="1.0" ?><manifest>' | 367 | projects, self.git_event_log |
| 310 | '<remote fetch="http://localhost" name="default-remote"/>' | 368 | ) |
| 311 | '<remote fetch="http://localhost2" name="goog"/>' | 369 | self.assertIsNotNone(update_result.manifest_path) |
| 312 | '<default remote="default-remote" revision="refs/heads/main"/>' | 370 | self.assertFalse(update_result.fatal) |
| 313 | '<project groups="notdefault,platform-' + self.platform + '" ' | 371 | with open(update_result.manifest_path, "r") as fp: |
| 314 | 'name="platform/art" path="art" ' | 372 | manifest_xml_data = fp.read() |
| 315 | 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" upstream="refs/heads/main"/>' | 373 | # Verify platform/vendor/x's project revision hasn't |
| 316 | '<superproject name="superproject"/>' | 374 | # changed. |
| 317 | '</manifest>') | 375 | self.assertEqual( |
| 318 | 376 | sort_attributes(manifest_xml_data), | |
| 319 | def test_superproject_update_project_revision_id_with_pinned_manifest(self): | 377 | '<?xml version="1.0" ?><manifest>' |
| 320 | """Test update of commit ids of a pinned manifest.""" | 378 | '<remote fetch="http://localhost" name="default-remote"/>' |
| 321 | manifest = self.getXmlManifest(""" | 379 | '<remote fetch="http://localhost2" name="goog"/>' |
| 380 | '<default remote="default-remote" revision="refs/heads/main"/>' | ||
| 381 | '<project groups="notdefault,platform-' | ||
| 382 | + self.platform | ||
| 383 | + '" ' | ||
| 384 | 'name="platform/art" path="art" ' | ||
| 385 | 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" upstream="refs/heads/main"/>' | ||
| 386 | '<superproject name="superproject"/>' | ||
| 387 | "</manifest>", | ||
| 388 | ) | ||
| 389 | |||
| 390 | def test_superproject_update_project_revision_id_with_pinned_manifest(self): | ||
| 391 | """Test update of commit ids of a pinned manifest.""" | ||
| 392 | manifest = self.getXmlManifest( | ||
| 393 | """ | ||
| 322 | <manifest> | 394 | <manifest> |
| 323 | <remote name="default-remote" fetch="http://localhost" /> | 395 | <remote name="default-remote" fetch="http://localhost" /> |
| 324 | <default remote="default-remote" revision="refs/heads/main" /> | 396 | <default remote="default-remote" revision="refs/heads/main" /> |
| @@ -326,80 +398,132 @@ class SuperprojectTestCase(unittest.TestCase): | |||
| 326 | <project path="vendor/x" name="platform/vendor/x" revision="" /> | 398 | <project path="vendor/x" name="platform/vendor/x" revision="" /> |
| 327 | <project path="vendor/y" name="platform/vendor/y" | 399 | <project path="vendor/y" name="platform/vendor/y" |
| 328 | revision="52d3c9f7c107839ece2319d077de0cd922aa9d8f" /> | 400 | revision="52d3c9f7c107839ece2319d077de0cd922aa9d8f" /> |
| 329 | <project path="art" name="platform/art" groups="notdefault,platform-""" + self.platform + """ | 401 | <project path="art" name="platform/art" groups="notdefault,platform-""" |
| 402 | + self.platform | ||
| 403 | + """ | ||
| 330 | " /></manifest> | 404 | " /></manifest> |
| 331 | """) | 405 | """ |
| 332 | self.maxDiff = None | 406 | ) |
| 333 | self._superproject = git_superproject.Superproject( | 407 | self.maxDiff = None |
| 334 | manifest, name='superproject', | 408 | self._superproject = git_superproject.Superproject( |
| 335 | remote=manifest.remotes.get('default-remote').ToRemoteSpec('superproject'), | 409 | manifest, |
| 336 | revision='refs/heads/main') | 410 | name="superproject", |
| 337 | self.assertEqual(len(self._superproject._manifest.projects), 3) | 411 | remote=manifest.remotes.get("default-remote").ToRemoteSpec( |
| 338 | projects = self._superproject._manifest.projects | 412 | "superproject" |
| 339 | data = ('160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00' | 413 | ), |
| 340 | '160000 commit e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06\tvendor/x\x00') | 414 | revision="refs/heads/main", |
| 341 | with mock.patch.object(self._superproject, '_Init', return_value=True): | 415 | ) |
| 342 | with mock.patch.object(self._superproject, '_Fetch', return_value=True): | 416 | self.assertEqual(len(self._superproject._manifest.projects), 3) |
| 343 | with mock.patch.object(self._superproject, | 417 | projects = self._superproject._manifest.projects |
| 344 | '_LsTree', | 418 | data = ( |
| 345 | return_value=data): | 419 | "160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00" |
| 346 | # Create temporary directory so that it can write the file. | 420 | "160000 commit e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06\tvendor/x\x00" |
| 347 | os.mkdir(self._superproject._superproject_path) | 421 | ) |
| 348 | update_result = self._superproject.UpdateProjectsRevisionId(projects, self.git_event_log) | 422 | with mock.patch.object(self._superproject, "_Init", return_value=True): |
| 349 | self.assertIsNotNone(update_result.manifest_path) | 423 | with mock.patch.object( |
| 350 | self.assertFalse(update_result.fatal) | 424 | self._superproject, "_Fetch", return_value=True |
| 351 | with open(update_result.manifest_path, 'r') as fp: | 425 | ): |
| 352 | manifest_xml_data = fp.read() | 426 | with mock.patch.object( |
| 353 | # Verify platform/vendor/x's project revision hasn't changed. | 427 | self._superproject, "_LsTree", return_value=data |
| 354 | self.assertEqual( | 428 | ): |
| 355 | sort_attributes(manifest_xml_data), | 429 | # Create temporary directory so that it can write the file. |
| 356 | '<?xml version="1.0" ?><manifest>' | 430 | os.mkdir(self._superproject._superproject_path) |
| 357 | '<remote fetch="http://localhost" name="default-remote"/>' | 431 | update_result = self._superproject.UpdateProjectsRevisionId( |
| 358 | '<default remote="default-remote" revision="refs/heads/main"/>' | 432 | projects, self.git_event_log |
| 359 | '<project groups="notdefault,platform-' + self.platform + '" ' | 433 | ) |
| 360 | 'name="platform/art" path="art" ' | 434 | self.assertIsNotNone(update_result.manifest_path) |
| 361 | 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" upstream="refs/heads/main"/>' | 435 | self.assertFalse(update_result.fatal) |
| 362 | '<project name="platform/vendor/x" path="vendor/x" ' | 436 | with open(update_result.manifest_path, "r") as fp: |
| 363 | 'revision="e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06" upstream="refs/heads/main"/>' | 437 | manifest_xml_data = fp.read() |
| 364 | '<project name="platform/vendor/y" path="vendor/y" ' | 438 | # Verify platform/vendor/x's project revision hasn't |
| 365 | 'revision="52d3c9f7c107839ece2319d077de0cd922aa9d8f"/>' | 439 | # changed. |
| 366 | '<superproject name="superproject"/>' | 440 | self.assertEqual( |
| 367 | '</manifest>') | 441 | sort_attributes(manifest_xml_data), |
| 368 | 442 | '<?xml version="1.0" ?><manifest>' | |
| 369 | def test_Fetch(self): | 443 | '<remote fetch="http://localhost" name="default-remote"/>' |
| 370 | manifest = self.getXmlManifest(""" | 444 | '<default remote="default-remote" revision="refs/heads/main"/>' |
| 445 | '<project groups="notdefault,platform-' | ||
| 446 | + self.platform | ||
| 447 | + '" ' | ||
| 448 | 'name="platform/art" path="art" ' | ||
| 449 | 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" upstream="refs/heads/main"/>' | ||
| 450 | '<project name="platform/vendor/x" path="vendor/x" ' | ||
| 451 | 'revision="e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06" upstream="refs/heads/main"/>' | ||
| 452 | '<project name="platform/vendor/y" path="vendor/y" ' | ||
| 453 | 'revision="52d3c9f7c107839ece2319d077de0cd922aa9d8f"/>' | ||
| 454 | '<superproject name="superproject"/>' | ||
| 455 | "</manifest>", | ||
| 456 | ) | ||
| 457 | |||
| 458 | def test_Fetch(self): | ||
| 459 | manifest = self.getXmlManifest( | ||
| 460 | """ | ||
| 371 | <manifest> | 461 | <manifest> |
| 372 | <remote name="default-remote" fetch="http://localhost" /> | 462 | <remote name="default-remote" fetch="http://localhost" /> |
| 373 | <default remote="default-remote" revision="refs/heads/main" /> | 463 | <default remote="default-remote" revision="refs/heads/main" /> |
| 374 | <superproject name="superproject"/> | 464 | <superproject name="superproject"/> |
| 375 | " /></manifest> | 465 | " /></manifest> |
| 376 | """) | 466 | """ |
| 377 | self.maxDiff = None | 467 | ) |
| 378 | self._superproject = git_superproject.Superproject( | 468 | self.maxDiff = None |
| 379 | manifest, name='superproject', | 469 | self._superproject = git_superproject.Superproject( |
| 380 | remote=manifest.remotes.get('default-remote').ToRemoteSpec('superproject'), | 470 | manifest, |
| 381 | revision='refs/heads/main') | 471 | name="superproject", |
| 382 | os.mkdir(self._superproject._superproject_path) | 472 | remote=manifest.remotes.get("default-remote").ToRemoteSpec( |
| 383 | os.mkdir(self._superproject._work_git) | 473 | "superproject" |
| 384 | with mock.patch.object(self._superproject, '_Init', return_value=True): | 474 | ), |
| 385 | with mock.patch('git_superproject.GitCommand', autospec=True) as mock_git_command: | 475 | revision="refs/heads/main", |
| 386 | with mock.patch('git_superproject.GitRefs.get', autospec=True) as mock_git_refs: | 476 | ) |
| 387 | instance = mock_git_command.return_value | 477 | os.mkdir(self._superproject._superproject_path) |
| 388 | instance.Wait.return_value = 0 | 478 | os.mkdir(self._superproject._work_git) |
| 389 | mock_git_refs.side_effect = ['', '1234'] | 479 | with mock.patch.object(self._superproject, "_Init", return_value=True): |
| 390 | 480 | with mock.patch( | |
| 391 | self.assertTrue(self._superproject._Fetch()) | 481 | "git_superproject.GitCommand", autospec=True |
| 392 | self.assertEqual(mock_git_command.call_args.args,(None, [ | 482 | ) as mock_git_command: |
| 393 | 'fetch', 'http://localhost/superproject', '--depth', '1', | 483 | with mock.patch( |
| 394 | '--force', '--no-tags', '--filter', 'blob:none', | 484 | "git_superproject.GitRefs.get", autospec=True |
| 395 | 'refs/heads/main:refs/heads/main' | 485 | ) as mock_git_refs: |
| 396 | ])) | 486 | instance = mock_git_command.return_value |
| 397 | 487 | instance.Wait.return_value = 0 | |
| 398 | # If branch for revision exists, set as --negotiation-tip. | 488 | mock_git_refs.side_effect = ["", "1234"] |
| 399 | self.assertTrue(self._superproject._Fetch()) | 489 | |
| 400 | self.assertEqual(mock_git_command.call_args.args,(None, [ | 490 | self.assertTrue(self._superproject._Fetch()) |
| 401 | 'fetch', 'http://localhost/superproject', '--depth', '1', | 491 | self.assertEqual( |
| 402 | '--force', '--no-tags', '--filter', 'blob:none', | 492 | mock_git_command.call_args.args, |
| 403 | '--negotiation-tip', '1234', | 493 | ( |
| 404 | 'refs/heads/main:refs/heads/main' | 494 | None, |
| 405 | ])) | 495 | [ |
| 496 | "fetch", | ||
| 497 | "http://localhost/superproject", | ||
| 498 | "--depth", | ||
| 499 | "1", | ||
| 500 | "--force", | ||
| 501 | "--no-tags", | ||
| 502 | "--filter", | ||
| 503 | "blob:none", | ||
| 504 | "refs/heads/main:refs/heads/main", | ||
| 505 | ], | ||
| 506 | ), | ||
| 507 | ) | ||
| 508 | |||
| 509 | # If branch for revision exists, set as --negotiation-tip. | ||
| 510 | self.assertTrue(self._superproject._Fetch()) | ||
| 511 | self.assertEqual( | ||
| 512 | mock_git_command.call_args.args, | ||
| 513 | ( | ||
| 514 | None, | ||
| 515 | [ | ||
| 516 | "fetch", | ||
| 517 | "http://localhost/superproject", | ||
| 518 | "--depth", | ||
| 519 | "1", | ||
| 520 | "--force", | ||
| 521 | "--no-tags", | ||
| 522 | "--filter", | ||
| 523 | "blob:none", | ||
| 524 | "--negotiation-tip", | ||
| 525 | "1234", | ||
| 526 | "refs/heads/main:refs/heads/main", | ||
| 527 | ], | ||
| 528 | ), | ||
| 529 | ) | ||
