Skip to content

Commit dc1166c

Browse files
committed
Move tests for functions now in db-config
1 parent ddc6d54 commit dc1166c

File tree

2 files changed

+331
-330
lines changed

2 files changed

+331
-330
lines changed

src/config-utils.test.ts

Lines changed: 0 additions & 330 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
import {
3434
GitHubVariant,
3535
GitHubVersion,
36-
prettyPrintPack,
3736
ConfigurationError,
3837
withTmpDir,
3938
BuildMode,
@@ -691,337 +690,8 @@ test("Unknown languages", async (t) => {
691690
});
692691
});
693692

694-
/**
695-
* Test macro for ensuring the packs block is valid
696-
*/
697-
const parsePacksMacro = test.macro({
698-
exec: (
699-
t: ExecutionContext<unknown>,
700-
packsInput: string,
701-
languages: Language[],
702-
expected: configUtils.Packs | undefined,
703-
) =>
704-
t.deepEqual(
705-
configUtils.parsePacksFromInput(packsInput, languages, false),
706-
expected,
707-
),
708-
709-
title: (providedTitle = "") => `Parse Packs: ${providedTitle}`,
710-
});
711-
712-
/**
713-
* Test macro for testing when the packs block is invalid
714-
*/
715-
const parsePacksErrorMacro = test.macro({
716-
exec: (
717-
t: ExecutionContext<unknown>,
718-
packsInput: string,
719-
languages: Language[],
720-
expected: RegExp,
721-
) =>
722-
t.throws(
723-
() => configUtils.parsePacksFromInput(packsInput, languages, false),
724-
{
725-
message: expected,
726-
},
727-
),
728-
title: (providedTitle = "") => `Parse Packs Error: ${providedTitle}`,
729-
});
730-
731-
/**
732-
* Test macro for testing when the packs block is invalid
733-
*/
734-
const invalidPackNameMacro = test.macro({
735-
exec: (t: ExecutionContext, name: string) =>
736-
parsePacksErrorMacro.exec(
737-
t,
738-
name,
739-
[KnownLanguage.cpp],
740-
new RegExp(`^"${name}" is not a valid pack$`),
741-
),
742-
title: (_providedTitle: string | undefined, arg: string | undefined) =>
743-
`Invalid pack string: ${arg}`,
744-
});
745-
746-
test("no packs", parsePacksMacro, "", [], undefined);
747-
test("two packs", parsePacksMacro, "a/b,c/d@1.2.3", [KnownLanguage.cpp], {
748-
[KnownLanguage.cpp]: ["a/b", "c/d@1.2.3"],
749-
});
750-
test(
751-
"two packs with spaces",
752-
parsePacksMacro,
753-
" a/b , c/d@1.2.3 ",
754-
[KnownLanguage.cpp],
755-
{
756-
[KnownLanguage.cpp]: ["a/b", "c/d@1.2.3"],
757-
},
758-
);
759-
test(
760-
"two packs with language",
761-
parsePacksErrorMacro,
762-
"a/b,c/d@1.2.3",
763-
[KnownLanguage.cpp, KnownLanguage.java],
764-
new RegExp(
765-
"Cannot specify a 'packs' input in a multi-language analysis. " +
766-
"Use a codeql-config.yml file instead and specify packs by language.",
767-
),
768-
);
769-
770-
test(
771-
"packs with other valid names",
772-
parsePacksMacro,
773-
[
774-
// ranges are ok
775-
"c/d@1.0",
776-
"c/d@~1.0.0",
777-
"c/d@~1.0.0:a/b",
778-
"c/d@~1.0.0+abc:a/b",
779-
"c/d@~1.0.0-abc:a/b",
780-
"c/d:a/b",
781-
// whitespace is removed
782-
" c/d @ ~1.0.0 : b.qls ",
783-
// and it is retained within a path
784-
" c/d @ ~1.0.0 : b/a path with/spaces.qls ",
785-
// this is valid. the path is '@'. It will probably fail when passed to the CLI
786-
"c/d@1.2.3:@",
787-
// this is valid, too. It will fail if it doesn't match a path
788-
// (globbing is not done)
789-
"c/d@1.2.3:+*)_(",
790-
].join(","),
791-
[KnownLanguage.cpp],
792-
{
793-
[KnownLanguage.cpp]: [
794-
"c/d@1.0",
795-
"c/d@~1.0.0",
796-
"c/d@~1.0.0:a/b",
797-
"c/d@~1.0.0+abc:a/b",
798-
"c/d@~1.0.0-abc:a/b",
799-
"c/d:a/b",
800-
"c/d@~1.0.0:b.qls",
801-
"c/d@~1.0.0:b/a path with/spaces.qls",
802-
"c/d@1.2.3:@",
803-
"c/d@1.2.3:+*)_(",
804-
],
805-
},
806-
);
807-
808-
test(invalidPackNameMacro, "c"); // all packs require at least a scope and a name
809-
test(invalidPackNameMacro, "c-/d");
810-
test(invalidPackNameMacro, "-c/d");
811-
test(invalidPackNameMacro, "c/d_d");
812-
test(invalidPackNameMacro, "c/d@@");
813-
test(invalidPackNameMacro, "c/d@1.0.0:");
814-
test(invalidPackNameMacro, "c/d:");
815-
test(invalidPackNameMacro, "c/d:/a");
816-
test(invalidPackNameMacro, "@1.0.0:a");
817-
test(invalidPackNameMacro, "c/d@../a");
818-
test(invalidPackNameMacro, "c/d@b/../a");
819-
test(invalidPackNameMacro, "c/d:z@1");
820-
821-
/**
822-
* Test macro for pretty printing pack specs
823-
*/
824-
const packSpecPrettyPrintingMacro = test.macro({
825-
exec: (t: ExecutionContext, packStr: string, packObj: configUtils.Pack) => {
826-
const parsed = configUtils.parsePacksSpecification(packStr);
827-
t.deepEqual(parsed, packObj, "parsed pack spec is correct");
828-
const stringified = prettyPrintPack(packObj);
829-
t.deepEqual(
830-
stringified,
831-
packStr.trim(),
832-
"pretty-printed pack spec is correct",
833-
);
834-
835-
t.deepEqual(
836-
configUtils.validatePackSpecification(packStr),
837-
packStr.trim(),
838-
"pack spec is valid",
839-
);
840-
},
841-
title: (
842-
_providedTitle: string | undefined,
843-
packStr: string,
844-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
845-
_packObj: configUtils.Pack,
846-
) => `Prettyprint pack spec: '${packStr}'`,
847-
});
848-
849-
test(packSpecPrettyPrintingMacro, "a/b", {
850-
name: "a/b",
851-
version: undefined,
852-
path: undefined,
853-
});
854-
test(packSpecPrettyPrintingMacro, "a/b@~1.2.3", {
855-
name: "a/b",
856-
version: "~1.2.3",
857-
path: undefined,
858-
});
859-
test(packSpecPrettyPrintingMacro, "a/b@~1.2.3:abc/def", {
860-
name: "a/b",
861-
version: "~1.2.3",
862-
path: "abc/def",
863-
});
864-
test(packSpecPrettyPrintingMacro, "a/b:abc/def", {
865-
name: "a/b",
866-
version: undefined,
867-
path: "abc/def",
868-
});
869-
test(packSpecPrettyPrintingMacro, " a/b:abc/def ", {
870-
name: "a/b",
871-
version: undefined,
872-
path: "abc/def",
873-
});
874-
875693
const mockLogger = getRunnerLogger(true);
876694

877-
const calculateAugmentationMacro = test.macro({
878-
exec: async (
879-
t: ExecutionContext,
880-
_title: string,
881-
rawPacksInput: string | undefined,
882-
rawQueriesInput: string | undefined,
883-
languages: Language[],
884-
expectedAugmentationProperties: configUtils.AugmentationProperties,
885-
) => {
886-
const actualAugmentationProperties =
887-
await configUtils.calculateAugmentation(
888-
rawPacksInput,
889-
rawQueriesInput,
890-
languages,
891-
);
892-
t.deepEqual(actualAugmentationProperties, expectedAugmentationProperties);
893-
},
894-
title: (_, title) => `Calculate Augmentation: ${title}`,
895-
});
896-
897-
test(
898-
calculateAugmentationMacro,
899-
"All empty",
900-
undefined,
901-
undefined,
902-
[KnownLanguage.javascript],
903-
{
904-
...configUtils.defaultAugmentationProperties,
905-
},
906-
);
907-
908-
test(
909-
calculateAugmentationMacro,
910-
"With queries",
911-
undefined,
912-
" a, b , c, d",
913-
[KnownLanguage.javascript],
914-
{
915-
...configUtils.defaultAugmentationProperties,
916-
queriesInput: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }],
917-
},
918-
);
919-
920-
test(
921-
calculateAugmentationMacro,
922-
"With queries combining",
923-
undefined,
924-
" + a, b , c, d ",
925-
[KnownLanguage.javascript],
926-
{
927-
...configUtils.defaultAugmentationProperties,
928-
queriesInputCombines: true,
929-
queriesInput: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }],
930-
},
931-
);
932-
933-
test(
934-
calculateAugmentationMacro,
935-
"With packs",
936-
" codeql/a , codeql/b , codeql/c , codeql/d ",
937-
undefined,
938-
[KnownLanguage.javascript],
939-
{
940-
...configUtils.defaultAugmentationProperties,
941-
packsInput: ["codeql/a", "codeql/b", "codeql/c", "codeql/d"],
942-
},
943-
);
944-
945-
test(
946-
calculateAugmentationMacro,
947-
"With packs combining",
948-
" + codeql/a, codeql/b, codeql/c, codeql/d",
949-
undefined,
950-
[KnownLanguage.javascript],
951-
{
952-
...configUtils.defaultAugmentationProperties,
953-
packsInputCombines: true,
954-
packsInput: ["codeql/a", "codeql/b", "codeql/c", "codeql/d"],
955-
},
956-
);
957-
958-
const calculateAugmentationErrorMacro = test.macro({
959-
exec: async (
960-
t: ExecutionContext,
961-
_title: string,
962-
rawPacksInput: string | undefined,
963-
rawQueriesInput: string | undefined,
964-
languages: Language[],
965-
expectedError: RegExp | string,
966-
) => {
967-
await t.throwsAsync(
968-
() =>
969-
configUtils.calculateAugmentation(
970-
rawPacksInput,
971-
rawQueriesInput,
972-
languages,
973-
),
974-
{ message: expectedError },
975-
);
976-
},
977-
title: (_, title) => `Calculate Augmentation Error: ${title}`,
978-
});
979-
980-
test(
981-
calculateAugmentationErrorMacro,
982-
"Plus (+) with nothing else (queries)",
983-
undefined,
984-
" + ",
985-
[KnownLanguage.javascript],
986-
/The workflow property "queries" is invalid/,
987-
);
988-
989-
test(
990-
calculateAugmentationErrorMacro,
991-
"Plus (+) with nothing else (packs)",
992-
" + ",
993-
undefined,
994-
[KnownLanguage.javascript],
995-
/The workflow property "packs" is invalid/,
996-
);
997-
998-
test(
999-
calculateAugmentationErrorMacro,
1000-
"Packs input with multiple languages",
1001-
" + a/b, c/d ",
1002-
undefined,
1003-
[KnownLanguage.javascript, KnownLanguage.java],
1004-
/Cannot specify a 'packs' input in a multi-language analysis/,
1005-
);
1006-
1007-
test(
1008-
calculateAugmentationErrorMacro,
1009-
"Packs input with no languages",
1010-
" + a/b, c/d ",
1011-
undefined,
1012-
[],
1013-
/No languages specified/,
1014-
);
1015-
1016-
test(
1017-
calculateAugmentationErrorMacro,
1018-
"Invalid packs",
1019-
" a-pack-without-a-scope ",
1020-
undefined,
1021-
[KnownLanguage.javascript],
1022-
/"a-pack-without-a-scope" is not a valid pack/,
1023-
);
1024-
1025695
test("no generateRegistries when registries is undefined", async (t) => {
1026696
return await withTmpDir(async (tmpDir) => {
1027697
const registriesInput = undefined;

0 commit comments

Comments
 (0)