Skip to content
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: 4 additions & 0 deletions sonar/audit/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def __dump_csv(problems: list[Problem], file: str, server_id: str = None, with_u
"""
with utilities.open_file(file, "w") as fd:
csvwriter = csv.writer(fd, delimiter=separator)
header = ["Server Id"] if server_id else []
header += ["Audit Check", "Category", "Severity", "Message"]
header += ["URL"] if with_url else []
csvwriter.writerow(header)
for p in problems:
data = []
if server_id is not None:
Expand Down
11 changes: 6 additions & 5 deletions test/unit/test_housekeeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ def test_housekeeper() -> None:
for opts in __GOOD_OPTS:
assert tutil.run_cmd(housekeeper.main, f"{CMD} {tutil.SQS_OPTS} {opts}") == errcodes.OK


def test_keep_branches_override(csv_file: Generator[str]) -> None:
"""test_keep_branches_override"""
if tutil.SQ.version() == "community":
pytest.skip("No branches in Community")
assert tutil.run_cmd(housekeeper.main, f"{CMD} {tutil.SQS_OPTS} -P 730 -T 730 -R 730 -B 90 -f {csv_file}") == errcodes.OK
nbr_br = tutil.csv_col_count_values(csv_file, 1, "BRANCH_LAST_ANALYSIS")
assert tutil.run_cmd(housekeeper.main, f"{CMD} {tutil.SQS_OPTS} -P 730 -T 730 -R 730 -B 90 -f {csv_file} --keepWhenInactive 'dontkeepanything'") == errcodes.OK
opts = f"{CMD} {tutil.SQS_OPTS} -P 730 -T 730 -R 730 -B 90 -f {csv_file}"
assert tutil.run_cmd(housekeeper.main, opts) == errcodes.OK
nbr_br = tutil.csv_col_count_values(csv_file, "Audit Check", "BRANCH_LAST_ANALYSIS")
assert tutil.run_cmd(housekeeper.main, f"{opts} --keepWhenInactive 'dontkeepanything'") == errcodes.OK
# With 'dontkeepanything' as branch regexp, more branches to delete should be found
assert tutil.csv_col_count_values(csv_file, 1, "BRANCH_LAST_ANALYSIS") > nbr_br

assert tutil.csv_col_count_values(csv_file, "Audit Check", "BRANCH_LAST_ANALYSIS") > nbr_br
2 changes: 1 addition & 1 deletion test/unit/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def csv_col_count_values(csv_file: str, col_name_or_nbr: Union[str, int], *value
if isinstance(col_name_or_nbr, int):
col = col_name_or_nbr - 1
else:
(col,) = get_cols(next(reader, col_name_or_nbr))
(col,) = get_cols(next(reader), col_name_or_nbr)
counter = sum(1 if line[col] in values_to_search else 0 for line in reader)
return counter

Expand Down