]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Add unit tests for configutil helpers 2438.magic-folder-stable.5.wip
authorDavid Stainton <dstainton415@gmail.com>
Thu, 10 Dec 2015 06:52:13 +0000 (08:52 +0200)
committerDaira Hopwood <daira@jacaranda.org>
Mon, 21 Dec 2015 21:44:30 +0000 (21:44 +0000)
src/allmydata/test/test_configutil.py [new file with mode: 0644]

diff --git a/src/allmydata/test/test_configutil.py b/src/allmydata/test/test_configutil.py
new file mode 100644 (file)
index 0000000..b6bb881
--- /dev/null
@@ -0,0 +1,34 @@
+import os.path
+
+from twisted.trial import unittest
+
+from allmydata.util import configutil, fileutil
+from allmydata.test.no_network import GridTestMixin
+from .test_cli import CLITestMixin
+
+
+class ConfigUtilTests(CLITestMixin, GridTestMixin, unittest.TestCase):
+
+    def test_config_utils(self):
+        self.basedir = "cli/ConfigUtilTests/test-config-utils"
+        self.set_up_grid()
+        tahoe_cfg = os.path.join(self.get_clientdir(i=0), "tahoe.cfg")
+
+        # test that at least one option was read correctly
+        config = configutil.get_config(tahoe_cfg)
+        self.failUnlessEqual(config.get("node", "nickname"), "client-0")
+
+        # test that set_config can mutate an existing option
+        configutil.set_config(config, "node", "nickname", "Alice!")
+        configutil.write_config(tahoe_cfg, config)
+
+        config = configutil.get_config(tahoe_cfg)
+        self.failUnlessEqual(config.get("node", "nickname"), "Alice!")
+
+        # test that set_config can set a new option
+        descriptor = "Twas brillig, and the slithy toves Did gyre and gimble in the wabe"
+        configutil.set_config(config, "node", "descriptor", descriptor)
+        configutil.write_config(tahoe_cfg, config)
+
+        config = configutil.get_config(tahoe_cfg)
+        self.failUnlessEqual(config.get("node", "descriptor"), descriptor)