Add tests of tryGetFilePath

This commit is contained in:
Robert
2023-05-03 17:24:41 +01:00
parent a3a6784539
commit ecfa701159
2 changed files with 47 additions and 1 deletions

View File

@@ -168,7 +168,7 @@ export function tryGetRule(
return undefined;
}
function tryGetFilePath(
export function tryGetFilePath(
physicalLocation: sarif.PhysicalLocation,
): string | undefined {
const filePath = physicalLocation.artifactLocation?.uri;

View File

@@ -1,6 +1,7 @@
import * as sarif from "sarif";
import {
extractAnalysisAlerts,
tryGetFilePath,
tryGetRule,
tryGetSeverity,
} from "../../src/variant-analysis/sarif-processing";
@@ -288,6 +289,51 @@ describe("SARIF processing", () => {
});
});
describe("tryGetFilePath", () => {
it("should return value when uri is a file path", () => {
const physicalLocation: sarif.PhysicalLocation = {
artifactLocation: {
uri: "foo/bar",
},
};
expect(tryGetFilePath(physicalLocation)).toBe("foo/bar");
});
it("should return undefined when uri has a file scheme", () => {
const physicalLocation: sarif.PhysicalLocation = {
artifactLocation: {
uri: "file:/",
},
};
expect(tryGetFilePath(physicalLocation)).toBe(undefined);
});
it("should return undefined when uri is empty", () => {
const physicalLocation: sarif.PhysicalLocation = {
artifactLocation: {
uri: "",
},
};
expect(tryGetFilePath(physicalLocation)).toBe(undefined);
});
it("should return undefined if artifact location uri is undefined", () => {
const physicalLocation: sarif.PhysicalLocation = {
artifactLocation: {
uri: undefined,
},
};
expect(tryGetFilePath(physicalLocation)).toBe(undefined);
});
it("should return undefined if artifact location is undefined", () => {
const physicalLocation: sarif.PhysicalLocation = {
artifactLocation: undefined,
};
expect(tryGetFilePath(physicalLocation)).toBe(undefined);
});
});
describe("tryGetSeverity", () => {
it("should return undefined if no rule set", () => {
const result = {