diff options
author | Tom Haddon <tom@haddons.net> | 2018-11-12 14:48:45 +0000 |
---|---|---|
committer | Tom Haddon <tom@haddons.net> | 2018-11-12 14:48:45 +0000 |
commit | 0e8598b5a985f3b20ce9ffefbaf6f6dc702724e0 (patch) | |
tree | b4b652d25c7ce385ec3593d7d4387615dfeeb8b8 | |
parent | b4929647582f90fec8596b9274249b33bc2d5b17 (diff) |
Fix unit tests for bionic and later lp#1802926
-rwxr-xr-x | hooks/hooks.py | 2 | ||||
-rw-r--r-- | unit_tests/test_hooks.py | 17 |
2 files changed, 17 insertions, 2 deletions
diff --git a/hooks/hooks.py b/hooks/hooks.py index fe4c4de..54902f5 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -539,7 +539,7 @@ def run_admin_command(client, cmdstr): def join_replset(master_node=None, host=None): - # TODO: This methoud shouldn't accept any arguments becase we don't care + # TODO: This method shouldn't accept any arguments because we don't care # about master_node - we always run replset admin commands on # localhost. # However, that might break other code calling this method. diff --git a/unit_tests/test_hooks.py b/unit_tests/test_hooks.py index 354d104..3432cfb 100644 --- a/unit_tests/test_hooks.py +++ b/unit_tests/test_hooks.py @@ -114,8 +114,13 @@ class MongoHooksTest(CharmTestCase): self.assertEqual(2, mock_run_admin_command.call_count) + @patch.object(hooks, 'run') + @patch.object(hooks, 'juju_log') + @patch.object(hooks, 'is_bionic_or_greater') @patch.object(hooks, 'mongo_client_smart') - def test_join_replset(self, mock_mongo_client): + def test_join_replset(self, mock_mongo_client, mock_is_bionic_or_greater, mock_juju_log, mock_run): + # Test with OS version not bionic or greater first. + mock_is_bionic_or_greater.return_value = False hooks.join_replset() self.assertFalse(mock_mongo_client.called) @@ -131,6 +136,16 @@ class MongoHooksTest(CharmTestCase): hooks.join_replset(master_node='mongo.local', host='fake-host') mock_mongo_client.assert_called_with('localhost', 'rs.add("fake-host")') + # Also test with bionic or greater. + old_mcr = hooks.MONGO_CLIENT_RETRIES + hooks.MONGO_CLIENT_RETRIES = 0 + mock_is_bionic_or_greater.return_value = True + mock_mongo_client.reset_mock() + hooks.join_replset(master_node='mongo.local', host='fake-host') + expected_run = ['mongo', '--quiet', '--host', "localhost", '--eval', 'printjson(rs.add("fake-host"))'] + mock_run.assert_called_with(expected_run) + # Restore mongo client retries for other tests. + hooks.MONGO_CLIENT_RETRIES = old_mcr @patch.object(hooks, 'mongo_client') def test_leave_replset(self, mock_mongo_client): |