summaryrefslogtreecommitdiffstats
path: root/tests/test_manifest_xml.py
diff options
context:
space:
mode:
authorMichael Kelly <mkelly@arista.com>2021-06-30 01:58:28 -0700
committerMichael Kelly <mkelly@arista.com>2021-07-08 16:48:21 +0000
commit06da9987f6be6ddc1637e8ae02646d6dfab09862 (patch)
treebe93f68a568f27341b61fa367a42dcdfe75df234 /tests/test_manifest_xml.py
parent58929732123780497ba08ed9c2d24f4bc65971a1 (diff)
downloadgit-repo-06da9987f6be6ddc1637e8ae02646d6dfab09862.tar.gz
Gracefully ignore bad remove-project line
Sometimes, we don't care if the remove project is referring to a non-existing project and we can just ignore it. This change allows us to ignore remove-project entries if the project that they refer to doesn't exist, making them effectively a no-op. Because this change breaks existing configuration, we allow this to be configuration controlled using the `optional` attribute in the remove-project tag. Change-Id: I6313a02983e81344eadcb4e47d7d6b037ee7420e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/310964 Tested-by: Michael Kelly <mkelly@arista.com> Reviewed-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'tests/test_manifest_xml.py')
-rw-r--r--tests/test_manifest_xml.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py
index 55468b51..96ee4c4a 100644
--- a/tests/test_manifest_xml.py
+++ b/tests/test_manifest_xml.py
@@ -638,3 +638,53 @@ class RemoteElementTests(ManifestParseTestCase):
638 self.assertNotEqual(a, manifest_xml._Default()) 638 self.assertNotEqual(a, manifest_xml._Default())
639 self.assertNotEqual(a, 123) 639 self.assertNotEqual(a, 123)
640 self.assertNotEqual(a, None) 640 self.assertNotEqual(a, None)
641
642
643class RemoveProjectElementTests(ManifestParseTestCase):
644 """Tests for <remove-project>."""
645
646 def test_remove_one_project(self):
647 manifest = self.getXmlManifest("""
648<manifest>
649 <remote name="default-remote" fetch="http://localhost" />
650 <default remote="default-remote" revision="refs/heads/main" />
651 <project name="myproject" />
652 <remove-project name="myproject" />
653</manifest>
654""")
655 self.assertEqual(manifest.projects, [])
656
657 def test_remove_one_project_one_remains(self):
658 manifest = self.getXmlManifest("""
659<manifest>
660 <remote name="default-remote" fetch="http://localhost" />
661 <default remote="default-remote" revision="refs/heads/main" />
662 <project name="myproject" />
663 <project name="yourproject" />
664 <remove-project name="myproject" />
665</manifest>
666""")
667
668 self.assertEqual(len(manifest.projects), 1)
669 self.assertEqual(manifest.projects[0].name, 'yourproject')
670
671 def test_remove_one_project_doesnt_exist(self):
672 with self.assertRaises(manifest_xml.ManifestParseError):
673 manifest = self.getXmlManifest("""
674<manifest>
675 <remote name="default-remote" fetch="http://localhost" />
676 <default remote="default-remote" revision="refs/heads/main" />
677 <remove-project name="myproject" />
678</manifest>
679""")
680 manifest.projects
681
682 def test_remove_one_optional_project_doesnt_exist(self):
683 manifest = self.getXmlManifest("""
684<manifest>
685 <remote name="default-remote" fetch="http://localhost" />
686 <default remote="default-remote" revision="refs/heads/main" />
687 <remove-project name="myproject" optional="true" />
688</manifest>
689""")
690 self.assertEqual(manifest.projects, [])