From 4e448015f3fda0c80a5e59dde38633a82ca880d1 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Mon, 19 Oct 2015 10:13:14 +0200 Subject: [PATCH] Increase the test coverage. --- tests/test_ha.py | 8 +++++++- tests/test_postgresql.py | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_ha.py b/tests/test_ha.py index a5a816dac..e34f9b8e6 100644 --- a/tests/test_ha.py +++ b/tests/test_ha.py @@ -1,7 +1,7 @@ import etcd import unittest -from mock import Mock, patch +from mock import Mock, MagicMock, patch from patroni.dcs import Cluster, Failover, Leader, Member from patroni.etcd import Client, Etcd from patroni.exceptions import DCSError, PostgresException @@ -130,6 +130,12 @@ def test_recover_master_failed(self): self.ha.has_lock = true self.assertEquals(self.ha.run_cycle(), 'removed leader key after trying and failing to start postgres') + @patch('sys.exit', return_value=1) + @patch('patroni.ha.Ha.sysid_valid', MagicMock(return_value=True)) + def test_sysid_no_match(self, exit_mock): + self.ha.run_cycle() + exit_mock.assert_called_once_with(1) + @patch.object(Cluster, 'is_unlocked', Mock(return_value=False)) def test_start_as_readonly(self): self.p.is_leader = self.p.is_healthy = false diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index 9a02ece69..544f8afde 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -429,3 +429,7 @@ def test_cleanup_archive_status(self, mock_file, mock_link, mock_remove, mock_un self.p.cleanup_archive_status() mock_unlink.assert_not_called() mock_remove.assert_not_called() + + @patch('subprocess.check_output', MagicMock(return_value=0, side_effect=pg_controldata_string)) + def test_sysid(self): + self.assertEqual(self.p.sysid, "6200971513092291716")