Commit 120e7e77 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Add unittest for RPC compression


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 764ff2eb
......@@ -33,6 +33,7 @@ from ganeti import http
from ganeti import errors
from ganeti import serializer
from ganeti import objects
from ganeti import backend
import testutils
......@@ -448,5 +449,25 @@ class TestNodeConfigResolver(unittest.TestCase):
])
class TestCompress(unittest.TestCase):
def test(self):
for data in ["", "Hello", "Hello World!\nnew\nlines"]:
self.assertEqual(rpc._Compress(data),
(constants.RPC_ENCODING_NONE, data))
for data in [512 * " ", 5242 * "Hello World!\n"]:
compressed = rpc._Compress(data)
self.assertEqual(len(compressed), 2)
self.assertEqual(backend._Decompress(compressed), data)
def testDecompression(self):
self.assertRaises(AssertionError, backend._Decompress, "")
self.assertRaises(AssertionError, backend._Decompress, [""])
self.assertRaises(AssertionError, backend._Decompress,
("unknown compression", "data"))
self.assertRaises(Exception, backend._Decompress,
(constants.RPC_ENCODING_ZLIB_BASE64, "invalid zlib data"))
if __name__ == "__main__":
testutils.GanetiTestProgram()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment