add tempDir and toolCacheDir to config
This commit is contained in:
parent
e9e2284547
commit
9c29fe283d
18 changed files with 156 additions and 114 deletions
38
lib/config-utils.test.js
generated
38
lib/config-utils.test.js
generated
|
|
@ -69,8 +69,8 @@ ava_1.default("load empty config", async (t) => {
|
|||
};
|
||||
},
|
||||
});
|
||||
const config = await configUtils.initConfig();
|
||||
t.deepEqual(config, await configUtils.getDefaultConfig());
|
||||
const config = await configUtils.initConfig(tmpDir, tmpDir);
|
||||
t.deepEqual(config, await configUtils.getDefaultConfig(tmpDir, tmpDir));
|
||||
});
|
||||
});
|
||||
ava_1.default("loading config saves config", async (t) => {
|
||||
|
|
@ -89,14 +89,14 @@ ava_1.default("loading config saves config", async (t) => {
|
|||
},
|
||||
});
|
||||
// Sanity check the saved config file does not already exist
|
||||
t.false(fs.existsSync(configUtils.getPathToParsedConfigFile()));
|
||||
t.false(fs.existsSync(configUtils.getPathToParsedConfigFile(tmpDir)));
|
||||
// Sanity check that getConfig throws before we have called initConfig
|
||||
await t.throwsAsync(configUtils.getConfig);
|
||||
const config1 = await configUtils.initConfig();
|
||||
await t.throwsAsync(() => configUtils.getConfig(tmpDir));
|
||||
const config1 = await configUtils.initConfig(tmpDir, tmpDir);
|
||||
// The saved config file should now exist
|
||||
t.true(fs.existsSync(configUtils.getPathToParsedConfigFile()));
|
||||
t.true(fs.existsSync(configUtils.getPathToParsedConfigFile(tmpDir)));
|
||||
// And that same newly-initialised config should now be returned by getConfig
|
||||
const config2 = await configUtils.getConfig();
|
||||
const config2 = await configUtils.getConfig(tmpDir);
|
||||
t.deepEqual(config1, config2);
|
||||
});
|
||||
});
|
||||
|
|
@ -106,7 +106,7 @@ ava_1.default("load input outside of workspace", async (t) => {
|
|||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
setInput('config-file', '../input');
|
||||
try {
|
||||
await configUtils.initConfig();
|
||||
await configUtils.initConfig(tmpDir, tmpDir);
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -121,7 +121,7 @@ ava_1.default("load non-local input with invalid repo syntax", async (t) => {
|
|||
// no filename given, just a repo
|
||||
setInput('config-file', 'octo-org/codeql-config@main');
|
||||
try {
|
||||
await configUtils.initConfig();
|
||||
await configUtils.initConfig(tmpDir, tmpDir);
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -137,7 +137,7 @@ ava_1.default("load non-existent input", async (t) => {
|
|||
setInput('config-file', 'input');
|
||||
setInput('languages', 'javascript');
|
||||
try {
|
||||
await configUtils.initConfig();
|
||||
await configUtils.initConfig(tmpDir, tmpDir);
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -188,11 +188,13 @@ ava_1.default("load non-empty input", async (t) => {
|
|||
'paths-ignore': ['a', 'b'],
|
||||
paths: ['c/d'],
|
||||
},
|
||||
tempDir: tmpDir,
|
||||
toolCacheDir: tmpDir,
|
||||
};
|
||||
fs.writeFileSync(path.join(tmpDir, 'input'), inputFileContents, 'utf8');
|
||||
setInput('config-file', 'input');
|
||||
setInput('languages', 'javascript');
|
||||
const actualConfig = await configUtils.initConfig();
|
||||
const actualConfig = await configUtils.initConfig(tmpDir, tmpDir);
|
||||
// Should exactly equal the object we constructed earlier
|
||||
t.deepEqual(actualConfig, expectedConfig);
|
||||
});
|
||||
|
|
@ -231,7 +233,7 @@ ava_1.default("default queries are used", async (t) => {
|
|||
fs.writeFileSync(path.join(tmpDir, 'input'), inputFileContents, 'utf8');
|
||||
setInput('config-file', 'input');
|
||||
setInput('languages', 'javascript');
|
||||
await configUtils.initConfig();
|
||||
await configUtils.initConfig(tmpDir, tmpDir);
|
||||
// Check resolve queries was called correctly
|
||||
t.deepEqual(resolveQueriesArgs.length, 1);
|
||||
t.deepEqual(resolveQueriesArgs[0].queries, ['javascript-code-scanning.qls']);
|
||||
|
|
@ -275,7 +277,7 @@ ava_1.default("API client used when reading remote config", async (t) => {
|
|||
fs.mkdirSync(path.join(tmpDir, 'foo/bar'), { recursive: true });
|
||||
setInput('config-file', 'octo-org/codeql-config/config.yaml@main');
|
||||
setInput('languages', 'javascript');
|
||||
await configUtils.initConfig();
|
||||
await configUtils.initConfig(tmpDir, tmpDir);
|
||||
t.assert(spyGetContents.called);
|
||||
});
|
||||
});
|
||||
|
|
@ -288,7 +290,7 @@ ava_1.default("Remote config handles the case where a directory is provided", as
|
|||
const repoReference = 'octo-org/codeql-config/config.yaml@main';
|
||||
setInput('config-file', repoReference);
|
||||
try {
|
||||
await configUtils.initConfig();
|
||||
await configUtils.initConfig(tmpDir, tmpDir);
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -307,7 +309,7 @@ ava_1.default("Invalid format of remote config handled correctly", async (t) =>
|
|||
const repoReference = 'octo-org/codeql-config/config.yaml@main';
|
||||
setInput('config-file', repoReference);
|
||||
try {
|
||||
await configUtils.initConfig();
|
||||
await configUtils.initConfig(tmpDir, tmpDir);
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -321,7 +323,7 @@ ava_1.default("No detected languages", async (t) => {
|
|||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
mockListLanguages([]);
|
||||
try {
|
||||
await configUtils.initConfig();
|
||||
await configUtils.initConfig(tmpDir, tmpDir);
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -335,7 +337,7 @@ ava_1.default("Unknown languages", async (t) => {
|
|||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
setInput('languages', 'ruby,english');
|
||||
try {
|
||||
await configUtils.initConfig();
|
||||
await configUtils.initConfig(tmpDir, tmpDir);
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -362,7 +364,7 @@ function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGen
|
|||
setInput('config-file', 'input');
|
||||
setInput('languages', 'javascript');
|
||||
try {
|
||||
await configUtils.initConfig();
|
||||
await configUtils.initConfig(tmpDir, tmpDir);
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue