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();
}
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);
}
Aggregations