From 0355884f3503306590bbdd71551e61ebf0210021 Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Mon, 20 Apr 2015 09:19:08 +0100 Subject: [PATCH] added unit test --- config.yaml | 2 +- unit_tests/test_rabbitmq_server_relations.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/config.yaml b/config.yaml index 45e073f8..c0067eb8 100644 --- a/config.yaml +++ b/config.yaml @@ -171,4 +171,4 @@ options: default: description: | Minimum number of units expected to exist before charm will attempt to - form a cluster. + form a rabbitmq cluster. diff --git a/unit_tests/test_rabbitmq_server_relations.py b/unit_tests/test_rabbitmq_server_relations.py index 4f3b881c..b7af05f6 100644 --- a/unit_tests/test_rabbitmq_server_relations.py +++ b/unit_tests/test_rabbitmq_server_relations.py @@ -129,3 +129,20 @@ class RelationUtil(TestCase): mock_peer_store_and_set.assert_called_with( relation_settings={'private-address': ipv6_addr}, relation_id=None) + + @patch.object(rabbitmq_server_relations, 'related_units') + @patch.object(rabbitmq_server_relations, 'relation_ids') + @patch.object(rabbitmq_server_relations, 'config') + def test_is_sufficient_peers(self, mock_config, mock_relation_ids, + mock_related_units): + _config = {'min-cluster-size': None} + mock_config.side_effect = lambda key: _config.get(key) + self.assertTrue(rabbitmq_server_relations.is_sufficient_peers()) + + mock_relation_ids.return_value = ['cluster:0'] + mock_related_units.return_value = ['test/0'] + _config = {'min-cluster-size': 3} + self.assertFalse(rabbitmq_server_relations.is_sufficient_peers()) + + mock_related_units.return_value = ['test/0', 'test/1'] + self.assertTrue(rabbitmq_server_relations.is_sufficient_peers())