-
Notifications
You must be signed in to change notification settings - Fork 452
Expand file tree
/
Copy pathtracer-config.test.ts
More file actions
90 lines (79 loc) · 2.56 KB
/
tracer-config.test.ts
File metadata and controls
90 lines (79 loc) · 2.56 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import * as fs from "fs";
import * as path from "path";
import test from "ava";
import * as sinon from "sinon";
import { CodeQL, getCodeQLForTesting } from "./codeql";
import * as configUtils from "./config-utils";
import { KnownLanguage } from "./languages";
import { createTestConfig, makeVersionInfo, setupTests } from "./testing-utils";
import { ToolsFeature } from "./tools-features";
import { getCombinedTracerConfig } from "./tracer-config";
import * as util from "./util";
setupTests(test);
function getTestConfig(tempDir: string): configUtils.Config {
return createTestConfig({
languages: [KnownLanguage.java],
tempDir,
dbLocation: path.resolve(tempDir, "codeql_databases"),
});
}
async function stubCodeql(
enabledFeatures: ToolsFeature[] = [],
): Promise<CodeQL> {
const codeqlObject = await getCodeQLForTesting();
sinon
.stub(codeqlObject, "getVersion")
.resolves(
makeVersionInfo(
"1.0.0",
Object.fromEntries(enabledFeatures.map((f) => [f, true])),
),
);
sinon
.stub(codeqlObject, "isTracedLanguage")
.withArgs(KnownLanguage.java)
.resolves(true);
return codeqlObject;
}
test("getCombinedTracerConfig - return undefined when no languages are traced languages", async (t) => {
await util.withTmpDir(async (tmpDir) => {
const config = getTestConfig(tmpDir);
// No traced languages
config.languages = [KnownLanguage.javascript, KnownLanguage.python];
t.deepEqual(
await getCombinedTracerConfig(await stubCodeql(), config),
undefined,
);
});
});
test("getCombinedTracerConfig", async (t) => {
await util.withTmpDir(async (tmpDir) => {
const config = getTestConfig(tmpDir);
const bundlePath = path.join(tmpDir, "bundle");
const codeqlPlatform =
process.platform === "win32"
? "win64"
: process.platform === "darwin"
? "osx64"
: "linux64";
const startTracingEnv = {
foo: "bar",
CODEQL_DIST: bundlePath,
CODEQL_PLATFORM: codeqlPlatform,
};
const tracingEnvironmentDir = path.join(
config.dbLocation,
"temp",
"tracingEnvironment",
);
fs.mkdirSync(tracingEnvironmentDir, { recursive: true });
const startTracingJson = path.join(
tracingEnvironmentDir,
"start-tracing.json",
);
fs.writeFileSync(startTracingJson, JSON.stringify(startTracingEnv));
const result = await getCombinedTracerConfig(await stubCodeql(), config);
t.notDeepEqual(result, undefined);
t.false(Object.prototype.hasOwnProperty.call(result?.env, "CODEQL_RUNNER"));
});
});