Skip to content

Commit

Permalink
Add general log test
Browse files Browse the repository at this point in the history
  • Loading branch information
torcolvin committed Jun 21, 2024
1 parent 69ba50f commit 0071db9
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions tools-tests/sgcollect_info_test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,54 @@
import sgcollect_info
import unittest
import io

import pytest

import sgcollect_info


@pytest.mark.parametrize(
"config",
[
'{{"logfilepath": "{tmpdir}"}}',
'{{"Logging": {{ "default": {{ "logfilepath": "{log_file}" }} }} }}',
'{{"logging": {{ "log_file_path": "{tmpdir}" }} }}',
],
)
def test_make_collect_logs_tasks(config, tmpdir):
log_file = tmpdir.join("sg_info.log")
log_file.write("foo")
with unittest.mock.patch(
"sgcollect_info.urlopen_with_basic_auth",
return_value=io.BytesIO(
config.format(
tmpdir=str(tmpdir).replace("\\", "\\\\"),
log_file=str(log_file).replace("\\", "\\\\"),
).encode("utf-8")
),
):
rotated_log_file = tmpdir.join("sg_info-01.log.gz")
rotated_log_file.write("foo")
tasks = sgcollect_info.make_collect_logs_tasks(
tmpdir,
sg_url="fakeurl",
sg_config_file_path="",
sg_username="",
sg_password="",
salt="",
should_redact=False,
)
assert [t.log_file for t in tasks] == [
log_file.basename,
rotated_log_file.basename,
]


def test_make_collect_logs_tasks(tmpdir):
def test_make_collect_logs_heap_profile(tmpdir):
with unittest.mock.patch(
"sgcollect_info.urlopen_with_basic_auth",
return_value=io.BytesIO(
'{{"logfilepath": "{logdir}"}}'.format(
logdir=str(tmpdir).replace(
"\\", "\\\\"
) # replace backslashes with double backslashes for windows paths in json
'{{"logfilepath": "{logpath}"}}'.format(
logpath=str(tmpdir).replace("\\", "\\\\")
).encode("utf-8")
),
):
Expand Down

0 comments on commit 0071db9

Please sign in to comment.