Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_logs_dir_not_a_dir integration-test #3987

Merged
merged 3 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ jobs:
source $(poetry env info --path)/bin/activate
cd content
mkdir -p test-pre-commit-command/logs
export DEMISTO_SDK_LOG_FILE_PATH=./test-pre-commit-command/logs/demisto_sdk_debug.log
export DEMISTO_SDK_LOG_FILE_PATH=./test-pre-commit-command/logs
echo "# test" >> Packs/HelloWorld/Integrations/HelloWorld/HelloWorld.yml
echo "# test" >> Packs/CortexXDR/Integrations/CortexXDRIR/CortexXDRIR.yml
echo "# test" >> Packs/QRadar/Integrations/QRadar_v3/QRadar_v3.yml
Expand Down Expand Up @@ -333,7 +333,7 @@ jobs:
source $(poetry env info --path)/bin/activate
cd content
mkdir -p test-graph-commands/logs
export DEMISTO_SDK_LOG_FILE_PATH=./test-graph-commands/logs/demisto_sdk_debug.log
export DEMISTO_SDK_LOG_FILE_PATH=./test-graph-commands/logs
# create content graph from scratch
demisto-sdk create-content-graph
# clean import folder
Expand Down
26 changes: 9 additions & 17 deletions demisto_sdk/tests/integration_tests/logger_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def test_default_logs_dir(mocker):
runner.invoke(main, ["validate", "-a"])

assert logs_dir_replacement.exists() # Assure 'logs' dir is generated by the code
assert list(logs_dir_replacement.glob("*")) == [
logs_dir_replacement / "demisto_sdk_debug.log"
]
assert (logs_dir_replacement / "demisto_sdk_debug.log").is_file()
shutil.rmtree(root_dir)


Expand All @@ -56,9 +54,7 @@ def test_custom_logs_dir_set_by_flag(mocker):
runner = CliRunner(mix_stderr=False)
runner.invoke(main, ["validate", "-a", "--log-file-path", str(custom_logs_dir)])

assert list(custom_logs_dir.glob("*")) == [
custom_logs_dir / "demisto_sdk_debug.log"
]
assert (custom_logs_dir / "demisto_sdk_debug.log").is_file()
assert (
len(list(default_logs_dir.glob("*"))) == 0
) # Assure default logs dir is not used
Expand All @@ -85,9 +81,7 @@ def test_custom_logs_dir_set_by_env_var(mocker, monkeypatch):
runner = CliRunner(mix_stderr=False)
runner.invoke(main, ["validate", "-a", "--log-file-path", str(custom_logs_dir)])

assert list(custom_logs_dir.glob("*")) == [
custom_logs_dir / "demisto_sdk_debug.log"
]
assert (custom_logs_dir / "demisto_sdk_debug.log").is_file()
assert (
len(list(default_logs_dir.glob("*"))) == 0
) # Assure default logs dir is not used
Expand Down Expand Up @@ -121,9 +115,7 @@ def test_custom_logs_dir_does_not_exist(mocker):
logger_warning.call_args_list,
f"Log file path '{custom_logs_dir}' does not exist and will be created.",
)
assert list(custom_logs_dir.glob("*")) == [
custom_logs_dir / "demisto_sdk_debug.log"
]
assert (custom_logs_dir / "demisto_sdk_debug.log").is_file()
assert (
len(list(default_logs_dir.glob("*"))) == 0
) # Assure default logs dir is not used
Expand All @@ -146,24 +138,24 @@ def test_logs_dir_not_a_dir(mocker):
custom_logs_dir = (
Path(mkdtemp(prefix=TEMP_DIRS_PREFIX)).resolve() / "some_random_file"
)
custom_logs_dir_parent = custom_logs_dir.parent
custom_logs_dir.touch()
assert custom_logs_dir.is_file() # Ensure file was created successfully

mocker.patch("demisto_sdk.commands.common.logger.LOGS_DIR", new=default_logs_dir)
logger_warning = mocker.patch.object(logging.getLogger("demisto-sdk"), "warning")

runner = CliRunner(mix_stderr=False)
runner.invoke(main, ["validate", "-a", "--log-file-path", str(custom_logs_dir)])

custom_logs_dir_parent = custom_logs_dir.parent

assert str_in_call_args_list(
logger_warning.call_args_list,
f"Log file path '{custom_logs_dir}' is a file and not a directory. Log file will be created in "
f"parent directory '{custom_logs_dir_parent}'.",
)
assert list(custom_logs_dir_parent.glob("*")) == [
custom_logs_dir, # The random file we created
custom_logs_dir_parent / "demisto_sdk_debug.log",
]

assert (custom_logs_dir_parent / "demisto_sdk_debug.log").is_file()
assert (
len(list(default_logs_dir.glob("*"))) == 0
) # Assure default logs dir is not used
Expand Down
Loading