summaryrefslogtreecommitdiff
diff options
authorTim Van Steenburgh <tim.van.steenburgh@canonical.com>2014-11-04 13:23:06 -0500
committerTim Van Steenburgh <tim.van.steenburgh@canonical.com>2014-11-04 13:23:06 -0500
commitd7c5ca832e4610bfd937d09fb9580ee0651ad935 (patch)
tree0ab13f370f143300e02872234f624b1a3d5a7061
parent21a0ca74b9e889245211436193cc71f481743f66 (diff)
Test refactor, add missed files
-rwxr-xr-xtests/01_test_write_log_rotate_config.py41
-rw-r--r--tests/tests.yaml1
2 files changed, 42 insertions, 0 deletions
diff --git a/tests/01_test_write_log_rotate_config.py b/tests/01_test_write_log_rotate_config.py
new file mode 100755
index 0000000..ba15ee0
--- /dev/null
+++ b/tests/01_test_write_log_rotate_config.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+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)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/tests.yaml b/tests/tests.yaml
new file mode 100644
index 0000000..193e5ac
--- /dev/null
+++ b/tests/tests.yaml
@@ -0,0 +1 @@
+tests: "[0-9]*"