Skip to content

Commit 82741e9

Browse files
committed
Add test for extension-managed db location
1 parent f426178 commit 82741e9

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

extensions/ql-vscode/test/factories/databases/databases.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function mockDbOptions(): FullDatabaseOptions {
1919
}
2020

2121
export function createMockDB(
22-
dir: DirResult,
22+
dir: DirResult | string,
2323
dbOptions = mockDbOptions(),
2424
// source archive location must be a real(-ish) location since
2525
// tests will add this to the workspace location
@@ -39,10 +39,18 @@ export function createMockDB(
3939
);
4040
}
4141

42-
export function sourceLocationUri(dir: DirResult) {
42+
export function sourceLocationUri(dir: DirResult | string) {
43+
if (typeof dir === "string") {
44+
return Uri.file(join(dir, "src.zip"));
45+
}
46+
4347
return Uri.file(join(dir.name, "src.zip"));
4448
}
4549

46-
export function dbLocationUri(dir: DirResult) {
50+
export function dbLocationUri(dir: DirResult | string) {
51+
if (typeof dir === "string") {
52+
return Uri.file(join(dir, "db"));
53+
}
54+
4755
return Uri.file(join(dir.name, "db"));
4856
}

extensions/ql-vscode/test/vscode-tests/minimal-workspace/local-queries/local-databases.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,37 @@ describe("local databases", () => {
242242
await expect(pathExists(mockDbItem.databaseUri.fsPath)).resolves.toBe(
243243
false,
244244
);
245+
await expect(pathExists(dir.name)).resolves.toBe(true);
246+
});
247+
248+
it("should remove a database item with an extension managed location", async () => {
249+
const dbLocation = join(dir.name, "org-repo-12");
250+
await ensureDir(dbLocation);
251+
252+
const mockDbItem = createMockDB(dbLocation, {
253+
...mockDbOptions(),
254+
extensionManagedLocation: dbLocation,
255+
});
256+
await ensureDir(mockDbItem.databaseUri.fsPath);
257+
258+
// pretend that this item is the first workspace folder in the list
259+
jest
260+
.spyOn(mockDbItem, "belongsToSourceArchiveExplorerUri")
261+
.mockReturnValue(true);
262+
263+
await (databaseManager as any).addDatabaseItem(mockDbItem);
264+
265+
updateSpy.mockClear();
266+
267+
await databaseManager.removeDatabaseItem(mockDbItem);
268+
269+
expect(databaseManager.databaseItems).toEqual([]);
270+
expect(updateSpy).toHaveBeenCalledWith("databaseList", []);
271+
// should remove the folder
272+
expect(workspace.updateWorkspaceFolders).toHaveBeenCalledWith(0, 1);
273+
274+
// should delete the complete extension managed location
275+
await expect(pathExists(dbLocation)).resolves.toBe(false);
245276
});
246277

247278
it("should remove a database item outside of the extension controlled area", async () => {

0 commit comments

Comments
 (0)