Skip to content

Commit 47cec7a

Browse files
committed
add test with config file and input together
1 parent 7b876ae commit 47cec7a

File tree

3 files changed

+142
-1
lines changed

3 files changed

+142
-1
lines changed

lib/config-utils.test.js

+49
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.test.ts

+92
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,98 @@ test("Queries can be specified using config input", async (t) => {
10081008
});
10091009
});
10101010

1011+
test("Using config input and file together, config input should be used.", async (t) => {
1012+
return await util.withTmpDir(async (tmpDir) => {
1013+
process.env["RUNNER_TEMP"] = tmpDir;
1014+
process.env["GITHUB_WORKSPACE"] = tmpDir;
1015+
1016+
const inputFileContents = `
1017+
name: my config
1018+
queries:
1019+
- uses: ./foo_file`;
1020+
const configFilePath = createConfigFile(inputFileContents, tmpDir);
1021+
1022+
const configInput = `
1023+
name: my config
1024+
queries:
1025+
- uses: ./foo
1026+
packs:
1027+
javascript:
1028+
1029+
python:
1030+
1031+
`;
1032+
1033+
fs.mkdirSync(path.join(tmpDir, "foo"));
1034+
1035+
const resolveQueriesArgs: Array<{
1036+
queries: string[];
1037+
extraSearchPath: string | undefined;
1038+
}> = [];
1039+
const codeQL = setCodeQL({
1040+
async resolveQueries(
1041+
queries: string[],
1042+
extraSearchPath: string | undefined
1043+
) {
1044+
resolveQueriesArgs.push({ queries, extraSearchPath });
1045+
return queriesToResolvedQueryForm(queries);
1046+
},
1047+
async packDownload(): Promise<PackDownloadOutput> {
1048+
return { packs: [] };
1049+
},
1050+
});
1051+
1052+
// Only JS, python packs will be ignored
1053+
const languages = "javascript";
1054+
1055+
const config = await configUtils.initConfig(
1056+
languages,
1057+
undefined,
1058+
undefined,
1059+
undefined,
1060+
undefined,
1061+
configFilePath,
1062+
configInput,
1063+
false,
1064+
false,
1065+
"",
1066+
"",
1067+
{ owner: "github", repo: "example" },
1068+
tmpDir,
1069+
codeQL,
1070+
tmpDir,
1071+
gitHubVersion,
1072+
sampleApiDetails,
1073+
createFeatures([]),
1074+
getRunnerLogger(true)
1075+
);
1076+
1077+
// Check resolveQueries was called correctly
1078+
// It'll be called once for the default queries
1079+
// and once for `./foo` from the config file.
1080+
t.deepEqual(resolveQueriesArgs.length, 2);
1081+
t.deepEqual(resolveQueriesArgs[1].queries.length, 1);
1082+
t.true(resolveQueriesArgs[1].queries[0].endsWith(`${path.sep}foo`));
1083+
t.deepEqual(config.packs as unknown, {
1084+
[Language.javascript]: ["a/[email protected]"],
1085+
});
1086+
1087+
// Now check that the end result contains the default queries and the query from config
1088+
t.deepEqual(config.queries["javascript"].builtin.length, 1);
1089+
t.deepEqual(config.queries["javascript"].custom.length, 1);
1090+
t.true(
1091+
config.queries["javascript"].builtin[0].endsWith(
1092+
"javascript-code-scanning.qls"
1093+
)
1094+
);
1095+
t.true(
1096+
config.queries["javascript"].custom[0].queries[0].endsWith(
1097+
`${path.sep}foo`
1098+
)
1099+
);
1100+
});
1101+
});
1102+
10111103
test("Invalid queries in workflow file handled correctly", async (t) => {
10121104
return await util.withTmpDir(async (tmpDir) => {
10131105
const queries = "foo/bar@v1@v3";

0 commit comments

Comments
 (0)