diff --git a/sonar/audit/problem.py b/sonar/audit/problem.py index 1d3a78a63..479efedae 100644 --- a/sonar/audit/problem.py +++ b/sonar/audit/problem.py @@ -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: diff --git a/test/unit/test_housekeeper.py b/test/unit/test_housekeeper.py index 288d7f9cc..2fed00002 100644 --- a/test/unit/test_housekeeper.py +++ b/test/unit/test_housekeeper.py @@ -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 diff --git a/test/unit/utilities.py b/test/unit/utilities.py index dffa10fd8..86622a017 100644 --- a/test/unit/utilities.py +++ b/test/unit/utilities.py @@ -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