From 60e6ed67e38918aa18b489e821eda99690291490 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Mon, 4 Apr 2016 10:06:28 +0200 Subject: [PATCH] Add unit tests. --- tests/test_patroni.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_patroni.py b/tests/test_patroni.py index d3801abb..fc806026 100644 --- a/tests/test_patroni.py +++ b/tests/test_patroni.py @@ -1,4 +1,5 @@ import etcd +import os import sys import time import unittest @@ -56,6 +57,14 @@ class TestPatroni(unittest.TestCase): self.assertRaises(SleepException, _main) with patch.object(Patroni, 'run', Mock(side_effect=KeyboardInterrupt())): _main() + sys.argv = ['patroni.py'] + # read the content of the yaml configuration file into the environment variable + # in order to test how does patroni handle the configuration passed from the environment. + with open('postgres0.yml', 'r') as f: + os.environ[Patroni.PATRONI_CONFIG_VARIABLE] = f.read() + with patch.object(Patroni, 'run', Mock(side_effect=SleepException())): + self.assertRaises(SleepException, _main) + del os.environ[Patroni.PATRONI_CONFIG_VARIABLE] @patch('time.sleep', Mock(side_effect=SleepException())) def test_run(self):