mirror of
https://github.com/github/codeql-action.git
synced 2025-12-24 08:10:06 +08:00
Make remote config retrieval more robust
This commit is contained in:
54
lib/config-utils.test.js
generated
54
lib/config-utils.test.js
generated
@@ -164,6 +164,60 @@ ava_1.default("API client used when reading remote config", async (t) => {
|
||||
sinon_1.default.restore();
|
||||
});
|
||||
});
|
||||
ava_1.default("Remote config handles the case where a directory is provided", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
const dummyResponse = {
|
||||
data: [],
|
||||
};
|
||||
let ok = new octokit.Octokit({
|
||||
userAgent: "CodeQL Action",
|
||||
});
|
||||
const repos = ok.repos;
|
||||
sinon_1.default.stub(repos, "getContents").resolves(Promise.resolve(dummyResponse));
|
||||
ok.repos = repos;
|
||||
sinon_1.default.stub(api, "client").value(ok);
|
||||
const repoReference = 'octo-org/codeql-config/config.yaml@main';
|
||||
setInput('config-file', repoReference);
|
||||
try {
|
||||
await configUtils.loadConfig();
|
||||
throw new Error('loadConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
t.deepEqual(err, new Error(configUtils.getConfigFileDirectoryGivenMessage(repoReference)));
|
||||
}
|
||||
sinon_1.default.restore();
|
||||
});
|
||||
});
|
||||
ava_1.default("Invalid format of remote config handled correctly", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
const dummyResponse = {
|
||||
data: {
|
||||
// note no "content" property here
|
||||
}
|
||||
};
|
||||
let ok = new octokit.Octokit({
|
||||
userAgent: "CodeQL Action",
|
||||
});
|
||||
const repos = ok.repos;
|
||||
sinon_1.default.stub(repos, "getContents").resolves(Promise.resolve(dummyResponse));
|
||||
ok.repos = repos;
|
||||
sinon_1.default.stub(api, "client").value(ok);
|
||||
const repoReference = 'octo-org/codeql-config/config.yaml@main';
|
||||
setInput('config-file', repoReference);
|
||||
try {
|
||||
await configUtils.loadConfig();
|
||||
throw new Error('loadConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
t.deepEqual(err, new Error(configUtils.getConfigFileFormatInvalidMessage(repoReference)));
|
||||
}
|
||||
sinon_1.default.restore();
|
||||
});
|
||||
});
|
||||
function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGenerator) {
|
||||
ava_1.default("load invalid input - " + testName, async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
|
||||
Reference in New Issue
Block a user