From 0e8598b5a985f3b20ce9ffefbaf6f6dc702724e0 Mon Sep 17 00:00:00 2001 From: Tom Haddon Date: Mon, 12 Nov 2018 14:48:45 +0000 Subject: Fix unit tests for bionic and later lp#1802926 --- unit_tests/test_hooks.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'unit_tests') 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): -- cgit v1.2.3