Merge ~mthaddon/charm-mongodb/+git/mongodb-charm:fix-tests into ~mongodb-charmers/charm-mongodb:master

Proposed by Tom Haddon
Status: Merged
Approved by: Jamon Camisso
Approved revision: 0e8598b5a985f3b20ce9ffefbaf6f6dc702724e0
Merged at revision: f04914ab678d2808d0bd8d22386fe5f2f3657470
Proposed branch: ~mthaddon/charm-mongodb/+git/mongodb-charm:fix-tests
Merge into: ~mongodb-charmers/charm-mongodb:master
Diff against target: 49 lines (+17/-2)
2 files modified
hooks/hooks.py (+1/-1)
unit_tests/test_hooks.py (+16/-1)
Reviewer Review Type Date Requested Status
Martin Hilton (community) Approve
MongoDB Charm Maintainers Pending
Review via email: mp+358641@code.launchpad.net

Commit message

Fix unit tests for bionic and later lp#1802926

Description of the change

Fix unit tests for bionic and later lp#1802926

Drive-by typo fix in hooks/hooks.py

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Martin Hilton (martin-hilton) wrote :

LGTM

review: Approve
Revision history for this message
Jamon Camisso (jamon) wrote :

Looks good, tests pass, +1'ed.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision f04914ab678d2808d0bd8d22386fe5f2f3657470

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/hooks.py b/hooks/hooks.py
2index fe4c4de..54902f5 100755
3--- a/hooks/hooks.py
4+++ b/hooks/hooks.py
5@@ -539,7 +539,7 @@ def run_admin_command(client, cmdstr):
6
7
8 def join_replset(master_node=None, host=None):
9- # TODO: This methoud shouldn't accept any arguments becase we don't care
10+ # TODO: This method shouldn't accept any arguments because we don't care
11 # about master_node - we always run replset admin commands on
12 # localhost.
13 # However, that might break other code calling this method.
14diff --git a/unit_tests/test_hooks.py b/unit_tests/test_hooks.py
15index 354d104..3432cfb 100644
16--- a/unit_tests/test_hooks.py
17+++ b/unit_tests/test_hooks.py
18@@ -114,8 +114,13 @@ class MongoHooksTest(CharmTestCase):
19
20 self.assertEqual(2, mock_run_admin_command.call_count)
21
22+ @patch.object(hooks, 'run')
23+ @patch.object(hooks, 'juju_log')
24+ @patch.object(hooks, 'is_bionic_or_greater')
25 @patch.object(hooks, 'mongo_client_smart')
26- def test_join_replset(self, mock_mongo_client):
27+ def test_join_replset(self, mock_mongo_client, mock_is_bionic_or_greater, mock_juju_log, mock_run):
28+ # Test with OS version not bionic or greater first.
29+ mock_is_bionic_or_greater.return_value = False
30 hooks.join_replset()
31 self.assertFalse(mock_mongo_client.called)
32
33@@ -131,6 +136,16 @@ class MongoHooksTest(CharmTestCase):
34 hooks.join_replset(master_node='mongo.local', host='fake-host')
35 mock_mongo_client.assert_called_with('localhost',
36 'rs.add("fake-host")')
37+ # Also test with bionic or greater.
38+ old_mcr = hooks.MONGO_CLIENT_RETRIES
39+ hooks.MONGO_CLIENT_RETRIES = 0
40+ mock_is_bionic_or_greater.return_value = True
41+ mock_mongo_client.reset_mock()
42+ hooks.join_replset(master_node='mongo.local', host='fake-host')
43+ expected_run = ['mongo', '--quiet', '--host', "localhost", '--eval', 'printjson(rs.add("fake-host"))']
44+ mock_run.assert_called_with(expected_run)
45+ # Restore mongo client retries for other tests.
46+ hooks.MONGO_CLIENT_RETRIES = old_mcr
47
48 @patch.object(hooks, 'mongo_client')
49 def test_leave_replset(self, mock_mongo_client):

Subscribers

People subscribed via source and target branches

to status/vote changes: