import unittest
from construct import Container

from pysyncthing.protocol import packet


class TestClusterConfigMessage(unittest.TestCase):

    EXAMPLE1 = "\x00\x01\x00\x01\x00\x00\x00>\x00\x00\x00:8\x00\x00\x00\xe1\x00\x00\x00\tsyncthing\x00\x01\x00\x81\x07v0.10.5\r\x00\xf0\t\x00\x00\x00\x01\x00\x00\x00\x04name\x00\x00\x00\x07example\x00"

    def test_parse_example1(self):
        p = packet.parse(self.EXAMPLE1)
        self.assertEqual(p.header.message_type, 0)
        self.assertEqual(p.payload.client_name, "syncthing")
        self.assertEqual(p.payload.client_version, "v0.10.5")

    def test_build_example1(self):
        self.assertEqual(self.EXAMPLE1, packet.build(Container(
            header=Container(
                message_version=0,
                message_id=1,
                message_type=0,
                compressed=True,
            ),
            payload=Container(
                client_name='syncthing',
                client_version='v0.10.5',
                folders=[],
                options={
                    "name": "example",
                }
            ),
        )))

@@ -163,25 +163,25 @@
 0%5Cx01%5Cx00%5Cx0
-1
+0
 %5Cx00%5Cx00%5Cx00
@@ -184,39 +184,9 @@
 %5Cx00
-%3E%5Cx00%5Cx00%5Cx00:8%5Cx00%5Cx00%5Cx00%5Cxe1
+8
 %5Cx00
@@ -215,17 +215,25 @@
 0%5Cx0
-1
+0
 %5Cx00%5Cx
-81
+00%5Cx00%5Cx00
 %5Cx07
@@ -244,19 +244,27 @@
 0.5%5C
-r
+x00
 %5Cx00%5Cx
-f0%5Ct
+00%5Cx00%5Cx00
 %5Cx00
@@ -832,11 +832,12 @@
 sed=
-Tru
+Fals
 e,%0A 

Fix tests