diff --git a/doc/what-is-new.md b/doc/what-is-new.md index a06fcd0b5..e824caa1a 100644 --- a/doc/what-is-new.md +++ b/doc/what-is-new.md @@ -1,11 +1,14 @@ # Next version yet unreleased +# Version 3.4 + - `sonar-tools` is now available as a docker image - `sonar-config` - Export can now export configuration as a YAML file (Only JSON was available previously). Import of YAML is not yet available - Beta version of config import in SonarCloud - `sonar-audit` a couple of new audit problems on permission templates (with no permissions, with no or wrong regexp) +- Removed calls to all APIs deprecated with 10.x, used their up-to-date replacement instead # Version 3.3 diff --git a/test/test_migration.py b/test/test_migration.py new file mode 100644 index 000000000..157901a0c --- /dev/null +++ b/test/test_migration.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +# +# sonar-migration tests +# Copyright (C) 2024 Olivier Korach +# mailto:olivier.korach AT gmail DOT com +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +""" sonar-migration tests """ + +import os +import sys +import json +from unittest.mock import patch +import pytest + +import utilities as util +from sonar import errcodes +import cli.options as opt +from cli import migration + +CMD = "migration.py" +OPTS = [CMD] + util.STD_OPTS + [f"-{opt.REPORT_FILE_SHORT}", util.JSON_FILE] + + +def __test_config_cmd(arguments: list[str]) -> None: + """Runs a test command""" + outputfile = arguments[arguments.index(f"-{opt.REPORT_FILE_SHORT}") + 1] + util.clean(outputfile) + with pytest.raises(SystemExit) as e: + with patch.object(sys, "argv", arguments): + migration.main() + assert int(str(e.value)) == errcodes.OK + assert util.file_not_empty(outputfile) + util.clean(outputfile) + +def test_migration_help() -> None: + """test_migration_help""" + util.clean(util.JSON_FILE) + with pytest.raises(SystemExit) as e: + with patch.object(sys, "argv", OPTS + ["-h"]): + migration.main() + assert int(str(e.value)) == 10 + assert not os.path.isfile(util.JSON_FILE) + + +def test_migration_basic() -> None: + """test_config_export""" + __test_config_cmd(OPTS)