Skip to content

Commit fd1b279

Browse files
committed
Add test ou output of sonar-migration
1 parent 270ff54 commit fd1b279

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

test/test_migration.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,6 @@
3636
OPTS = [CMD] + util.STD_OPTS + [f"-{opt.REPORT_FILE_SHORT}", util.JSON_FILE]
3737

3838

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-
5139
def test_migration_help() -> None:
5240
"""test_migration_help"""
5341
util.clean(util.JSON_FILE)
@@ -58,6 +46,47 @@ def test_migration_help() -> None:
5846
assert not os.path.isfile(util.JSON_FILE)
5947

6048

61-
def test_migration_basic() -> None:
49+
def test_migration() -> None:
6250
"""test_config_export"""
63-
__test_config_cmd(OPTS)
51+
util.clean(util.JSON_FILE)
52+
with pytest.raises(SystemExit) as e:
53+
with patch.object(sys, "argv", OPTS):
54+
migration.main()
55+
assert int(str(e.value)) == errcodes.OK
56+
assert util.file_not_empty(util.JSON_FILE)
57+
with open(file=util.JSON_FILE, mode="r", encoding="utf-8") as fh:
58+
json_config = json.loads(fh.read())
59+
60+
u = json_config["users"]["admin"]
61+
assert "sonar-users" in u["groups"]
62+
assert u["local"] and u["active"]
63+
assert "sonarQubeLastConnectionDate" in u
64+
assert "sonarLintLastConnectionDate" in u
65+
assert json_config["users"]["olivier"]["externalProvider"] == "sonarqube"
66+
67+
u = json_config["users"]["olivier-korach65532"]
68+
assert u["externalProvider"] == "github"
69+
assert u["name"] == "Olivier Korach"
70+
assert not u["local"]
71+
assert u["externalLogin"] == "okorach"
72+
assert u["email"] == "[email protected]"
73+
74+
p = json_config["projects"]["okorach_sonar-tools"]
75+
assert "lastTaskScannerContext" in p["backgroundTasks"]
76+
for elem in "detectedCi", "lastAnalysis", "revision":
77+
assert elem in p
78+
assert p["ncloc"]["py"] > 0
79+
assert p["ncloc"]["total"] > 0
80+
81+
iss = p["branches"]["master"]["issues"]
82+
assert iss["accepted"] > 0
83+
assert iss["fslePositives"] > 0
84+
assert iss["thirdParty"] == 0
85+
86+
p = json_config["projects"]["checkstyle-issues"]
87+
assert len(p["branches"]["issues"]["thirdParty"]) > 0
88+
89+
assert json_config["projects"]["demo:gitlab-ci-maven"]["detectedCi"] == "GitLab CI"
90+
assert json_config["projects"]["demo:gitlab-actions-cli"]["detectedCi"] == "Github Actions"
91+
92+
util.clean(util.JSON_FILE)

0 commit comments

Comments
 (0)