test_git.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import os
  2. from gitremote import GitRemote
  3. import infra
  4. class GitTestBase(infra.basetest.BRTest):
  5. config = \
  6. """
  7. BR2_BACKUP_SITE=""
  8. """
  9. gitremotedir = infra.filepath("tests/download/git-remote")
  10. gitremote = None
  11. def setUp(self):
  12. super(GitTestBase, self).setUp()
  13. self.gitremote = GitRemote(self.builddir, self.gitremotedir, self.logtofile)
  14. def tearDown(self):
  15. self.show_msg("Cleaning up")
  16. if self.gitremote:
  17. self.gitremote.stop()
  18. if self.b and not self.keepbuilds:
  19. self.b.delete()
  20. def check_hash(self, package):
  21. # store downloaded tarball inside the output dir so the test infra
  22. # cleans it up at the end
  23. env = {"BR2_DL_DIR": os.path.join(self.builddir, "dl"),
  24. "GITREMOTE_PORT_NUMBER": str(self.gitremote.port)}
  25. self.b.build(["{}-dirclean".format(package),
  26. "{}-source".format(package)],
  27. env)
  28. def check_download(self, package):
  29. # store downloaded tarball inside the output dir so the test infra
  30. # cleans it up at the end
  31. env = {"BR2_DL_DIR": os.path.join(self.builddir, "dl"),
  32. "GITREMOTE_PORT_NUMBER": str(self.gitremote.port)}
  33. self.b.build(["{}-dirclean".format(package),
  34. "{}-legal-info".format(package)],
  35. env)
  36. class TestGitHash(GitTestBase):
  37. br2_external = [infra.filepath("tests/download/br2-external/git-hash")]
  38. def test_run(self):
  39. with self.assertRaises(SystemError):
  40. self.check_hash("bad")
  41. self.check_hash("good")
  42. self.check_hash("nohash")
  43. class TestGitRefs(GitTestBase):
  44. br2_external = [infra.filepath("tests/download/br2-external/git-refs")]
  45. def test_run(self):
  46. with self.assertRaises(SystemError):
  47. self.check_download("git-wrong-content")
  48. with self.assertRaises(SystemError):
  49. self.check_download("git-wrong-sha1")