summaryrefslogtreecommitdiff
path: root/unit_tests
diff options
authorMario Splivalo <mario.splivalo@canonical.com>2017-01-09 18:29:01 +0100
committerMario Splivalo <mario.splivalo@canonical.com>2017-01-09 18:29:01 +0100
commita0e0f45faa600d9819c5d6305538231ceb30ffd8 (patch)
tree05568022bff0f4e7780117a530c8275dde37a010 /unit_tests
parent6693ed2da0b9421840d57b99b01c86d3510f60a4 (diff)
Added unit test for remove_replset_from_upstart()
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)