Improve method naming

This commit is contained in:
Henry Mercer 2022-12-22 18:33:06 +00:00
parent e09fbf5b4a
commit 3224214d91
6 changed files with 104 additions and 47 deletions

View file

@ -125,7 +125,7 @@ const workflow = __importStar(require("./workflow"));
},
},
]);
await testFailedSarifUpload(t, actionsWorkflow, {
const result = await testFailedSarifUpload(t, actionsWorkflow, {
expectedLogs: [
{
message: "Won't upload a failed SARIF file since SARIF upload is disabled.",
@ -134,6 +134,7 @@ const workflow = __importStar(require("./workflow"));
],
expectUpload: false,
});
t.is(result.upload_failed_run_skipped_because, "SARIF upload is disabled");
});
(0, ava_1.default)("uploading failed SARIF run fails when workflow does not reference github/codeql-action", async (t) => {
const actionsWorkflow = createTestWorkflow([
@ -142,7 +143,19 @@ const workflow = __importStar(require("./workflow"));
uses: "actions/checkout@v3",
},
]);
await t.throwsAsync(async () => await testFailedSarifUpload(t, actionsWorkflow));
const expectedError = "Could not get upload input to github/codeql-action/analyze since the analyze job does not " +
"call github/codeql-action/analyze.";
const result = await testFailedSarifUpload(t, actionsWorkflow, {
expectedLogs: [
{
message: `Failed to upload a SARIF file for this failed CodeQL code scanning run. Error: ${expectedError}`,
type: "debug",
},
],
expectUpload: false,
});
t.is(result.upload_failed_run_error, expectedError);
t.truthy(result.upload_failed_run_stack_trace);
});
function createTestWorkflow(steps) {
return {
@ -182,9 +195,18 @@ async function testFailedSarifUpload(t, actionsWorkflow, { category, expectedLog
const diagnosticsExportStub = sinon.stub(codeqlObject, "diagnosticsExport");
sinon.stub(workflow, "getWorkflow").resolves(actionsWorkflow);
const uploadFromActions = sinon.stub(uploadLib, "uploadFromActions");
uploadFromActions.resolves({ sarifID: "42" });
uploadFromActions.resolves({
sarifID: "42",
statusReport: { raw_upload_size_bytes: 20, zipped_upload_size_bytes: 10 },
});
const waitForProcessing = sinon.stub(uploadLib, "waitForProcessing");
await initActionPostHelper.uploadFailedSarif(config, (0, repository_1.parseRepositoryNwo)("github/codeql-action"), (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.UploadFailedSarifEnabled]), (0, testing_utils_1.getRecordingLogger)(messages));
const result = await initActionPostHelper.tryUploadSarifIfRunFailed(config, (0, repository_1.parseRepositoryNwo)("github/codeql-action"), (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.UploadFailedSarifEnabled]), (0, testing_utils_1.getRecordingLogger)(messages));
if (expectUpload) {
t.deepEqual(result, {
raw_upload_size_bytes: 20,
zipped_upload_size_bytes: 10,
});
}
t.deepEqual(messages, expectedLogs);
if (expectUpload) {
t.true(diagnosticsExportStub.calledOnceWith(sinon.match.string, category), `Actual args were: ${diagnosticsExportStub.args}`);
@ -198,5 +220,6 @@ async function testFailedSarifUpload(t, actionsWorkflow, { category, expectedLog
t.true(uploadFromActions.notCalled);
t.true(waitForProcessing.notCalled);
}
return result;
}
//# sourceMappingURL=init-action-post-helper.test.js.map