-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add actor name discovery and some unit tests
With this the scanning part should be complete. Checker that actually reports errors will be delivered by the next commit.
- Loading branch information
1 parent
ceb0a78
commit a128d0e
Showing
3 changed files
with
125 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...tem_upgrade/common/actors/trackcustommodifications/tests/test_trackcustommodifications.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import pytest | ||
|
||
from leapp.libraries.actor import trackcustommodifications | ||
from leapp.libraries.common.testutils import CurrentActorMocked, produce_mocked | ||
from leapp.libraries.stdlib import api | ||
|
||
FILES_FROM_RPM = """ | ||
repos/system_upgrade/el8toel9/actors/xorgdrvfact/libraries/xorgdriverlib.py | ||
repos/system_upgrade/el8toel9/actors/anotheractor/actor.py | ||
repos/system_upgrade/el8toel9/files | ||
""" | ||
|
||
FILES_ON_SYSTEM = """ | ||
repos/system_upgrade/el8toel9/actors/xorgdrvfact/libraries/xorgdriverlib.py | ||
repos/system_upgrade/el8toel9/actors/anotheractor/actor.py | ||
repos/system_upgrade/el8toel9/files | ||
/some/unrelated/to/leapp/file | ||
repos/system_upgrade/el8toel9/files/file/that/should/not/be/there | ||
repos/system_upgrade/el8toel9/actors/actor/that/should/not/be/there | ||
""" | ||
|
||
VERIFIED_FILES = """ | ||
.......T. repos/system_upgrade/el8toel9/actors/xorgdrvfact/libraries/xorgdriverlib.py | ||
S.5....T. repos/system_upgrade/el8toel9/actors/anotheractor/actor.py | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('a_file,name', [ | ||
('repos/system_upgrade/el8toel9/actors/checkblacklistca/actor.py', 'CheckBlackListCA'), | ||
('repos/system_upgrade/el7toel8/actors/checkmemcached/actor.py', 'CheckMemcached'), | ||
('repos/system_upgrade/el7toel8/actors/checkmemcached/libraries/checkmemcached.py', 'CheckMemcached'), | ||
# not a library and not an actor file | ||
('repos/system_upgrade/el7toel8/models/authselect.py', ''), | ||
]) | ||
def test_deduce_actor_name_from_file(a_file, name): | ||
assert trackcustommodifications.deduce_actor_name(a_file) == name | ||
|
||
|
||
def mocked__run_command(list_of_args, log_message): | ||
if list_of_args == ['rpm', '-ql', 'leapp-upgrade-el7toel8']: | ||
# get source of truth | ||
return FILES_FROM_RPM.strip().split('\n') | ||
if list_of_args and list_of_args[0] == 'find': | ||
# listing files in directory | ||
return FILES_ON_SYSTEM.strip().split('\n') | ||
if list_of_args == ['rpm', '-V', 'leapp-upgrade-el7toel8']: | ||
# checking authenticity | ||
return VERIFIED_FILES.strip().split('\n') | ||
return [] | ||
|
||
|
||
def test_check_for_modifications(monkeypatch): | ||
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4')) | ||
monkeypatch.setattr(trackcustommodifications, '_run_command', mocked__run_command) | ||
modified, custom = trackcustommodifications.check_for_modifications() | ||
assert len(modified) == 2 | ||
assert modified[0].filename == 'repos/system_upgrade/el8toel9/actors/xorgdrvfact/libraries/xorgdriverlib.py' | ||
assert modified[0].rpm_checks_str == '.......T.' | ||
assert len(custom) == 3 | ||
assert custom[0].filename == '/some/unrelated/to/leapp/file' | ||
assert custom[0].rpm_checks_str == '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters