Skip to content

Commit

Permalink
Fix GHAE CodeQL setup test
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Mercer committed Jan 10, 2023
1 parent 9203e31 commit 9f8ddbd
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
19 changes: 15 additions & 4 deletions lib/codeql.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/codeql.test.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lib/testing-utils.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/testing-utils.js.map

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

21 changes: 17 additions & 4 deletions src/codeql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ setupTests(test);
const sampleApiDetails = {
auth: "token",
url: "https://github.com",
apiURL: undefined,
registriesAuthTokens: undefined,
apiURL: "https://api.github.com",
};

const sampleGHAEApiDetails = {
auth: "token",
url: "https://example.githubenterprise.com",
apiURL: undefined,
registriesAuthTokens: undefined,
apiURL: "https://example.githubenterprise.com/api/v3",
};

let stubConfig: Config;
Expand Down Expand Up @@ -362,6 +360,21 @@ test("download codeql bundle from github ae endpoint", async (t) => {
path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`)
);

sinon
.stub(actionsUtil, "getRequiredInput")
.withArgs("token")
.returns(sampleGHAEApiDetails.auth);
const requiredEnvParamStub = sinon.stub(util, "getRequiredEnvParam");
requiredEnvParamStub
.withArgs("GITHUB_SERVER_URL")
.returns(sampleGHAEApiDetails.url);
requiredEnvParamStub
.withArgs("GITHUB_API_URL")
.returns(sampleGHAEApiDetails.apiURL);

sinon.stub(actionsUtil, "isRunningLocalAction").returns(false);
process.env["GITHUB_ACTION_REPOSITORY"] = "github/codeql-action";

await codeql.setupCodeQL(
undefined,
sampleGHAEApiDetails,
Expand Down
4 changes: 4 additions & 0 deletions src/testing-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as github from "@actions/github";
import { TestFn } from "ava";
import * as nock from "nock";
import * as sinon from "sinon";

import * as apiClient from "./api-client";
Expand Down Expand Up @@ -90,6 +91,9 @@ export function setupTests(test: TestFn<any>) {
process.stdout.write(t.context.testOutput);
}

// Undo any modifications made by nock
nock.cleanAll();

// Undo any modifications made by sinon
sinon.restore();

Expand Down

0 comments on commit 9f8ddbd

Please sign in to comment.