test_git.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import os
  2. import shutil
  3. from tests.download.gitremote import GitRemote
  4. import infra
  5. class GitTestBase(infra.basetest.BRConfigTest):
  6. config = \
  7. """
  8. BR2_BACKUP_SITE=""
  9. """
  10. gitremotedir = infra.filepath("tests/download/git-remote")
  11. gitremote = None
  12. def setUp(self):
  13. super(GitTestBase, self).setUp()
  14. self.gitremote = GitRemote(self.builddir, self.gitremotedir, self.logtofile)
  15. def tearDown(self):
  16. self.show_msg("Cleaning up")
  17. if self.gitremote:
  18. self.gitremote.stop()
  19. if self.b and not self.keepbuilds:
  20. self.b.delete()
  21. def check_hash(self, package):
  22. # store downloaded tarball inside the output dir so the test infra
  23. # cleans it up at the end
  24. env = {"BR2_DL_DIR": os.path.join(self.builddir, "dl"),
  25. "GITREMOTE_PORT_NUMBER": str(self.gitremote.port)}
  26. self.b.build(["{}-dirclean".format(package),
  27. "{}-source".format(package)],
  28. env)
  29. def check_download(self, package):
  30. # store downloaded tarball inside the output dir so the test infra
  31. # cleans it up at the end
  32. dl_dir = os.path.join(self.builddir, "dl")
  33. # enforce we test the download
  34. if os.path.exists(dl_dir):
  35. shutil.rmtree(dl_dir)
  36. env = {"BR2_DL_DIR": dl_dir,
  37. "GITREMOTE_PORT_NUMBER": str(self.gitremote.port)}
  38. self.b.build(["{}-dirclean".format(package),
  39. "{}-legal-info".format(package)],
  40. env)
  41. class TestGitHash(GitTestBase):
  42. br2_external = [infra.filepath("tests/download/br2-external/git-hash")]
  43. def test_run(self):
  44. with self.assertRaises(SystemError):
  45. self.check_hash("bad")
  46. self.check_hash("good")
  47. self.check_hash("nohash")
  48. class TestGitRefs(GitTestBase):
  49. br2_external = [infra.filepath("tests/download/br2-external/git-refs")]
  50. def test_run(self):
  51. with self.assertRaises(SystemError):
  52. self.check_download("git-wrong-content")
  53. with self.assertRaises(SystemError):
  54. self.check_download("git-wrong-sha1")
  55. self.check_download("git-partial-sha1-branch-head")
  56. self.check_download("git-partial-sha1-reachable-by-branch")
  57. self.check_download("git-partial-sha1-reachable-by-tag")
  58. self.check_download("git-partial-sha1-tag-itself")
  59. self.check_download("git-partial-sha1-tag-points-to")
  60. self.check_download("git-sha1-branch-head")
  61. self.check_download("git-sha1-reachable-by-branch")
  62. self.check_download("git-sha1-reachable-by-tag")
  63. self.check_download("git-sha1-tag-itself")
  64. self.check_download("git-sha1-tag-points-to")
  65. self.check_download("git-submodule-disabled")
  66. self.check_download("git-submodule-enabled")
  67. self.check_download("git-tag")