Skip to content

Commit

Permalink
Factor out some code in post-init tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Mercer committed Dec 6, 2022
1 parent 2207a72 commit 697ed97
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 88 deletions.
70 changes: 28 additions & 42 deletions lib/init-action-post-helper.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action-post-helper.test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 33 additions & 44 deletions src/init-action-post-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,48 +86,45 @@ test("post: init action with debug mode on", async (t) => {
});

test("uploads failed SARIF run for typical workflow", async (t) => {
const actionsWorkflow: workflow.Workflow = {
name: "CodeQL",
on: {
push: {
branches: ["main"],
},
pull_request: {
branches: ["main"],
const actionsWorkflow = createTestWorkflow([
{
name: "Checkout repository",
uses: "actions/checkout@v3",
},
{
name: "Initialize CodeQL",
uses: "github/codeql-action/init@v2",
with: {
languages: "javascript",
},
},
jobs: {
analyze: {
name: "CodeQL Analysis",
"runs-on": "ubuntu-latest",
steps: [
{
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",
},
},
],
{
name: "Perform CodeQL Analysis",
uses: "github/codeql-action/analyze@v2",
with: {
category: "my-category",
},
},
};
]);
await testFailedSarifUpload(t, actionsWorkflow, { category: "my-category" });
});

test("uploading failed SARIF run fails when workflow does not reference github/codeql-action", async (t) => {
const actionsWorkflow: workflow.Workflow = {
const actionsWorkflow = createTestWorkflow([
{
name: "Checkout repository",
uses: "actions/checkout@v3",
},
]);
await t.throwsAsync(
async () => await testFailedSarifUpload(t, actionsWorkflow)
);
});

function createTestWorkflow(
steps: workflow.WorkflowJobStep[]
): workflow.Workflow {
return {
name: "CodeQL",
on: {
push: {
Expand All @@ -141,19 +138,11 @@ test("uploading failed SARIF run fails when workflow does not reference github/c
analyze: {
name: "CodeQL Analysis",
"runs-on": "ubuntu-latest",
steps: [
{
name: "Checkout repository",
uses: "actions/checkout@v3",
},
],
steps,
},
},
};
await t.throwsAsync(
async () => await testFailedSarifUpload(t, actionsWorkflow)
);
});
}

async function testFailedSarifUpload(
t: ExecutionContext<unknown>,
Expand Down
2 changes: 1 addition & 1 deletion src/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as yaml from "js-yaml";
import * as api from "./api-client";
import { getRequiredEnvParam } from "./util";

interface WorkflowJobStep {
export interface WorkflowJobStep {
name?: string;
run?: any;
uses?: string;
Expand Down

0 comments on commit 697ed97

Please sign in to comment.