Skip to content

Commit

Permalink
test: Replace logrotate rpm with mock
Browse files Browse the repository at this point in the history
See #1105
  • Loading branch information
danigm committed Sep 20, 2024
1 parent f27d1b2 commit 3ed857f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
Binary file removed test/binary/logrotate-0-0.x86_64.rpm
Binary file not shown.
46 changes: 42 additions & 4 deletions test/mockdata/mock_logrotate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import stat

from rpm import RPMFILE_CONFIG, RPMFILE_NOREPLACE

from Testing import get_tested_mock_package
Expand All @@ -6,9 +8,45 @@
LogrotatePackage = get_tested_mock_package(
lazyload=True,
files={
'tmp/foo/my.log': {},
'tmp/foo2/my.log': {},
'etc/logrotate.d/logrotate.conf': { 'content-path': 'files/logrotate/logrotate.conf' },
'etc/logrotate.d/logrotate2.conf': { 'content-path': 'files/logrotate/logrotate2.conf' },
'/tmp/foo': {
'create_dirs': True,
'is_dir': True,
'metadata': {
'mode': stat.S_IFDIR | 0o755,
'user': 'marxin',
'group': 'users',
},
},
'/tmp/foo2': {
'create_dirs': True,
'is_dir': True,
'metadata': {
'mode': stat.S_IFREG | stat.S_ISUID | 0o777,
'user': 'root',
'group': 'users2',
},
},
'/tmp/foo/my.log': {
'metadata': {
'mode': 0o644 | stat.S_IFREG,
'user': 'root',
'group': 'users2',
},
},
'/tmp/foo2/my.log': {
'metadata': {
'mode': stat.S_IFREG | stat.S_ISUID | 0o777,
'user': 'root',
'group': 'users2',
},
},
'/etc/logrotate.d/logrotate.conf': {
'create_dirs': True,
'content-path': 'files/logrotate/logrotate.conf',
},
'/etc/logrotate.d/logrotate2.conf': {
'create_dirs': True,
'content-path': 'files/logrotate/logrotate2.conf',
},
}
)
7 changes: 4 additions & 3 deletions test/test_logrotate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from mockdata.mock_logrotate import LogrotatePackage
from rpmlint.checks.LogrotateCheck import LogrotateCheck
from rpmlint.filter import Filter

Expand All @@ -13,10 +14,10 @@ def logrotatecheck():
return output, test


@pytest.mark.parametrize('package', ['binary/logrotate'])
def test_logrotate(tmp_path, package, logrotatecheck):
@pytest.mark.parametrize('package', [LogrotatePackage])
def test_logrotate(package, logrotatecheck):
output, test = logrotatecheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'E: logrotate-log-dir-not-packaged /var/log/myapp' in out
assert 'E: logrotate-duplicate /var/log/myapp' in out
Expand Down

0 comments on commit 3ed857f

Please sign in to comment.