|
1 | 1 | import * as sarif from "sarif"; |
2 | 2 | import { |
3 | 3 | extractAnalysisAlerts, |
| 4 | + tryGetFilePath, |
4 | 5 | tryGetRule, |
5 | 6 | tryGetSeverity, |
6 | 7 | } from "../../src/variant-analysis/sarif-processing"; |
@@ -288,6 +289,51 @@ describe("SARIF processing", () => { |
288 | 289 | }); |
289 | 290 | }); |
290 | 291 |
|
| 292 | + describe("tryGetFilePath", () => { |
| 293 | + it("should return value when uri is a file path", () => { |
| 294 | + const physicalLocation: sarif.PhysicalLocation = { |
| 295 | + artifactLocation: { |
| 296 | + uri: "foo/bar", |
| 297 | + }, |
| 298 | + }; |
| 299 | + expect(tryGetFilePath(physicalLocation)).toBe("foo/bar"); |
| 300 | + }); |
| 301 | + |
| 302 | + it("should return undefined when uri has a file scheme", () => { |
| 303 | + const physicalLocation: sarif.PhysicalLocation = { |
| 304 | + artifactLocation: { |
| 305 | + uri: "file:/", |
| 306 | + }, |
| 307 | + }; |
| 308 | + expect(tryGetFilePath(physicalLocation)).toBe(undefined); |
| 309 | + }); |
| 310 | + |
| 311 | + it("should return undefined when uri is empty", () => { |
| 312 | + const physicalLocation: sarif.PhysicalLocation = { |
| 313 | + artifactLocation: { |
| 314 | + uri: "", |
| 315 | + }, |
| 316 | + }; |
| 317 | + expect(tryGetFilePath(physicalLocation)).toBe(undefined); |
| 318 | + }); |
| 319 | + |
| 320 | + it("should return undefined if artifact location uri is undefined", () => { |
| 321 | + const physicalLocation: sarif.PhysicalLocation = { |
| 322 | + artifactLocation: { |
| 323 | + uri: undefined, |
| 324 | + }, |
| 325 | + }; |
| 326 | + expect(tryGetFilePath(physicalLocation)).toBe(undefined); |
| 327 | + }); |
| 328 | + |
| 329 | + it("should return undefined if artifact location is undefined", () => { |
| 330 | + const physicalLocation: sarif.PhysicalLocation = { |
| 331 | + artifactLocation: undefined, |
| 332 | + }; |
| 333 | + expect(tryGetFilePath(physicalLocation)).toBe(undefined); |
| 334 | + }); |
| 335 | + }); |
| 336 | + |
291 | 337 | describe("tryGetSeverity", () => { |
292 | 338 | it("should return undefined if no rule set", () => { |
293 | 339 | const result = { |
|
0 commit comments