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