aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-protocol/src/test/java/org/sonar/scanner
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2024-10-09 15:09:39 +0200
committersonartech <sonartech@sonarsource.com>2024-10-11 20:02:42 +0000
commit3f0a34901c55eb1e204fe4028d2773f8484b513f (patch)
treee79565fd2126baf3711a545619470dd2f44d2598 /sonar-scanner-protocol/src/test/java/org/sonar/scanner
parent8859ed6887ec1e2eb3e86a11b98b73b5b8606710 (diff)
downloadsonarqube-3f0a34901c55eb1e204fe4028d2773f8484b513f.tar.gz
sonarqube-3f0a34901c55eb1e204fe4028d2773f8484b513f.zip
SONAR-23327 Implement addTelemetryProperty in the scanner engine
Diffstat (limited to 'sonar-scanner-protocol/src/test/java/org/sonar/scanner')
-rw-r--r--sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/FileStructureTest.java21
-rw-r--r--sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java24
2 files changed, 39 insertions, 6 deletions
diff --git a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/FileStructureTest.java b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/FileStructureTest.java
index b2787934275..9c7ada548b3 100644
--- a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/FileStructureTest.java
+++ b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/FileStructureTest.java
@@ -20,6 +20,7 @@
package org.sonar.scanner.protocol.output;
import java.io.File;
+import java.nio.charset.Charset;
import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.Test;
@@ -60,10 +61,10 @@ public class FileStructureTest {
@Test
public void locate_files() throws Exception {
File dir = temp.newFolder();
- FileUtils.write(new File(dir, "metadata.pb"), "metadata content");
- FileUtils.write(new File(dir, "issues-3.pb"), "external issues of component 3");
- FileUtils.write(new File(dir, "external-issues-3.pb"), "issues of component 3");
- FileUtils.write(new File(dir, "component-42.pb"), "details of component 42");
+ FileUtils.write(new File(dir, "metadata.pb"), "metadata content", Charset.defaultCharset());
+ FileUtils.write(new File(dir, "issues-3.pb"), "external issues of component 3", Charset.defaultCharset());
+ FileUtils.write(new File(dir, "external-issues-3.pb"), "issues of component 3", Charset.defaultCharset());
+ FileUtils.write(new File(dir, "component-42.pb"), "details of component 42", Charset.defaultCharset());
FileStructure structure = new FileStructure(dir);
assertThat(structure.metadataFile()).exists().isFile();
@@ -78,9 +79,19 @@ public class FileStructureTest {
public void contextProperties_file() throws Exception {
File dir = temp.newFolder();
File file = new File(dir, "context-props.pb");
- FileUtils.write(file, "content");
+ FileUtils.write(file, "content", Charset.defaultCharset());
FileStructure structure = new FileStructure(dir);
assertThat(structure.contextProperties()).exists().isFile().isEqualTo(file);
}
+
+ @Test
+ public void telemetryFile_hasTheCorrectName() throws Exception {
+ File dir = temp.newFolder();
+ File file = new File(dir, "telemetry-entries.pb");
+ FileUtils.write(file, "content", Charset.defaultCharset());
+
+ FileStructure structure = new FileStructure(dir);
+ assertThat(structure.telemetryEntries()).exists().isFile().isEqualTo(file);
+ }
}
diff --git a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java
index 368886e2265..4b89c9a3db5 100644
--- a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java
+++ b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java
@@ -154,7 +154,8 @@ public class ScannerReportWriterTest {
// write data
ScannerReport.Cve cve = ScannerReport.Cve.newBuilder()
.setCveId("CVE-2023-20863")
- .setDescription("In spring framework versions prior to 5.2.24 release+ ,5.3.27+ and 6.0.8+ , it is possible for a user to provide a specially crafted SpEL expression that may cause a denial-of-service (DoS) condition.")
+ .setDescription("In spring framework versions prior to 5.2.24 release+ ,5.3.27+ and 6.0.8+ , it is possible for a user to provide a" +
+ " specially crafted SpEL expression that may cause a denial-of-service (DoS) condition.")
.setCvssScore(6.5f)
.setEpssScore(0.00306f)
.setEpssPercentile(0.70277f)
@@ -366,4 +367,25 @@ public class ScannerReportWriterTest {
assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGES, 1)).isTrue();
}
+ @Test
+ public void write_telemetry() {
+
+ List<ScannerReport.TelemetryEntry> input = List.of(
+ ScannerReport.TelemetryEntry.newBuilder()
+ .setKey("key")
+ .setValue("value").build(),
+ ScannerReport.TelemetryEntry.newBuilder()
+ .setKey("key2")
+ .setValue("value2").build());
+
+ underTest.writeTelemetry(input);
+
+ try (CloseableIterator<ScannerReport.TelemetryEntry> telemetryIterator =
+ Protobuf.readStream(underTest.getFileStructure().telemetryEntries(), ScannerReport.TelemetryEntry.parser())) {
+
+ assertThat(telemetryIterator).toIterable()
+ .containsExactlyElementsOf(input)
+ .hasSize(input.size());
+ }
+ }
}