test_server.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # test_server.py -- Compatibility tests for git server.
  2. # Copyright (C) 2010 Google, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; version 2
  7. # of the License or (at your option) any later version of
  8. # the License.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. # MA 02110-1301, USA.
  19. """Compatibility tests between Dulwich and the cgit server.
  20. Warning: these tests should be fairly stable, but when writing/debugging new
  21. tests, deadlocks may freeze the test process such that it cannot be
  22. Ctrl-C'ed. On POSIX systems, you can kill the tests with Ctrl-Z, "kill %".
  23. """
  24. import threading
  25. from dulwich.server import (
  26. DictBackend,
  27. TCPGitServer,
  28. )
  29. from dulwich.tests.compat.server_utils import (
  30. ServerTests,
  31. NoSideBand64kReceivePackHandler,
  32. )
  33. from dulwich.tests.compat.utils import (
  34. CompatTestCase,
  35. )
  36. class GitServerTestCase(ServerTests, CompatTestCase):
  37. """Tests for client/server compatibility.
  38. This server test case does not use side-band-64k in git-receive-pack.
  39. """
  40. protocol = 'git'
  41. def _handlers(self):
  42. return {'git-receive-pack': NoSideBand64kReceivePackHandler}
  43. def _check_server(self, dul_server):
  44. receive_pack_handler_cls = dul_server.handlers['git-receive-pack']
  45. caps = receive_pack_handler_cls.capabilities()
  46. self.assertFalse('side-band-64k' in caps)
  47. def _start_server(self, repo):
  48. backend = DictBackend({'/': repo})
  49. dul_server = TCPGitServer(backend, 'localhost', 0,
  50. handlers=self._handlers())
  51. self._check_server(dul_server)
  52. self.addCleanup(dul_server.shutdown)
  53. self.addCleanup(dul_server.server_close)
  54. threading.Thread(target=dul_server.serve).start()
  55. self._server = dul_server
  56. _, port = self._server.socket.getsockname()
  57. return port
  58. class GitServerSideBand64kTestCase(GitServerTestCase):
  59. """Tests for client/server compatibility with side-band-64k support."""
  60. # side-band-64k in git-receive-pack was introduced in git 1.7.0.2
  61. min_git_version = (1, 7, 0, 2)
  62. def _handlers(self):
  63. return None # default handlers include side-band-64k
  64. def _check_server(self, server):
  65. receive_pack_handler_cls = server.handlers['git-receive-pack']
  66. caps = receive_pack_handler_cls.capabilities()
  67. self.assertTrue('side-band-64k' in caps)