Skip to content

Commit

Permalink
Enable dynamic bash commands disable for tests
Browse files Browse the repository at this point in the history
Dracut testing should be more versatile with this approach. This is more
an extension for future testing.
  • Loading branch information
jkonecny12 committed Jan 20, 2025
1 parent 1a61d89 commit 63b081c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tests/unit_tests/dracut_tests/test_dracut_anaconda-lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@
import re
import subprocess
import unittest

from collections import namedtuple
from tempfile import NamedTemporaryFile, TemporaryDirectory

DISABLE_COMMANDS = [
"command",
]
DISABLE_COMMAND_PREFIX = "disabled-command"


Expand Down Expand Up @@ -53,13 +49,19 @@ def _load_script(self, script_name):
with open(os.path.join("../dracut/", script_name), "rt", encoding="utf-8") as f:
self._content = f.read()

self._disable_bash_commands()

def _disable_bash_commands(self):
def _disable_bash_commands(self, disabled_commands):
disable_list = []
# disable external and problematic commands in Dracut
for disabled_cmd in DISABLE_COMMANDS:
disable_list.append(f"""
for disabled_cmd in disabled_commands:
if isinstance(disabled_cmd, list):
disable_list.append(f"""
{disabled_cmd[0]}() {{
echo "{DISABLE_COMMAND_PREFIX}: {disabled_cmd} args: $@" >&2
{disabled_cmd[1]}
}}
""")
if isinstance(disabled_cmd, str):
disable_list.append(f"""
{disabled_cmd}() {{
echo "{DISABLE_COMMAND_PREFIX}: {disabled_cmd} args: $@" >&2
}}
Expand Down Expand Up @@ -121,6 +123,7 @@ def _check_get_text_with_content(self, test_input, expected_stdout):
def test_config_get(self):
"""Test bash config_get function to read .treeinfo file"""
self._load_script("anaconda-lib.sh")
self._disable_bash_commands(["command"])

# test multiple values in file
self._check_get_text_with_content(
Expand Down

0 comments on commit 63b081c

Please sign in to comment.