summaryrefslogtreecommitdiff
path: root/unit_tests
diff options
authorMario Splivalo <mario.splivalo@canonical.com>2014-12-10 12:18:45 +0100
committerMario Splivalo <mario.splivalo@canonical.com>2014-12-10 12:18:45 +0100
commite01ad034bf16da8bf48edea9dcd5630e3eea89ac (patch)
treee7978ccda36e6ca499f25a15779e439bf424e5b9 /unit_tests
parent6f0d28c312388d722ecd76930305ef1309ae196b (diff)
Syncing to get closer with lp:~mariosplivalo/charms/trusty/mongodb/charmhelpers-sync
Diffstat (limited to 'unit_tests')
-rw-r--r--unit_tests/test_write_log_rotate_config.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/unit_tests/test_write_log_rotate_config.py b/unit_tests/test_write_log_rotate_config.py
new file mode 100644
index 0000000..e1d6154
--- /dev/null
+++ b/unit_tests/test_write_log_rotate_config.py
@@ -0,0 +1,35 @@
+import mock
+import os
+import unittest
+import tempfile
+import sys
+sys.path.append('hooks')
+import hooks
+
+
+class TestWriteLogrotateConfigFile(unittest.TestCase):
+
+ def test_success(self):
+ logpath = '/tmp/foo/foo.log'
+ config_data = {
+ 'logpath': logpath,
+ 'logrotate-frequency': 'daily',
+ 'logrotate-maxsize': '5G',
+ 'logrotate-rotate': 5,
+ }
+ fd, temp_fn = tempfile.mkstemp()
+ os.close(fd)
+ with mock.patch('hooks.juju_log') as mock_juju_log:
+ with mock.patch('hooks.open', create=True) as mock_open:
+ mock_open.return_value = mock.MagicMock(spec=file)
+ hooks.write_logrotate_config(config_data, temp_fn)
+ os.unlink(temp_fn)
+ mock_juju_log.assert_called_once_with('Writing {}.'.format(temp_fn))
+ mock_open.assert_called_once_with(temp_fn, 'w')
+ mock_file = mock_open().__enter__()
+ call_args = mock_file.write.call_args[0][0]
+ self.assertTrue(mock_file.write.called)
+ self.assertIn(logpath, call_args)
+ self.assertIn('daily', call_args)
+ self.assertIn('maxsize 5G', call_args)
+ self.assertIn('rotate 5', call_args)