From de0497b72046624df7ab17f3c57628e38c7af452 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 14 Oct 2020 20:33:50 +0200 Subject: Add tests for keepalive-related functions Signed-off-by: Olivier Gayot --- tests/test_solter.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'tests/test_solter.py') diff --git a/tests/test_solter.py b/tests/test_solter.py index 5166a4f..6a41d50 100644 --- a/tests/test_solter.py +++ b/tests/test_solter.py @@ -13,3 +13,57 @@ class TestSolter(unittest.TestCase): with self.assertRaises(ValueError): solter.get_commands_send_data(sockfd=3, data='Hello\nWorld') + + def test_get_commands_change_tcp_option(self): + expected = ( + "set $rsp -= sizeof(int)", + "set {int}$rsp = 137", + "call (int)setsockopt(42, 6, 4, $rsp, sizeof(int))", + "set $rsp += sizeof(int)", + ) + self.assertEqual(solter._get_commands_change_tcp_option(sockfd=42, value=137, param=4), expected) + + def test_get_commands_enable_keepalive(self): + expected = ( + "set $rsp -= sizeof(int)", + "set {int}$rsp = 1", + "call (int)setsockopt(13, 1, 9, $rsp, sizeof(int))", + "set $rsp += sizeof(int)", + ) + self.assertEqual(solter.get_commands_enable_keepalive(sockfd=13), expected) + + def test_get_commands_disable_keepalive(self): + expected = ( + "set $rsp -= sizeof(int)", + "set {int}$rsp = 0", + "call (int)setsockopt(14, 1, 9, $rsp, sizeof(int))", + "set $rsp += sizeof(int)", + ) + self.assertEqual(solter.get_commands_disable_keepalive(sockfd=14), expected) + + def test_get_commands_change_keepalive_time(self): + expected = ( + "set $rsp -= sizeof(int)", + "set {int}$rsp = 60", + "call (int)setsockopt(15, 6, 4, $rsp, sizeof(int))", + "set $rsp += sizeof(int)", + ) + self.assertEqual(solter.get_commands_change_keepalive_time(sockfd=15, value=60), expected) + + def test_get_commands_change_keepalive_count(self): + expected = ( + "set $rsp -= sizeof(int)", + "set {int}$rsp = 10", + "call (int)setsockopt(16, 6, 6, $rsp, sizeof(int))", + "set $rsp += sizeof(int)", + ) + self.assertEqual(solter.get_commands_change_keepalive_count(sockfd=16, value=10), expected) + + def test_get_commands_change_keepalive_interval(self): + expected = ( + "set $rsp -= sizeof(int)", + "set {int}$rsp = 40", + "call (int)setsockopt(17, 6, 5, $rsp, sizeof(int))", + "set $rsp += sizeof(int)", + ) + self.assertEqual(solter.get_commands_change_keepalive_intvl(sockfd=17, value=40), expected) -- cgit v1.2.3