8
sys.path.append('hooks')
12
class TestWriteLogrotateConfigFile(unittest.TestCase):
14
def test_success(self):
15
logpath = '/tmp/foo/foo.log'
18
'logrotate-frequency': 'daily',
19
'logrotate-maxsize': '5G',
20
'logrotate-rotate': 5,
22
fd, temp_fn = tempfile.mkstemp()
24
with mock.patch('hooks.juju_log') as mock_juju_log:
25
with mock.patch('hooks.open', create=True) as mock_open:
26
mock_open.return_value = mock.MagicMock(spec=file)
27
hooks.write_logrotate_config(config_data, temp_fn)
29
mock_juju_log.assert_called_once_with('Writing {}.'.format(temp_fn))
30
mock_open.assert_called_once_with(temp_fn, 'w')
31
mock_file = mock_open().__enter__()
32
call_args = mock_file.write.call_args[0][0]
33
self.assertTrue(mock_file.write.called)
34
self.assertIn(logpath, call_args)
35
self.assertIn('daily', call_args)
36
self.assertIn('maxsize 5G', call_args)
37
self.assertIn('rotate 5', call_args)
40
if __name__ == '__main__':