Add tests of tryGetFilePath
This commit is contained in:
@@ -168,7 +168,7 @@ export function tryGetRule(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function tryGetFilePath(
|
||||
export function tryGetFilePath(
|
||||
physicalLocation: sarif.PhysicalLocation,
|
||||
): string | undefined {
|
||||
const filePath = physicalLocation.artifactLocation?.uri;
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user