Add a test that Octokit isn't used for local config

This commit is contained in:
Sam Partington 2020-06-24 14:12:36 +01:00
parent b0af5695e6
commit f4cf65ca2d
3 changed files with 54 additions and 4 deletions

View file

@ -1,7 +1,4 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
@ -9,10 +6,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const octokit = __importStar(require("@octokit/rest"));
const ava_1 = __importDefault(require("ava"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const sinon_1 = __importDefault(require("sinon"));
const configUtils = __importStar(require("./config-utils"));
const testing_utils_1 = require("./testing-utils");
const util = __importStar(require("./util"));
@ -114,6 +116,27 @@ ava_1.default("load non-empty input", async (t) => {
t.deepEqual(actualConfig, expectedConfig);
});
});
ava_1.default("Octokit not used when reading local config", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
process.env['RUNNER_TEMP'] = tmpDir;
process.env['GITHUB_WORKSPACE'] = tmpDir;
const spyKit = sinon_1.default.spy(octokit, "Octokit");
const inputFileContents = `
name: my config
disable-default-queries: true
queries:
- uses: ./
paths-ignore:
- a
- b
paths:
- c/d`;
fs.writeFileSync(path.join(tmpDir, 'input'), inputFileContents, 'utf8');
setInput('config-file', 'input');
await configUtils.loadConfig();
t.false(spyKit.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

@ -1,6 +1,8 @@
import * as octokit from '@octokit/rest';
import test from 'ava';
import * as fs from 'fs';
import * as path from 'path';
import sinon from 'sinon';
import * as configUtils from './config-utils';
import {silenceDebugOutput} from './testing-utils';
@ -125,6 +127,31 @@ test("load non-empty input", async t => {
});
});
test("Octokit not used when reading local config", async t => {
return await util.withTmpDir(async tmpDir => {
process.env['RUNNER_TEMP'] = tmpDir;
process.env['GITHUB_WORKSPACE'] = tmpDir;
const spyKit = sinon.spy(octokit, "Octokit");
const inputFileContents = `
name: my config
disable-default-queries: true
queries:
- uses: ./
paths-ignore:
- a
- b
paths:
- c/d`;
fs.writeFileSync(path.join(tmpDir, 'input'), inputFileContents, 'utf8');
setInput('config-file', 'input');
await configUtils.loadConfig();
t.false(spyKit.called);
});
});
function doInvalidInputTest(
testName: string,
inputFileContents: string,