Add regression test for upload: false
This commit is contained in:
parent
a409f43c7a
commit
dc9c1c1a51
3 changed files with 116 additions and 28 deletions
53
lib/init-action-post-helper.test.js
generated
53
lib/init-action-post-helper.test.js
generated
|
|
@ -103,6 +103,38 @@ const workflow = __importStar(require("./workflow"));
|
||||||
]);
|
]);
|
||||||
await testFailedSarifUpload(t, actionsWorkflow, { category: "my-category" });
|
await testFailedSarifUpload(t, actionsWorkflow, { category: "my-category" });
|
||||||
});
|
});
|
||||||
|
(0, ava_1.default)("doesn't upload failed SARIF for workflow with upload: false", async (t) => {
|
||||||
|
const actionsWorkflow = createTestWorkflow([
|
||||||
|
{
|
||||||
|
name: "Checkout repository",
|
||||||
|
uses: "actions/checkout@v3",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Initialize CodeQL",
|
||||||
|
uses: "github/codeql-action/init@v2",
|
||||||
|
with: {
|
||||||
|
languages: "javascript",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Perform CodeQL Analysis",
|
||||||
|
uses: "github/codeql-action/analyze@v2",
|
||||||
|
with: {
|
||||||
|
category: "my-category",
|
||||||
|
upload: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
await testFailedSarifUpload(t, actionsWorkflow, {
|
||||||
|
expectedLogs: [
|
||||||
|
{
|
||||||
|
message: "Won't upload a failed SARIF file since SARIF upload is disabled.",
|
||||||
|
type: "debug",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
expectUpload: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
(0, ava_1.default)("uploading failed SARIF run fails when workflow does not reference github/codeql-action", async (t) => {
|
(0, ava_1.default)("uploading failed SARIF run fails when workflow does not reference github/codeql-action", async (t) => {
|
||||||
const actionsWorkflow = createTestWorkflow([
|
const actionsWorkflow = createTestWorkflow([
|
||||||
{
|
{
|
||||||
|
|
@ -132,7 +164,7 @@ function createTestWorkflow(steps) {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
async function testFailedSarifUpload(t, actionsWorkflow, { category } = {}) {
|
async function testFailedSarifUpload(t, actionsWorkflow, { category, expectedLogs = [], expectUpload = true, } = {}) {
|
||||||
const config = {
|
const config = {
|
||||||
codeQLCmd: "codeql",
|
codeQLCmd: "codeql",
|
||||||
debugMode: true,
|
debugMode: true,
|
||||||
|
|
@ -153,11 +185,18 @@ async function testFailedSarifUpload(t, actionsWorkflow, { category } = {}) {
|
||||||
uploadFromActions.resolves({ sarifID: "42" });
|
uploadFromActions.resolves({ sarifID: "42" });
|
||||||
const waitForProcessing = sinon.stub(uploadLib, "waitForProcessing");
|
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));
|
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));
|
||||||
t.deepEqual(messages, []);
|
t.deepEqual(messages, expectedLogs);
|
||||||
t.true(diagnosticsExportStub.calledOnceWith(sinon.match.string, category), `Actual args were: ${diagnosticsExportStub.args}`);
|
if (expectUpload) {
|
||||||
t.true(uploadFromActions.calledOnceWith(sinon.match.string, sinon.match.string, category, sinon.match.any), `Actual args were: ${uploadFromActions.args}`);
|
t.true(diagnosticsExportStub.calledOnceWith(sinon.match.string, category), `Actual args were: ${diagnosticsExportStub.args}`);
|
||||||
t.true(waitForProcessing.calledOnceWith(sinon.match.any, "42", sinon.match.any, {
|
t.true(uploadFromActions.calledOnceWith(sinon.match.string, sinon.match.string, category, sinon.match.any), `Actual args were: ${uploadFromActions.args}`);
|
||||||
isUnsuccessfulExecution: true,
|
t.true(waitForProcessing.calledOnceWith(sinon.match.any, "42", sinon.match.any, {
|
||||||
}));
|
isUnsuccessfulExecution: true,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
t.true(diagnosticsExportStub.notCalled);
|
||||||
|
t.true(uploadFromActions.notCalled);
|
||||||
|
t.true(waitForProcessing.notCalled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//# sourceMappingURL=init-action-post-helper.test.js.map
|
//# sourceMappingURL=init-action-post-helper.test.js.map
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -11,6 +11,7 @@ import { parseRepositoryNwo } from "./repository";
|
||||||
import {
|
import {
|
||||||
createFeatures,
|
createFeatures,
|
||||||
getRecordingLogger,
|
getRecordingLogger,
|
||||||
|
LoggedMessage,
|
||||||
setupTests,
|
setupTests,
|
||||||
} from "./testing-utils";
|
} from "./testing-utils";
|
||||||
import * as uploadLib from "./upload-lib";
|
import * as uploadLib from "./upload-lib";
|
||||||
|
|
@ -111,6 +112,40 @@ test("uploads failed SARIF run for typical workflow", async (t) => {
|
||||||
await testFailedSarifUpload(t, actionsWorkflow, { category: "my-category" });
|
await testFailedSarifUpload(t, actionsWorkflow, { category: "my-category" });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("doesn't upload failed SARIF for workflow with upload: false", async (t) => {
|
||||||
|
const actionsWorkflow = createTestWorkflow([
|
||||||
|
{
|
||||||
|
name: "Checkout repository",
|
||||||
|
uses: "actions/checkout@v3",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Initialize CodeQL",
|
||||||
|
uses: "github/codeql-action/init@v2",
|
||||||
|
with: {
|
||||||
|
languages: "javascript",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Perform CodeQL Analysis",
|
||||||
|
uses: "github/codeql-action/analyze@v2",
|
||||||
|
with: {
|
||||||
|
category: "my-category",
|
||||||
|
upload: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
await testFailedSarifUpload(t, actionsWorkflow, {
|
||||||
|
expectedLogs: [
|
||||||
|
{
|
||||||
|
message:
|
||||||
|
"Won't upload a failed SARIF file since SARIF upload is disabled.",
|
||||||
|
type: "debug",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
expectUpload: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("uploading failed SARIF run fails when workflow does not reference github/codeql-action", async (t) => {
|
test("uploading failed SARIF run fails when workflow does not reference github/codeql-action", async (t) => {
|
||||||
const actionsWorkflow = createTestWorkflow([
|
const actionsWorkflow = createTestWorkflow([
|
||||||
{
|
{
|
||||||
|
|
@ -149,7 +184,15 @@ function createTestWorkflow(
|
||||||
async function testFailedSarifUpload(
|
async function testFailedSarifUpload(
|
||||||
t: ExecutionContext<unknown>,
|
t: ExecutionContext<unknown>,
|
||||||
actionsWorkflow: workflow.Workflow,
|
actionsWorkflow: workflow.Workflow,
|
||||||
{ category }: { category?: string } = {}
|
{
|
||||||
|
category,
|
||||||
|
expectedLogs = [],
|
||||||
|
expectUpload = true,
|
||||||
|
}: {
|
||||||
|
category?: string;
|
||||||
|
expectedLogs?: LoggedMessage[];
|
||||||
|
expectUpload?: boolean;
|
||||||
|
} = {}
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const config = {
|
const config = {
|
||||||
codeQLCmd: "codeql",
|
codeQLCmd: "codeql",
|
||||||
|
|
@ -180,23 +223,29 @@ async function testFailedSarifUpload(
|
||||||
createFeatures([Feature.UploadFailedSarifEnabled]),
|
createFeatures([Feature.UploadFailedSarifEnabled]),
|
||||||
getRecordingLogger(messages)
|
getRecordingLogger(messages)
|
||||||
);
|
);
|
||||||
t.deepEqual(messages, []);
|
t.deepEqual(messages, expectedLogs);
|
||||||
t.true(
|
if (expectUpload) {
|
||||||
diagnosticsExportStub.calledOnceWith(sinon.match.string, category),
|
t.true(
|
||||||
`Actual args were: ${diagnosticsExportStub.args}`
|
diagnosticsExportStub.calledOnceWith(sinon.match.string, category),
|
||||||
);
|
`Actual args were: ${diagnosticsExportStub.args}`
|
||||||
t.true(
|
);
|
||||||
uploadFromActions.calledOnceWith(
|
t.true(
|
||||||
sinon.match.string,
|
uploadFromActions.calledOnceWith(
|
||||||
sinon.match.string,
|
sinon.match.string,
|
||||||
category,
|
sinon.match.string,
|
||||||
sinon.match.any
|
category,
|
||||||
),
|
sinon.match.any
|
||||||
`Actual args were: ${uploadFromActions.args}`
|
),
|
||||||
);
|
`Actual args were: ${uploadFromActions.args}`
|
||||||
t.true(
|
);
|
||||||
waitForProcessing.calledOnceWith(sinon.match.any, "42", sinon.match.any, {
|
t.true(
|
||||||
isUnsuccessfulExecution: true,
|
waitForProcessing.calledOnceWith(sinon.match.any, "42", sinon.match.any, {
|
||||||
})
|
isUnsuccessfulExecution: true,
|
||||||
);
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
t.true(diagnosticsExportStub.notCalled);
|
||||||
|
t.true(uploadFromActions.notCalled);
|
||||||
|
t.true(waitForProcessing.notCalled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue