|
@@ -0,0 +1,82 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+from cStringIO import StringIO
|
|
|
+from unittest import TestCase
|
|
|
+
|
|
|
+from dulwich.protocol import (
|
|
|
+ Protocol,
|
|
|
+ extract_capabilities,
|
|
|
+ )
|
|
|
+
|
|
|
+class ProtocolTests(TestCase):
|
|
|
+
|
|
|
+ def setUp(self):
|
|
|
+ self.rout = StringIO()
|
|
|
+ self.rin = StringIO()
|
|
|
+ self.proto = Protocol(self.rin.read, self.rout.write)
|
|
|
+
|
|
|
+ def test_write_pkt_line_none(self):
|
|
|
+ self.proto.write_pkt_line(None)
|
|
|
+ self.assertEquals(self.rout.getvalue(), "0000")
|
|
|
+
|
|
|
+ def test_write_pkt_line(self):
|
|
|
+ self.proto.write_pkt_line("bla")
|
|
|
+ self.assertEquals(self.rout.getvalue(), "0007bla")
|
|
|
+
|
|
|
+ def test_read_pkt_line(self):
|
|
|
+ self.rin.write("0008cmd ")
|
|
|
+ self.rin.seek(0)
|
|
|
+ self.assertEquals("cmd ", self.proto.read_pkt_line())
|
|
|
+
|
|
|
+ def test_read_pkt_seq(self):
|
|
|
+ self.rin.write("0008cmd 0005l0000")
|
|
|
+ self.rin.seek(0)
|
|
|
+ self.assertEquals(["cmd ", "l"], list(self.proto.read_pkt_seq()))
|
|
|
+
|
|
|
+ def test_read_pkt_line_none(self):
|
|
|
+ self.rin.write("0000")
|
|
|
+ self.rin.seek(0)
|
|
|
+ self.assertEquals(None, self.proto.read_pkt_line())
|
|
|
+
|
|
|
+ def test_write_sideband(self):
|
|
|
+ self.proto.write_sideband(3, "bloe")
|
|
|
+ self.assertEquals(self.rout.getvalue(), "0009\x03bloe")
|
|
|
+
|
|
|
+ def test_send_cmd(self):
|
|
|
+ self.proto.send_cmd("fetch", "a", "b")
|
|
|
+ self.assertEquals(self.rout.getvalue(), "000efetch a\x00b\x00")
|
|
|
+
|
|
|
+ def test_read_cmd(self):
|
|
|
+ self.rin.write("0012cmd arg1\x00arg2\x00")
|
|
|
+ self.rin.seek(0)
|
|
|
+ self.assertEquals(("cmd", ["arg1", "arg2"]), self.proto.read_cmd())
|
|
|
+
|
|
|
+ def test_read_cmd_noend0(self):
|
|
|
+ self.rin.write("0011cmd arg1\x00arg2")
|
|
|
+ self.rin.seek(0)
|
|
|
+ self.assertRaises(AssertionError, self.proto.read_cmd)
|
|
|
+
|
|
|
+
|
|
|
+class ExtractCapabilitiesTestCase(TestCase):
|
|
|
+
|
|
|
+ def test_plain(self):
|
|
|
+ self.assertEquals(("bla", None), extract_capabilities("bla"))
|
|
|
+
|
|
|
+ def test_caps(self):
|
|
|
+ self.assertEquals(("bla", ["la", "la"]), extract_capabilities("bla\0la\0la"))
|