]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_node.py: refactor test_location* to reduce code duplication. refs #754
authorDaira Hopwood <daira@jacaranda.org>
Mon, 9 Feb 2015 19:45:31 +0000 (19:45 +0000)
committerDaira Hopwood <daira@jacaranda.org>
Tue, 10 Feb 2015 17:12:43 +0000 (17:12 +0000)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/test/test_node.py

index 88303f2a63c319c70c97fc8a353c880d1f6a085a..cf7d0f57d222cf6d43ae8d50ee55a3c9d8e68b46 100644 (file)
@@ -33,12 +33,14 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
         d.addCallback(flushEventualQueue)
         return d
 
-    def test_location(self):
-        basedir = "test_node/test_location"
+    def _test_location(self, basedir, expected_addresses, tub_port=None, tub_location=None):
         fileutil.make_dirs(basedir)
         f = open(os.path.join(basedir, 'tahoe.cfg'), 'wt')
         f.write("[node]\n")
-        f.write("tub.location = 1.2.3.4:5\n")
+        if tub_port:
+            f.write("tub.port = %d\n" % (tub_port,))
+        if tub_location is not None:
+            f.write("tub.location = %s\n" % (tub_location,))
         f.close()
 
         n = TestNode(basedir)
@@ -47,30 +49,22 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
 
         def _check_addresses(ignored_result):
             furl = n.tub.registerReference(n)
-            self.failUnless("1.2.3.4:5" in furl, furl)
+            for address in expected_addresses:
+                self.failUnlessIn(address, furl)
 
         d.addCallback(_check_addresses)
         return d
 
-    def test_location2(self):
-        basedir = "test_node/test_location2"
-        fileutil.make_dirs(basedir)
-        f = open(os.path.join(basedir, 'tahoe.cfg'), 'wt')
-        f.write("[node]\n")
-        f.write("tub.location = 1.2.3.4:5,example.org:8091\n")
-        f.close()
-
-        n = TestNode(basedir)
-        n.setServiceParent(self.parent)
-        d = n.when_tub_ready()
+    def test_location1(self):
+        return self._test_location(basedir="test_node/test_location1",
+                                   expected_addresses=["192.0.2.0:1234"],
+                                   tub_location="192.0.2.0:1234")
 
-        def _check_addresses(ignored_result):
-            furl = n.tub.registerReference(n)
-            self.failUnless("1.2.3.4:5" in furl, furl)
-            self.failUnless("example.org:8091" in furl, furl)
+    def test_location2(self):
+        return self._test_location(basedir="test_node/test_location2",
+                                   expected_addresses=["192.0.2.0:1234", "example.org:8091"],
+                                   tub_location="192.0.2.0:1234,example.org:8091")
 
-        d.addCallback(_check_addresses)
-        return d
 
     def test_tahoe_cfg_utf8(self):
         basedir = "test_node/test_tahoe_cfg_utf8"