Skip to content

Commit 380f033

Browse files
authored
Merge pull request #1322 from okorach:add-basic-sonar-migration-test
Add-basic-sonar-migration-test
2 parents 50086c9 + a090d5f commit 380f033

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

doc/what-is-new.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Next version yet unreleased
22

3+
# Version 3.4
4+
35
- `sonar-tools` is now available as a docker image
46
- `sonar-config`
57
- Export can now export configuration as a YAML file (Only JSON was available previously).
68
Import of YAML is not yet available
79
- Beta version of config import in SonarCloud
810
- `sonar-audit` a couple of new audit problems on permission templates (with no permissions, with no or wrong regexp)
11+
- Removed calls to all APIs deprecated with 10.x, used their up-to-date replacement instead
912

1013
# Version 3.3
1114

test/test_migration.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python3
2+
#
3+
# sonar-migration tests
4+
# Copyright (C) 2024 Olivier Korach
5+
# mailto:olivier.korach AT gmail DOT com
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU Lesser General Public
9+
# License as published by the Free Software Foundation; either
10+
# version 3 of the License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
# Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with this program; if not, write to the Free Software Foundation,
19+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
#
21+
22+
""" sonar-migration tests """
23+
24+
import os
25+
import sys
26+
import json
27+
from unittest.mock import patch
28+
import pytest
29+
30+
import utilities as util
31+
from sonar import errcodes
32+
import cli.options as opt
33+
from cli import migration
34+
35+
CMD = "migration.py"
36+
OPTS = [CMD] + util.STD_OPTS + [f"-{opt.REPORT_FILE_SHORT}", util.JSON_FILE]
37+
38+
39+
def __test_config_cmd(arguments: list[str]) -> None:
40+
"""Runs a test command"""
41+
outputfile = arguments[arguments.index(f"-{opt.REPORT_FILE_SHORT}") + 1]
42+
util.clean(outputfile)
43+
with pytest.raises(SystemExit) as e:
44+
with patch.object(sys, "argv", arguments):
45+
migration.main()
46+
assert int(str(e.value)) == errcodes.OK
47+
assert util.file_not_empty(outputfile)
48+
util.clean(outputfile)
49+
50+
def test_migration_help() -> None:
51+
"""test_migration_help"""
52+
util.clean(util.JSON_FILE)
53+
with pytest.raises(SystemExit) as e:
54+
with patch.object(sys, "argv", OPTS + ["-h"]):
55+
migration.main()
56+
assert int(str(e.value)) == 10
57+
assert not os.path.isfile(util.JSON_FILE)
58+
59+
60+
def test_migration_basic() -> None:
61+
"""test_config_export"""
62+
__test_config_cmd(OPTS)

0 commit comments

Comments
 (0)