Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/172206

Change subject: Add unit tests for pybal.ipvs.LVSService
......................................................................

Add unit tests for pybal.ipvs.LVSService

No tests for the four methods that add / edit / delete services yet.
I'll do those in a separate patch.

Change-Id: Ifbe36db977df19ddd1f7c3f51991ffefb8d55798
---
M tests/test_ipvs.py
1 file changed, 41 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/debs/pybal 
refs/changes/06/172206/1

diff --git a/tests/test_ipvs.py b/tests/test_ipvs.py
index 653fecc..0361304 100644
--- a/tests/test_ipvs.py
+++ b/tests/test_ipvs.py
@@ -9,14 +9,16 @@
 import unittest
 
 import pybal.ipvs
+import pybal.util
 
 
 class ServerStub(object):
     """Test stub for `pybal.Server`."""
-    def __init__(self, host, ip=None, weight=None):
+    def __init__(self, host, ip=None, weight=None, port=None):
         self.host = host
         self.ip = ip
         self.weight = weight
+        self.port = port
 
 
 class IPVSManagerTestCase(unittest.TestCase):
@@ -102,3 +104,41 @@
         subcommand = pybal.ipvs.IPVSManager.commandEditServer(service, server)
         self.assertEquals(
             subcommand, '-e -t [2620::123]:443 -r localhost -w 25')
+
+
+class LVSServiceTestCase(unittest.TestCase):
+    """Test case for `pybal.ipvs.LVSService`."""
+
+    def setUp(self):
+        self.config = pybal.util.ConfigDict({'dryrun': 'true'})
+        self.service = ('tcp', '127.0.0.1', 80, 'rr')
+
+    def testConstructor(self):
+        """Test `LVSService.__init__`."""
+        with self.assertRaises(ValueError):
+            service = ('invalid-protocol', '127.0.0.1', 80, 'rr')
+            pybal.ipvs.LVSService('invalid-protocol', service, self.config)
+
+        with self.assertRaises(ValueError):
+            service = ('tcp', '127.0.0.1', 80, 'invalid-scheduler')
+            pybal.ipvs.LVSService('invalid-scheduler', service, self.config)
+
+    def testService(self):
+        """Test `LVSService.service`."""
+        lvs_service = pybal.ipvs.LVSService('http', self.service, self.config)
+        self.assertEquals(lvs_service.service(), self.service)
+
+    def testInitServer(self):
+        """Test `LVSService.initServer`."""
+        lvs_service = pybal.ipvs.LVSService('http', self.service, self.config)
+        server = ServerStub('localhost', port=8080)
+        lvs_service.initServer(server)
+        self.assertEquals(server.port, 80)
+
+    def testGetDepoolThreshold(self):
+        """Test `LVSService.getDepoolThreshold`."""
+        lvs = pybal.ipvs.LVSService('test', self.service, self.config)
+        self.assertEquals(lvs.getDepoolThreshold(), 0.5)
+        self.config['depool-threshold'] = 0.25
+        lvs = pybal.ipvs.LVSService('test', self.service, self.config)
+        self.assertEquals(lvs.getDepoolThreshold(), 0.25)

-- 
To view, visit https://gerrit.wikimedia.org/r/172206
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifbe36db977df19ddd1f7c3f51991ffefb8d55798
Gerrit-PatchSet: 1
Gerrit-Project: operations/debs/pybal
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to