Fix failing test
Also, small change to ensure `qlpackOfDatabase` never returns undefined. It will either return a value or throw.
This commit is contained in:
@@ -52,9 +52,6 @@ export async function getLocationsForUriString(
|
||||
}
|
||||
|
||||
const qlpack = await qlpackOfDatabase(cli, db);
|
||||
if (qlpack === undefined) {
|
||||
throw new Error('Can\'t infer qlpack from database source archive');
|
||||
}
|
||||
const templates = createTemplates(uri.pathWithinSourceArchive);
|
||||
|
||||
const links: FullLocationLink[] = [];
|
||||
|
||||
@@ -12,9 +12,10 @@ import {
|
||||
import { CodeQLCliServer } from '../cli';
|
||||
import { DatabaseItem } from '../databases';
|
||||
|
||||
export async function qlpackOfDatabase(cli: CodeQLCliServer, db: DatabaseItem): Promise<string | undefined> {
|
||||
if (db.contents === undefined)
|
||||
return undefined;
|
||||
export async function qlpackOfDatabase(cli: CodeQLCliServer, db: DatabaseItem): Promise<string> {
|
||||
if (db.contents === undefined) {
|
||||
throw new Error('Database is invalid and cannot infer QLPack.');
|
||||
}
|
||||
const datasetPath = db.contents.datasetUri.fsPath;
|
||||
const dbscheme = await helpers.getPrimaryDbscheme(datasetPath);
|
||||
return await helpers.getQlPackForDbscheme(cli, dbscheme);
|
||||
|
||||
@@ -156,9 +156,6 @@ export class TemplatePrintAstProvider {
|
||||
}
|
||||
|
||||
const qlpack = await qlpackOfDatabase(this.cli, db);
|
||||
if (!qlpack) {
|
||||
throw new Error('Can\'t infer qlpack from database source archive');
|
||||
}
|
||||
const queries = await resolveQueries(this.cli, qlpack, KeyType.PrintAstQuery);
|
||||
if (queries.length > 1) {
|
||||
throw new Error('Found multiple Print AST queries. Can\'t continue');
|
||||
|
||||
@@ -17,6 +17,7 @@ describe('queryResolver', () => {
|
||||
let module: Record<string, Function>;
|
||||
let writeFileSpy: sinon.SinonSpy;
|
||||
let getQlPackForDbschemeSpy: sinon.SinonStub;
|
||||
let getPrimaryDbschemeSpy: sinon.SinonStub;
|
||||
let mockCli: Record<string, sinon.SinonStub>;
|
||||
beforeEach(() => {
|
||||
mockCli = {
|
||||
@@ -70,13 +71,14 @@ describe('queryResolver', () => {
|
||||
};
|
||||
const result = await module.qlpackOfDatabase(mockCli, db);
|
||||
expect(result).to.eq('my-qlpack');
|
||||
expect(getQlPackForDbschemeSpy).to.have.been.calledWith(mockCli, '/path/to/database');
|
||||
expect(getPrimaryDbschemeSpy).to.have.been.calledWith('/path/to/database');
|
||||
});
|
||||
});
|
||||
|
||||
function createModule() {
|
||||
writeFileSpy = sinon.spy();
|
||||
getQlPackForDbschemeSpy = sinon.stub();
|
||||
getPrimaryDbschemeSpy = sinon.stub();
|
||||
return proxyquire('../../../contextual/queryResolver', {
|
||||
'fs-extra': {
|
||||
writeFile: writeFileSpy
|
||||
@@ -84,6 +86,7 @@ describe('queryResolver', () => {
|
||||
|
||||
'../helpers': {
|
||||
getQlPackForDbscheme: getQlPackForDbschemeSpy,
|
||||
getPrimaryDbscheme: getPrimaryDbschemeSpy,
|
||||
getOnDiskWorkspaceFolders: () => ({}),
|
||||
showAndLogErrorMessage: () => ({})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user