Skip to content

Commit

Permalink
VSTS-301 Fix semver check for compatibility with SQ >= 10.0 (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-caro-sonarsource committed Jun 5, 2023
1 parent 5c23ba9 commit d8b2469
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commonv5/ts/sonarqube/TaskReport.ts
Expand Up @@ -46,7 +46,7 @@ export default class TaskReport {
let taskReportGlob: string;
let taskReportGlobResult: string[];

if (endpoint.type === EndpointType.SonarQube && serverVersion < semver.parse("7.2.0")) {
if (endpoint.type === EndpointType.SonarQube && semver.satisfies(serverVersion, "<7.2.0")) {
tl.debug(
"SonarQube version < 7.2.0 detected, falling back to default location(s) for report-task.txt file."
);
Expand Down
31 changes: 31 additions & 0 deletions commonv5/ts/sonarqube/__tests__/TaskReport-test.ts
Expand Up @@ -135,6 +135,37 @@ it("should find report files for SonarQube above 7.2.0", async () => {
expect(tl.findMatch).toHaveBeenCalledWith("mock root search path", expectedSearchPath);
});

it.each(["10.0.0", "20.0.0"])(
"should find report files for SonarQube above %p",
async (version) => {
// using spyOn so we can reset the original behaviour
jest.spyOn(tl, "getVariable").mockImplementation(() => "mock root search path");
jest.spyOn(tl, "findMatch").mockImplementation(() => ["path1", "path2"]);

const endpoint = new Endpoint(EndpointType.SonarQube, null);

const reportFiles = await TaskReport.findTaskFileReport(endpoint, new semver.SemVer(version));

expect(reportFiles.length).toBe(2);
expect(reportFiles[0]).toBe("path1");
expect(reportFiles[1]).toBe("path2");

expect(tl.getVariable).toHaveBeenCalledTimes(2);
expect(tl.getVariable).toBeCalledWith("Agent.TempDirectory");

// Calculate the expected path to take account of different
// path separators in Windows/non-Windows
const expectedSearchPath = path.join(
"sonar",
tl.getVariable("Build.BuildNumber"),
"**",
"report-task.txt"
);
expect(tl.findMatch).toHaveBeenCalledTimes(1);
expect(tl.findMatch).toHaveBeenCalledWith("mock root search path", expectedSearchPath);
}
);

it("should find report files for SonarQube below 7.2.0", async () => {
// using spyOn so we can reset the original behaviour
jest.spyOn(tl, "getVariable").mockImplementation(() => "mock root search path");
Expand Down

0 comments on commit d8b2469

Please sign in to comment.