~evarlast/charms/trusty/mongodb/i-do-not-know-how-to-use-bzr-so-i-pushed-here

« back to all changes in this revision

Viewing changes to tests/test_write_log_rotate_config.py

  • Committer: Juan L. Negron
  • Date: 2013-12-11 22:03:08 UTC
  • mfrom: (35.1.5 logrotate)
  • Revision ID: juan.negron@canonical.com-20131211220308-udz0nxuimm66ds99
Merging bac's changes MP:198633

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import hooks
 
2
import mock
 
3
import os
 
4
import unittest
 
5
import tempfile
 
6
 
 
7
 
 
8
class TestWriteLogrotateConfigFile(unittest.TestCase):
 
9
 
 
10
    def test_success(self):
 
11
        logpath = '/tmp/foo/foo.log'
 
12
        config_data = {
 
13
            'logpath': logpath,
 
14
            'logrotate-frequency': 'daily',
 
15
            'logrotate-maxsize': '5G',
 
16
            'logrotate-rotate': 5,
 
17
        }
 
18
        fd, temp_fn = tempfile.mkstemp()
 
19
        os.close(fd)
 
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)
 
24
                os.unlink(temp_fn)
 
25
        mock_juju_log.assert_called_once_with('Writing {}.'.format(temp_fn))
 
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)