Skip to content

Commit

Permalink
Assert new sonar.token warning
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource committed Mar 20, 2023
1 parent 4932200 commit 1e31086
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
10 changes: 8 additions & 2 deletions its/src/test/java/com/sonar/it/csharp/AnalysisWarningsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public void analysisWarningsImport() throws IOException {

Ce.Task task = TestUtils.getAnalysisWarningsTask(ORCHESTRATOR, buildResult);
assertThat(task.getStatus()).isEqualTo(Ce.TaskStatus.SUCCESS);
assertThat(task.getWarningsList()).containsExactly("First message", "Second message");
assertThat(task.getWarningsList()).containsExactly(
"The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.",
"First message",
"Second message");
}

@Test
Expand All @@ -65,6 +68,9 @@ public void analysisWarnings_OldRoslyn() throws IOException {

Ce.Task task = TestUtils.getAnalysisWarningsTask(ORCHESTRATOR, buildResult);
assertThat(task.getStatus()).isEqualTo(Ce.TaskStatus.SUCCESS);
assertThat(task.getWarningsList()).containsExactly("Analysis using MsBuild 14 and 15 build tools is deprecated. Please update your pipeline to MsBuild 16 or higher.");
assertThat(task.getWarningsList()).containsExactly(
"The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.",
"Analysis using MsBuild 14 and 15 build tools is deprecated. Please update your pipeline to MsBuild 16 or higher."
);
}
}
25 changes: 13 additions & 12 deletions its/src/test/java/com/sonar/it/csharp/TestProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@ public void projectIsAnalyzed() {

@Test
public void logsContainInfoAndWarning() {
assertThat(buildResult.getLogs()).contains(
"SonarScanner for .NET detected only TEST files and no MAIN files for C# in the current solution. " +
"Only TEST-code related results will be imported to your SonarQube/SonarCloud project. " +
"Many of our rules (e.g. vulnerabilities) are raised only on MAIN-code. " +
"Read more about how the SonarScanner for .NET detects test projects: https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects",
"Found 1 MSBuild C# project: 1 TEST project."
assertThat(buildResult.getLogsLines(l -> l.contains("INFO"))).contains("INFO: Found 1 MSBuild C# project: 1 TEST project.");
assertThat(buildResult.getLogsLines(l -> l.contains("WARN"))).contains(
"WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.",
"WARN: SonarScanner for .NET detected only TEST files and no MAIN files for C# in the current solution. Only TEST-code related results will be imported to your SonarQube/SonarCloud project. " +
"Many of our rules (e.g. vulnerabilities) are raised only on MAIN-code. Read more about how the SonarScanner for .NET detects" +
" test projects: https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects"
);
TestUtils.verifyGuiTestOnlyProjectAnalysisWarning(ORCHESTRATOR, buildResult, "C#");
}

@Test
Expand Down Expand Up @@ -103,11 +102,13 @@ public void with_html_and_csharp_code_explicitly_marked_as_test_should_not_popul
assertThat(getMeasureAsInt(EXPLICITLY_MARKED_AS_TEST, "ncloc")).isNull();

assertThat(buildResult.getLogsLines(l -> l.contains("WARN")))
.contains("WARN: SonarScanner for .NET detected only TEST files and no MAIN files for C# in the current solution. " +
"Only TEST-code related results will be imported to your SonarQube/SonarCloud project. " +
"Many of our rules (e.g. vulnerabilities) are raised only on MAIN-code. " +
"Read more about how the SonarScanner for .NET detects test projects: https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects");
.contains(
"WARN: SonarScanner for .NET detected only TEST files and no MAIN files for C# in the current solution. " +
"Only TEST-code related results will be imported to your SonarQube/SonarCloud project. " +
"Many of our rules (e.g. vulnerabilities) are raised only on MAIN-code. " +
"Read more about how the SonarScanner for .NET detects test projects: https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects",
"The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter."
);
assertThat(buildResult.getLogsLines(l -> l.contains("INFO"))).contains("INFO: Found 1 MSBuild C# project: 1 TEST project.");
TestUtils.verifyGuiTestOnlyProjectAnalysisWarning(ORCHESTRATOR, buildResult, "C#");
}
}
4 changes: 0 additions & 4 deletions its/src/test/java/com/sonar/it/shared/ScannerCliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void givenRazorPagesMainCode_whenScannerForCliIsUsed_logsCSharpWarning()
);
// The HTML plugin works
assertThat(TestUtils.getMeasureAsInt(ORCHESTRATOR, RAZOR_PAGES_PROJECT, "violations")).isEqualTo(2);
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
}

@Test
Expand All @@ -79,7 +78,6 @@ public void givenMainHtmlCodeAndTestCSharpCode_whenScannerForCliIsUsed_logsCShar
);
// The HTML plugin works
assertThat(TestUtils.getMeasureAsInt(ORCHESTRATOR, HTML_IN_MAIN_AND_CSHARP_IN_TEST_SUBFOLDERS, "violations")).isEqualTo(2);
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
}

@Test
Expand All @@ -95,7 +93,6 @@ public void givenTestHtmlAndCSharpCode_whenScannerForCliIsUsed_logsCSharpWarning
"WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.",
INCREMENTAL_PR_ANALYSIS_WARNING
);
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
}

@Test
Expand All @@ -108,7 +105,6 @@ public void givenTestHtmlCode_whenScannerForCliIsUsed_doesNotLogCsharpWarning()

assertThat(result.getLogsLines(l -> l.contains("WARN")))
.containsExactly("WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.");
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
}

private SonarScanner getSonarScanner(String projectKey, String projectDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,13 @@ public void logsContainInfo() {
.contains("WARN: SonarScanner for .NET detected only TEST files and no MAIN files for C# in the current solution. " +
"Only TEST-code related results will be imported to your SonarQube/SonarCloud project. " +
"Many of our rules (e.g. vulnerabilities) are raised only on MAIN-code. " +
"Read more about how the SonarScanner for .NET detects test projects: https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects");
"Read more about how the SonarScanner for .NET detects test projects: https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects",
"WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter."
);

assertThat(buildResult.getLogsLines(l -> l.contains("INFO"))).contains(
"INFO: Found 1 MSBuild VB.NET project: 1 MAIN project.",
"INFO: Found 1 MSBuild C# project: 1 TEST project.");
assertThat(buildResult.getLogsLines(l -> l.contains("WARN")))
.containsExactly(
"WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter."
);
}

@Test
Expand Down
8 changes: 3 additions & 5 deletions its/src/test/java/com/sonar/it/vbnet/TestProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ public void with_vbnet_only_test_should_not_populate_metrics() throws Exception
.contains("WARN: SonarScanner for .NET detected only TEST files and no MAIN files for VB.NET in the current solution. " +
"Only TEST-code related results will be imported to your SonarQube/SonarCloud project. " +
"Many of our rules (e.g. vulnerabilities) are raised only on MAIN-code. " +
"Read more about how the SonarScanner for .NET detects test projects: https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects");

assertThat(buildResult.getLogsLines(l -> l.contains("INFO"))).contains("INFO: Found 1 MSBuild VB.NET project: 1 TEST project.");
assertThat(buildResult.getLogsLines(l -> l.contains("WARN")))
.containsExactly(
"Read more about how the SonarScanner for .NET detects test projects: https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects",
"WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter."
);

assertThat(buildResult.getLogsLines(l -> l.contains("INFO"))).contains("INFO: Found 1 MSBuild VB.NET project: 1 TEST project.");
}

@Test
Expand Down

0 comments on commit 1e31086

Please sign in to comment.