test_git.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. self.check_hash("export-subst")
  49. with open(os.path.join(self.builddir, "dl", "export-subst", "git", "file2"), "r") as f:
  50. blob = f.read()
  51. self.assertEqual(blob, "0fdb95cf4f3c5ed4003287649cabb33c5f843e26\n")
  52. class TestGitRefs(GitTestBase):
  53. br2_external = [infra.filepath("tests/download/br2-external/git-refs")]
  54. def test_run(self):
  55. with self.assertRaises(SystemError):
  56. self.check_download("git-wrong-content")
  57. with self.assertRaises(SystemError):
  58. self.check_download("git-wrong-sha1")
  59. self.check_download("git-partial-sha1-branch-head")
  60. self.check_download("git-partial-sha1-reachable-by-branch")
  61. self.check_download("git-partial-sha1-reachable-by-tag")
  62. self.check_download("git-partial-sha1-tag-itself")
  63. self.check_download("git-partial-sha1-tag-points-to")
  64. self.check_download("git-sha1-branch-head")
  65. self.check_download("git-sha1-reachable-by-branch")
  66. self.check_download("git-sha1-reachable-by-tag")
  67. self.check_download("git-sha1-tag-itself")
  68. self.check_download("git-sha1-tag-points-to")
  69. self.check_download("git-submodule-disabled")
  70. self.check_download("git-submodule-enabled")
  71. self.check_download("git-tag")