8
class TestWriteLogrotateConfigFile(unittest.TestCase):
10
def test_success(self):
11
logpath = '/tmp/foo/foo.log'
14
'logrotate-frequency': 'daily',
15
'logrotate-maxsize': '5G',
16
'logrotate-rotate': 5,
18
fd, temp_fn = tempfile.mkstemp()
20
with mock.patch('hooks.juju_log') as mock_juju_log:
21
with mock.patch('hooks.open', create=True) as mock_open:
22
mock_open.return_value = mock.MagicMock(spec=file)
23
hooks.write_logrotate_config(config_data, temp_fn)
25
self.assertFalse(mock_juju_log.called)
26
mock_open.assert_called_once_with(temp_fn, 'w')
27
mock_file = mock_open().__enter__()
28
call_args = mock_file.write.call_args[0][0]
29
self.assertTrue(mock_file.write.called)
30
self.assertIn(logpath, call_args)
31
self.assertIn('daily', call_args)
32
self.assertIn('maxsize 5G', call_args)
33
self.assertIn('rotate 5', call_args)