Add a test that an Octokit request is made for remote config

This commit is contained in:
Sam Partington 2020-06-25 15:06:15 +01:00
parent 32c9898fa4
commit 388403b46e
3 changed files with 54 additions and 1 deletions

View file

@ -163,6 +163,30 @@ ava_1.default("Remote and local configuration paths correctly identified", t =>
// Otherwise look locally (this is the fallback)
t.assert(configUtils.isLocal('file'));
});
ava_1.default("Octokit used when reading remote config", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
process.env['RUNNER_TEMP'] = tmpDir;
process.env['GITHUB_WORKSPACE'] = tmpDir;
const inputFileContents = `
name: my config
disable-default-queries: true
queries:
- uses: ./
paths-ignore:
- a
- b
paths:
- c/d`;
let ok = new octokit.Octokit({
userAgent: "CodeQL Action",
});
const spyRequest = sinon_1.default.stub(ok, "request").resolves(inputFileContents);
sinon_1.default.stub(octokit, "Octokit").resolves(ok);
setInput('config-file', 'octo-org/codeql-config/config.yaml@main');
await configUtils.loadConfig();
t.assert(spyRequest.called);
});
});
function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGenerator) {
ava_1.default("load invalid input - " + testName, async (t) => {
return await util.withTmpDir(async (tmpDir) => {

File diff suppressed because one or more lines are too long

View file

@ -183,6 +183,35 @@ test("Remote and local configuration paths correctly identified", t => {
t.assert(configUtils.isLocal('file'));
});
test("Octokit used when reading remote config", async t => {
return await util.withTmpDir(async tmpDir => {
process.env['RUNNER_TEMP'] = tmpDir;
process.env['GITHUB_WORKSPACE'] = tmpDir;
const inputFileContents = `
name: my config
disable-default-queries: true
queries:
- uses: ./
paths-ignore:
- a
- b
paths:
- c/d`;
let ok = new octokit.Octokit({
userAgent: "CodeQL Action",
});
const spyRequest = sinon.stub(ok, "request").resolves(inputFileContents);
sinon.stub(octokit, "Octokit").resolves(ok);
setInput('config-file', 'octo-org/codeql-config/config.yaml@main');
await configUtils.loadConfig();
t.assert(spyRequest.called);
});
});
function doInvalidInputTest(
testName: string,
inputFileContents: string,