forked from github/codeql-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeql-bundle.test.ts
More file actions
75 lines (68 loc) · 2.84 KB
/
Copy pathcodeql-bundle.test.ts
File metadata and controls
75 lines (68 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import test from "ava";
import { getCodeQLBundleFromUrl, getCodeQLBundleName } from "./codeql-bundle";
import { BuiltInLanguage } from "./languages";
import { BundlePlatform } from "./platform";
test("getCodeQLBundleName returns a per-language bundle name only when a language is specified", (t) => {
t.is(
getCodeQLBundleName("zstd", BundlePlatform.Linux64, BuiltInLanguage.java),
"codeql-bundle-java-linux64.tar.zst",
);
t.is(
getCodeQLBundleName("zstd", BundlePlatform.Linux64),
"codeql-bundle-linux64.tar.zst",
);
});
test("getCodeQLBundleName names the Swift bundle for macOS", (t) => {
t.is(
getCodeQLBundleName("zstd", BundlePlatform.Osx64, BuiltInLanguage.swift),
"codeql-bundle-swift-osx64.tar.zst",
);
});
for (const [assetName, language] of [
["codeql-bundle-java-linux64.tar.zst", BuiltInLanguage.java],
["codeql-bundle-swift-osx64.tar.zst", BuiltInLanguage.swift],
// Recognize unpublished language/platform combinations to keep them out of the toolcache.
["codeql-bundle-csharp-win64.tar.gz", BuiltInLanguage.csharp],
["codeql-bundle-java-kotlin-linux64.tar.zst", BuiltInLanguage.java],
["codeql-bundle-%70ython-linux64.tar.zst", BuiltInLanguage.python],
] as const) {
test(`getCodeQLBundleFromUrl identifies ${assetName} without adding a fallback`, (t) => {
const url = `https://github.com/github/codeql-action/releases/download/codeql-bundle-v1.2.3/${assetName}`;
t.deepEqual(getCodeQLBundleFromUrl(url), {
kind: "per-language",
url,
language,
});
});
}
test("getCodeQLBundleFromUrl preserves encoding, query parameters and fragments", (t) => {
const url =
"https://github.com/github/codeql-action/releases/download/codeql-bundle-v1.2.3/codeql-bundle-%70ython-linux64.tar.zst?download=1#asset";
t.deepEqual(getCodeQLBundleFromUrl(url), {
kind: "per-language",
url,
language: BuiltInLanguage.python,
});
});
test("getCodeQLBundleFromUrl treats unrecognized assets as combined bundles", (t) => {
for (const name of [
"codeql-bundle-linux64.tar.zst",
"codeql-bundle-osx64.tar.gz",
"codeql-bundle-win64.tar.zst",
// The all-platform bundle.
"codeql-bundle.tar.gz",
// A platform we do not publish per-language bundles for, whose name also contains a hyphen.
"codeql-bundle-linux-arm64.tar.zst",
// Not a language we know about.
"codeql-bundle-cobol-linux64.tar.zst",
// A name we cannot decode must not be mistaken for a language either.
"codeql-bundle-%zz-linux64.tar.zst",
]) {
const url = `https://github.com/github/codeql-action/releases/download/codeql-bundle-v1.2.3/${name}`;
t.deepEqual(getCodeQLBundleFromUrl(url), { kind: "combined", url });
}
});
test("getCodeQLBundleFromUrl preserves URLs it cannot parse", (t) => {
const url = "not a url";
t.deepEqual(getCodeQLBundleFromUrl(url), { kind: "combined", url });
});