summaryrefslogtreecommitdiff
path: root/unit_tests
diff options
Diffstat (limited to 'unit_tests')
-rw-r--r--unit_tests/test_hooks.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/unit_tests/test_hooks.py b/unit_tests/test_hooks.py
index 85331f7..aad1a96 100644
--- a/unit_tests/test_hooks.py
+++ b/unit_tests/test_hooks.py
@@ -7,6 +7,9 @@ from test_utils import mock_open
from pymongo.errors import OperationFailure
from subprocess import CalledProcessError
+import tempfile
+import os
+
# Defines a set of functions to patch on the hooks object. Any of these
# methods will be patched by default on the default invocations of the
# hooks.some_func(). Invoking the the interface change relations will cause
@@ -357,3 +360,26 @@ class MongoHooksTest(CharmTestCase):
with mock_open('/etc/mongodb.conf', test_config):
results = hooks.get_current_mongo_config()
self.assertEqual(results, expected)
+
+ def test_remove_replset_from_upstart(self):
+ test_contents = u"""
+--exec /usr/bin/mongod -- --replSet myset --rest --config /etc/mongodb.conf
+ """
+ expected = u"""
+--exec /usr/bin/mongod -- --rest --config /etc/mongodb.conf
+ """
+
+ mocked_upstart = tempfile.NamedTemporaryFile(delete=False)
+ hooks.default_mongodb_init_config = mocked_upstart.name
+
+ try:
+ mocked_upstart.write(test_contents)
+ mocked_upstart.close()
+
+ hooks.remove_replset_from_upstart()
+
+ with open(hooks.default_mongodb_init_config) as changed_upstart:
+ changed_contents = changed_upstart.read()
+ self.assertEqual(changed_contents, expected)
+ finally:
+ os.unlink(mocked_upstart.name)