mirror of
https://github.com/github/codeql-action.git
synced 2025-12-24 08:10:06 +08:00
pull out mockGetContents method
This commit is contained in:
34
lib/config-utils.test.js
generated
34
lib/config-utils.test.js
generated
@@ -31,6 +31,16 @@ function setInput(name, value) {
|
||||
delete process.env[envVar];
|
||||
}
|
||||
}
|
||||
function mockGetContents(content) {
|
||||
// Passing an auth token is required, so we just use a dummy value
|
||||
let client = new github.GitHub('123');
|
||||
const response = {
|
||||
data: content
|
||||
};
|
||||
const spyGetContents = sinon_1.default.stub(client.repos, "getContents").resolves(response);
|
||||
sinon_1.default.stub(api, "getApiClient").value(() => client);
|
||||
return spyGetContents;
|
||||
}
|
||||
ava_1.default("load empty config", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
@@ -147,13 +157,9 @@ ava_1.default("API client used when reading remote config", async (t) => {
|
||||
paths:
|
||||
- c/d`;
|
||||
const dummyResponse = {
|
||||
data: {
|
||||
content: Buffer.from(inputFileContents).toString("base64"),
|
||||
}
|
||||
content: Buffer.from(inputFileContents).toString("base64"),
|
||||
};
|
||||
let client = new github.GitHub('123');
|
||||
const spyGetContents = sinon_1.default.stub(client.repos, "getContents").resolves(Promise.resolve(dummyResponse));
|
||||
sinon_1.default.stub(api, "getApiClient").value(() => client);
|
||||
const spyGetContents = mockGetContents(dummyResponse);
|
||||
setInput('config-file', 'octo-org/codeql-config/config.yaml@main');
|
||||
await configUtils.loadConfig();
|
||||
t.assert(spyGetContents.called);
|
||||
@@ -163,12 +169,8 @@ ava_1.default("Remote config handles the case where a directory is provided", as
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
const dummyResponse = {
|
||||
data: [],
|
||||
};
|
||||
let client = new github.GitHub('123');
|
||||
sinon_1.default.stub(client.repos, "getContents").resolves(Promise.resolve(dummyResponse));
|
||||
sinon_1.default.stub(api, "getApiClient").value(() => client);
|
||||
const dummyResponse = []; // directories are returned as arrays
|
||||
mockGetContents(dummyResponse);
|
||||
const repoReference = 'octo-org/codeql-config/config.yaml@main';
|
||||
setInput('config-file', repoReference);
|
||||
try {
|
||||
@@ -185,13 +187,9 @@ ava_1.default("Invalid format of remote config handled correctly", async (t) =>
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
const dummyResponse = {
|
||||
data: {
|
||||
// note no "content" property here
|
||||
}
|
||||
// note no "content" property here
|
||||
};
|
||||
let client = new github.GitHub('123');
|
||||
sinon_1.default.stub(client.repos, "getContents").resolves(Promise.resolve(dummyResponse));
|
||||
sinon_1.default.stub(api, "getApiClient").value(() => client);
|
||||
mockGetContents(dummyResponse);
|
||||
const repoReference = 'octo-org/codeql-config/config.yaml@main';
|
||||
setInput('config-file', repoReference);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user