forked from github/vscode-codeql
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun-queries.test.ts
More file actions
100 lines (90 loc) · 2.76 KB
/
run-queries.test.ts
File metadata and controls
100 lines (90 loc) · 2.76 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
91
92
93
94
95
96
97
98
99
100
import * as chai from 'chai';
import * as path from 'path';
import 'mocha';
import 'sinon-chai';
import * as sinon from 'sinon';
import * as chaiAsPromised from 'chai-as-promised';
import { QueryInfo } from '../../run-queries';
import { QlProgram, Severity, compileQuery } from '../../pure/messages';
import { DatabaseItem } from '../../databases';
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('run-queries', () => {
it('should create a QueryInfo', () => {
const info = createMockQueryInfo();
const queryID = info.queryID;
expect(path.basename(info.compiledQueryPath)).to.eq(`compiledQuery${queryID}.qlo`);
expect(path.basename(info.dilPath)).to.eq(`results${queryID}.dil`);
expect(path.basename(info.resultsPaths.resultsPath)).to.eq(`results${queryID}.bqrs`);
expect(path.basename(info.resultsPaths.interpretedResultsPath)).to.eq(`interpretedResults${queryID}.sarif`);
expect(info.dataset).to.eq('file:///abc');
});
describe('compile', () => {
it('should compile', async () => {
const info = createMockQueryInfo();
const qs = createMockQueryServerClient();
const mockProgress = 'progress-monitor';
const mockCancel = 'cancel-token';
const results = await info.compile(
qs as any,
mockProgress as any,
mockCancel as any
);
expect(results).to.deep.eq([
{ message: 'err', severity: Severity.ERROR }
]);
expect(qs.sendRequest).to.have.been.calledOnceWith(
compileQuery,
{
compilationOptions: {
computeNoLocationUrls: true,
failOnWarnings: false,
fastCompilation: false,
includeDilInQlo: true,
localChecking: false,
noComputeGetUrl: false,
noComputeToString: false,
computeDefaultStrings: true
},
extraOptions: {
timeoutSecs: 5
},
queryToCheck: 'my-program',
resultPath: info.compiledQueryPath,
target: { query: {} }
},
mockCancel,
mockProgress
);
});
});
function createMockQueryInfo() {
return new QueryInfo(
'my-program' as unknown as QlProgram,
{
contents: {
datasetUri: 'file:///abc'
}
} as unknown as DatabaseItem,
'my-scheme' // queryDbscheme
);
}
function createMockQueryServerClient() {
return {
config: {
timeoutSecs: 5
},
sendRequest: sinon.stub().returns(new Promise(resolve => {
resolve({
messages: [
{ message: 'err', severity: Severity.ERROR },
{ message: 'warn', severity: Severity.WARNING },
]
});
})),
logger: {
log: sinon.spy()
}
};
}
});