Search in sources :

Example 6 with GoContext

use of org.sonar.go.plugin.GoCoverageReport.GoContext in project sonar-go by SonarSource.

the class GoCoverageReportTest method upload_reports.

@Test
void upload_reports() throws IOException {
    Path baseDir = COVERAGE_DIR.toAbsolutePath();
    SensorContextTester context = SensorContextTester.create(baseDir);
    context.setSettings(new MapSettings());
    context.settings().setProperty("sonar.go.coverage.reportPaths", "coverage.relative.out");
    Path goFilePath = baseDir.resolve("cover.go");
    String content = new String(Files.readAllBytes(goFilePath), UTF_8);
    context.fileSystem().add(TestInputFileBuilder.create("moduleKey", baseDir.toFile(), goFilePath.toFile()).setLanguage("go").setType(InputFile.Type.MAIN).initMetadata(content).build());
    GoContext goContext = new GoContext(File.separatorChar, COVERAGE_DIR.toString());
    GoCoverageReport.saveCoverageReports(context, goContext);
    String fileKey = "moduleKey:cover.go";
    assertThat(context.lineHits(fileKey, 3)).isNull();
    assertThat(context.lineHits(fileKey, 4)).isEqualTo(1);
    assertThat(context.lineHits(fileKey, 5)).isEqualTo(2);
    assertThat(context.conditions(fileKey, 5)).isNull();
    assertThat(context.coveredConditions(fileKey, 5)).isNull();
    assertThat(context.lineHits(fileKey, 6)).isEqualTo(0);
    assertThat(context.lineHits(fileKey, 7)).isEqualTo(0);
    assertThat(context.lineHits(fileKey, 8)).isNull();
}
Also used : Path(java.nio.file.Path) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) MapSettings(org.sonar.api.config.internal.MapSettings) GoContext(org.sonar.go.plugin.GoCoverageReport.GoContext) Test(org.junit.jupiter.api.Test)

Example 7 with GoContext

use of org.sonar.go.plugin.GoCoverageReport.GoContext in project sonar-go by SonarSource.

the class GoCoverageReportTest method parse_coverage_windows_relative.

@Test
void parse_coverage_windows_relative() throws IOException {
    Path coverageFile = COVERAGE_DIR.resolve("coverage.win.relative.out");
    GoContext windowsContext = new GoContext('\\', "C:\\Users\\paul\\go");
    String coverPath = "C:\\Users\\paul\\go\\github.com\\SonarSource\\sonar-go\\sonar-go-plugin\\src\\test\\resources\\coverage\\cover.go";
    assertCoverGo(coverageFile, windowsContext, coverPath);
}
Also used : Path(java.nio.file.Path) GoContext(org.sonar.go.plugin.GoCoverageReport.GoContext) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)7 GoContext (org.sonar.go.plugin.GoCoverageReport.GoContext)7 Path (java.nio.file.Path)5 CoverageStat (org.sonar.go.plugin.GoCoverageReport.CoverageStat)2 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)1 MapSettings (org.sonar.api.config.internal.MapSettings)1 Coverage (org.sonar.go.plugin.GoCoverageReport.Coverage)1 FileCoverage (org.sonar.go.plugin.GoCoverageReport.FileCoverage)1 LineCoverage (org.sonar.go.plugin.GoCoverageReport.LineCoverage)1