Skip to content

Commit c7eb488

Browse files
committed
Add tests
1 parent d14a212 commit c7eb488

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

src/codeql.test.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,84 @@ test(
713713
{},
714714
);
715715

716+
test(
717+
"repo property queries have the highest precedence",
718+
injectedConfigMacro,
719+
{
720+
...defaultAugmentationProperties,
721+
queriesInputCombines: true,
722+
queriesInput: [{ uses: "xxx" }, { uses: "yyy" }],
723+
repoPropertyQueries: {
724+
combines: false,
725+
input: [{ uses: "zzz" }, { uses: "aaa" }],
726+
},
727+
},
728+
{
729+
originalUserInput: {
730+
queries: [{ uses: "uu" }, { uses: "vv" }],
731+
},
732+
},
733+
{
734+
queries: [{ uses: "zzz" }, { uses: "aaa" }],
735+
},
736+
);
737+
738+
test(
739+
"repo property queries combines with queries input",
740+
injectedConfigMacro,
741+
{
742+
...defaultAugmentationProperties,
743+
queriesInputCombines: false,
744+
queriesInput: [{ uses: "xxx" }, { uses: "yyy" }],
745+
repoPropertyQueries: {
746+
combines: true,
747+
input: [{ uses: "zzz" }, { uses: "aaa" }],
748+
},
749+
},
750+
{
751+
originalUserInput: {
752+
queries: [{ uses: "uu" }, { uses: "vv" }],
753+
},
754+
},
755+
{
756+
queries: [
757+
{ uses: "zzz" },
758+
{ uses: "aaa" },
759+
{ uses: "xxx" },
760+
{ uses: "yyy" },
761+
],
762+
},
763+
);
764+
765+
test(
766+
"repo property queries combines everything else",
767+
injectedConfigMacro,
768+
{
769+
...defaultAugmentationProperties,
770+
queriesInputCombines: true,
771+
queriesInput: [{ uses: "xxx" }, { uses: "yyy" }],
772+
repoPropertyQueries: {
773+
combines: true,
774+
input: [{ uses: "zzz" }, { uses: "aaa" }],
775+
},
776+
},
777+
{
778+
originalUserInput: {
779+
queries: [{ uses: "uu" }, { uses: "vv" }],
780+
},
781+
},
782+
{
783+
queries: [
784+
{ uses: "zzz" },
785+
{ uses: "aaa" },
786+
{ uses: "xxx" },
787+
{ uses: "yyy" },
788+
{ uses: "uu" },
789+
{ uses: "vv" },
790+
],
791+
},
792+
);
793+
716794
test("passes a code scanning config AND qlconfig to the CLI", async (t: ExecutionContext<unknown>) => {
717795
await util.withTmpDir(async (tempDir) => {
718796
const runnerConstructorStub = stubToolRunnerConstructor();

src/config/db-config.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,42 @@ test(
271271
},
272272
);
273273

274+
test(
275+
calculateAugmentationMacro,
276+
"With repo property queries",
277+
undefined,
278+
undefined,
279+
[KnownLanguage.javascript],
280+
{
281+
"github-codeql-extra-queries": "a, b, c, d",
282+
},
283+
{
284+
...dbConfig.defaultAugmentationProperties,
285+
repoPropertyQueries: {
286+
combines: false,
287+
input: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }],
288+
},
289+
},
290+
);
291+
292+
test(
293+
calculateAugmentationMacro,
294+
"With repo property queries combining",
295+
undefined,
296+
undefined,
297+
[KnownLanguage.javascript],
298+
{
299+
"github-codeql-extra-queries": "+ a, b, c, d",
300+
},
301+
{
302+
...dbConfig.defaultAugmentationProperties,
303+
repoPropertyQueries: {
304+
combines: true,
305+
input: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }],
306+
},
307+
},
308+
);
309+
274310
const calculateAugmentationErrorMacro = test.macro({
275311
exec: async (
276312
t: ExecutionContext,
@@ -315,6 +351,18 @@ test(
315351
/The workflow property "packs" is invalid/,
316352
);
317353

354+
test(
355+
calculateAugmentationErrorMacro,
356+
"Plus (+) with nothing else (repo property queries)",
357+
undefined,
358+
undefined,
359+
[KnownLanguage.javascript],
360+
{
361+
"github-codeql-extra-queries": " + ",
362+
},
363+
/The repository property "github-codeql-extra-queries" is invalid/,
364+
);
365+
318366
test(
319367
calculateAugmentationErrorMacro,
320368
"Packs input with multiple languages",

0 commit comments

Comments
 (0)