Add test for modified findSarifFilesInDir
This commit is contained in:
parent
f7fbaa019f
commit
51891595a7
6 changed files with 34 additions and 10 deletions
14
lib/upload-lib.js
generated
14
lib/upload-lib.js
generated
|
|
@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.InvalidSarifUploadError = exports.CodeQualityTarget = exports.CodeScanningTarget = exports.SARIF_UPLOAD_TARGET = void 0;
|
||||
exports.InvalidSarifUploadError = exports.CodeQualityTarget = exports.CodeScanningTarget = exports.defaultIsSarif = exports.qualityIsSarif = exports.SARIF_UPLOAD_TARGET = void 0;
|
||||
exports.shouldShowCombineSarifFilesDeprecationWarning = shouldShowCombineSarifFilesDeprecationWarning;
|
||||
exports.populateRunAutomationDetails = populateRunAutomationDetails;
|
||||
exports.findSarifFilesInDir = findSarifFilesInDir;
|
||||
|
|
@ -281,10 +281,12 @@ async function uploadPayload(payload, repositoryNwo, logger, target = SARIF_UPLO
|
|||
}
|
||||
}
|
||||
const qualityIsSarif = (name) => name.endsWith(".quality.sarif");
|
||||
const defaultIsSarif = (name) => name.endsWith(".sarif") && !qualityIsSarif(name);
|
||||
exports.qualityIsSarif = qualityIsSarif;
|
||||
const defaultIsSarif = (name) => name.endsWith(".sarif") && !(0, exports.qualityIsSarif)(name);
|
||||
exports.defaultIsSarif = defaultIsSarif;
|
||||
// Recursively walks a directory and returns all SARIF files it finds.
|
||||
// Does not follow symlinks.
|
||||
function findSarifFilesInDir(sarifPath, isSarif = defaultIsSarif) {
|
||||
function findSarifFilesInDir(sarifPath, isSarif = exports.defaultIsSarif) {
|
||||
const sarifFiles = [];
|
||||
const walkSarifFiles = (dir) => {
|
||||
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||
|
|
@ -300,7 +302,7 @@ function findSarifFilesInDir(sarifPath, isSarif = defaultIsSarif) {
|
|||
walkSarifFiles(sarifPath);
|
||||
return sarifFiles;
|
||||
}
|
||||
function getSarifFilePaths(sarifPath, isSarif = defaultIsSarif) {
|
||||
function getSarifFilePaths(sarifPath, isSarif = exports.defaultIsSarif) {
|
||||
if (!fs.existsSync(sarifPath)) {
|
||||
// This is always a configuration error, even for first-party runs.
|
||||
throw new util_1.ConfigurationError(`Path does not exist: ${sarifPath}`);
|
||||
|
|
@ -420,13 +422,13 @@ function buildPayload(commitOid, ref, analysisKey, analysisName, zippedSarif, wo
|
|||
exports.CodeScanningTarget = {
|
||||
name: "code scanning",
|
||||
target: SARIF_UPLOAD_TARGET.CODE_SCANNING_UPLOAD_TARGET,
|
||||
sarifFilter: defaultIsSarif,
|
||||
sarifFilter: exports.defaultIsSarif,
|
||||
sentinelPrefix: "CODEQL_UPLOAD_SARIF_",
|
||||
};
|
||||
exports.CodeQualityTarget = {
|
||||
name: "code quality",
|
||||
target: SARIF_UPLOAD_TARGET.CODE_QUALITY_UPLOAD_TARGET,
|
||||
sarifFilter: qualityIsSarif,
|
||||
sarifFilter: exports.qualityIsSarif,
|
||||
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_",
|
||||
};
|
||||
/**
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
8
lib/upload-lib.test.js
generated
8
lib/upload-lib.test.js
generated
|
|
@ -91,6 +91,9 @@ ava_1.default.beforeEach(() => {
|
|||
fs.mkdirSync(path.join(tmpDir, "dir3"));
|
||||
fs.symlinkSync(tmpDir, path.join(tmpDir, "dir3", "symlink1"), "dir");
|
||||
fs.symlinkSync(path.join(tmpDir, "a.sarif"), path.join(tmpDir, "dir3", "symlink2.sarif"), "file");
|
||||
// add some `.quality.sarif` files that should be ignored, unless we look for them specifically
|
||||
fs.writeFileSync(path.join(tmpDir, "a.quality.sarif"), "");
|
||||
fs.writeFileSync(path.join(tmpDir, "dir1", "b.quality.sarif"), "");
|
||||
const sarifFiles = uploadLib.findSarifFilesInDir(tmpDir);
|
||||
t.deepEqual(sarifFiles, [
|
||||
path.join(tmpDir, "a.sarif"),
|
||||
|
|
@ -98,6 +101,11 @@ ava_1.default.beforeEach(() => {
|
|||
path.join(tmpDir, "dir1", "d.sarif"),
|
||||
path.join(tmpDir, "dir1", "dir2", "e.sarif"),
|
||||
]);
|
||||
const qualitySarifFiles = uploadLib.findSarifFilesInDir(tmpDir, uploadLib.qualityIsSarif);
|
||||
t.deepEqual(qualitySarifFiles, [
|
||||
path.join(tmpDir, "a.quality.sarif"),
|
||||
path.join(tmpDir, "dir1", "b.quality.sarif"),
|
||||
]);
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("populateRunAutomationDetails", (t) => {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -122,6 +122,10 @@ test("finding SARIF files", async (t) => {
|
|||
"file",
|
||||
);
|
||||
|
||||
// add some `.quality.sarif` files that should be ignored, unless we look for them specifically
|
||||
fs.writeFileSync(path.join(tmpDir, "a.quality.sarif"), "");
|
||||
fs.writeFileSync(path.join(tmpDir, "dir1", "b.quality.sarif"), "");
|
||||
|
||||
const sarifFiles = uploadLib.findSarifFilesInDir(tmpDir);
|
||||
|
||||
t.deepEqual(sarifFiles, [
|
||||
|
|
@ -130,6 +134,16 @@ test("finding SARIF files", async (t) => {
|
|||
path.join(tmpDir, "dir1", "d.sarif"),
|
||||
path.join(tmpDir, "dir1", "dir2", "e.sarif"),
|
||||
]);
|
||||
|
||||
const qualitySarifFiles = uploadLib.findSarifFilesInDir(
|
||||
tmpDir,
|
||||
uploadLib.qualityIsSarif,
|
||||
);
|
||||
|
||||
t.deepEqual(qualitySarifFiles, [
|
||||
path.join(tmpDir, "a.quality.sarif"),
|
||||
path.join(tmpDir, "dir1", "b.quality.sarif"),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -380,8 +380,8 @@ export interface UploadResult {
|
|||
sarifID: string;
|
||||
}
|
||||
|
||||
const qualityIsSarif = (name: string) => name.endsWith(".quality.sarif");
|
||||
const defaultIsSarif = (name: string) =>
|
||||
export const qualityIsSarif = (name: string) => name.endsWith(".quality.sarif");
|
||||
export const defaultIsSarif = (name: string) =>
|
||||
name.endsWith(".sarif") && !qualityIsSarif(name);
|
||||
|
||||
// Recursively walks a directory and returns all SARIF files it finds.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue