test_git.py 3.0 KB

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