Browse Source

Fix dul-receive-pack and dul-upload-pack.

Jelmer Vernooij 14 years ago
parent
commit
d77e80b8bf
5 changed files with 76 additions and 30 deletions
  1. 2 0
      NEWS
  2. 2 15
      bin/dul-receive-pack
  3. 2 15
      bin/dul-upload-pack
  4. 26 0
      dulwich/tests/__init__.py
  5. 44 0
      dulwich/tests/test_blackbox.py

+ 2 - 0
NEWS

@@ -19,6 +19,8 @@
   * Support parsing git mbox patches without a version tail, as generated by
     Mercurial.  (Jelmer Vernooij)
 
+  * Fix dul-receive-pack and dul-upload-pack. (Jelmer Vernooij)
+
  DOCUMENTATION
 
   * Run the tutorial inside the test suite. (Jelmer Vernooij)

+ 2 - 15
bin/dul-receive-pack

@@ -17,19 +17,6 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 
+from dulwich.server import serve_command, ReceivePackHandler
 import sys
-from dulwich.repo import Repo
-from dulwich.server import GitBackend, ReceivePackHandler
-
-def send_fn(data):
-    sys.stdout.write(data)
-    sys.stdout.flush()
-
-if __name__ == "__main__":
-    gitdir = None
-    if len(sys.argv) > 1:
-        gitdir = sys.argv[1]
-
-    backend = GitBackend(Repo(gitdir))
-    handler = ReceivePackHandler(backend, sys.stdin.read, send_fn)
-    handler.handle()
+sys.exit(serve_command(ReceivePackHandler))

+ 2 - 15
bin/dul-upload-pack

@@ -17,19 +17,6 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 
+from dulwich.server import serve_command, UploadPackHandler
 import sys
-from dulwich.repo import Repo
-from dulwich.server import GitBackend, UploadPackHandler
-
-def send_fn(data):
-    sys.stdout.write(data)
-    sys.stdout.flush()
-
-if __name__ == "__main__":
-    gitdir = None
-    if len(sys.argv) > 1:
-        gitdir = sys.argv[1]
-
-    backend = GitBackend(Repo(gitdir))
-    handler = UploadPackHandler(backend, sys.stdin.read, send_fn)
-    handler.handle()
+sys.exit(serve_command(UploadPackHandler))

+ 26 - 0
dulwich/tests/__init__.py

@@ -57,8 +57,34 @@ except ImportError:
             testtools.testcase.TestCase.skipException = TestSkipped
 
 
+class BlackboxTestCase(TestCase):
+    """Blackbox testing."""
+
+    bin_directory = os.path.abspath(os.path.join(os.path.dirname(__file__),
+        "..", "..", "bin"))
+
+    def bin_path(self, name):
+        """Determine the full path of a binary.
+
+        :param name: Name of the script
+        :return: Full path
+        """
+        return os.path.join(self.bin_directory, name)
+
+    def run_command(self, name, args):
+        """Run a Dulwich command.
+
+        :param name: Name of the command, as it exists in bin/
+        :param args: Arguments to the command
+        """
+        import subprocess
+        return subprocess.Popen([self.bin_path(name)] + args, stdout=subprocess.PIPE,
+            stdin=subprocess.PIPE, stderr=subprocess.PIPE)
+
+
 def test_suite():
     names = [
+        'blackbox',
         'client',
         'fastexport',
         'file',

+ 44 - 0
dulwich/tests/test_blackbox.py

@@ -0,0 +1,44 @@
+# test_blackbox.py -- blackbox tests
+# Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2
+# of the License or (at your option) a later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.
+
+"""Blackbox tests for Dulwich commands."""
+
+import tempfile
+
+from dulwich.repo import (
+    Repo,
+    )
+from dulwich.tests import (
+    BlackboxTestCase,
+    )
+
+
+class GitReceivePackTests(BlackboxTestCase):
+    """Blackbox tests for dul-receive-pack."""
+
+    def setUp(self):
+        super(GitReceivePackTests, self).setUp()
+        self.path = tempfile.mkdtemp()
+        self.repo = Repo.init(self.path)
+
+    def test_basic(self):
+        process = self.run_command("dul-receive-pack", [self.path])
+        (stdout, stderr) = process.communicate("0000")
+        self.assertEquals('', stderr)
+        self.assertEquals('0000', stdout[-4:])
+        self.assertEquals(0, process.returncode)