Merge pull request #3458 from github/robertbrignull/database-prompting
Refactor database-fetcher.ts into a class and simplify
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -2,10 +2,8 @@ import { window } from "vscode";
|
||||
import type { Octokit } from "@octokit/rest";
|
||||
import { showNeverAskAgainDialog } from "../../common/vscode/dialog";
|
||||
import { getLanguageDisplayName } from "../../common/query-language";
|
||||
import { downloadGitHubDatabaseFromUrl } from "../database-fetcher";
|
||||
import type { DatabaseFetcher } from "../database-fetcher";
|
||||
import { withProgress } from "../../common/vscode/progress";
|
||||
import type { DatabaseManager } from "../local-databases";
|
||||
import type { CodeQLCliServer } from "../../codeql-cli/cli";
|
||||
import type { AppCommandManager } from "../../common/commands";
|
||||
import type { GitHubDatabaseConfig } from "../../config";
|
||||
import type { CodeqlDatabase } from "./api";
|
||||
@@ -58,9 +56,7 @@ export async function downloadDatabaseFromGitHub(
|
||||
owner: string,
|
||||
repo: string,
|
||||
databases: CodeqlDatabase[],
|
||||
databaseManager: DatabaseManager,
|
||||
storagePath: string,
|
||||
cliServer: CodeQLCliServer,
|
||||
databaseFetcher: DatabaseFetcher,
|
||||
commandManager: AppCommandManager,
|
||||
): Promise<void> {
|
||||
const selectedDatabases = await promptForDatabases(databases);
|
||||
@@ -72,7 +68,7 @@ export async function downloadDatabaseFromGitHub(
|
||||
selectedDatabases.map((database) =>
|
||||
withProgress(
|
||||
async (progress) => {
|
||||
await downloadGitHubDatabaseFromUrl(
|
||||
await databaseFetcher.downloadGitHubDatabaseFromUrl(
|
||||
database.url,
|
||||
database.id,
|
||||
database.created_at,
|
||||
@@ -81,9 +77,6 @@ export async function downloadDatabaseFromGitHub(
|
||||
repo,
|
||||
octokit,
|
||||
progress,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
} from "./download";
|
||||
import type { GitHubDatabaseConfig } from "../../config";
|
||||
import type { DatabaseManager } from "../local-databases";
|
||||
import type { CodeQLCliServer } from "../../codeql-cli/cli";
|
||||
import type { CodeqlDatabase, ListDatabasesResult } from "./api";
|
||||
import { listDatabases } from "./api";
|
||||
import type { DatabaseUpdate } from "./updates";
|
||||
@@ -24,6 +23,7 @@ import {
|
||||
isNewerDatabaseAvailable,
|
||||
} from "./updates";
|
||||
import type { Octokit } from "@octokit/rest";
|
||||
import type { DatabaseFetcher } from "../database-fetcher";
|
||||
|
||||
export class GitHubDatabasesModule extends DisposableObject {
|
||||
/**
|
||||
@@ -33,8 +33,7 @@ export class GitHubDatabasesModule extends DisposableObject {
|
||||
constructor(
|
||||
private readonly app: App,
|
||||
private readonly databaseManager: DatabaseManager,
|
||||
private readonly databaseStoragePath: string,
|
||||
private readonly cliServer: CodeQLCliServer,
|
||||
private readonly databaseFetcher: DatabaseFetcher,
|
||||
private readonly config: GitHubDatabaseConfig,
|
||||
) {
|
||||
super();
|
||||
@@ -43,15 +42,13 @@ export class GitHubDatabasesModule extends DisposableObject {
|
||||
public static async initialize(
|
||||
app: App,
|
||||
databaseManager: DatabaseManager,
|
||||
databaseStoragePath: string,
|
||||
cliServer: CodeQLCliServer,
|
||||
databaseFetcher: DatabaseFetcher,
|
||||
config: GitHubDatabaseConfig,
|
||||
): Promise<GitHubDatabasesModule> {
|
||||
const githubDatabasesModule = new GitHubDatabasesModule(
|
||||
app,
|
||||
databaseManager,
|
||||
databaseStoragePath,
|
||||
cliServer,
|
||||
databaseFetcher,
|
||||
config,
|
||||
);
|
||||
app.subscriptions.push(githubDatabasesModule);
|
||||
@@ -185,9 +182,7 @@ export class GitHubDatabasesModule extends DisposableObject {
|
||||
owner,
|
||||
repo,
|
||||
databases,
|
||||
this.databaseManager,
|
||||
this.databaseStoragePath,
|
||||
this.cliServer,
|
||||
this.databaseFetcher,
|
||||
this.app.commands,
|
||||
);
|
||||
}
|
||||
@@ -212,8 +207,7 @@ export class GitHubDatabasesModule extends DisposableObject {
|
||||
repo,
|
||||
databaseUpdates,
|
||||
this.databaseManager,
|
||||
this.databaseStoragePath,
|
||||
this.cliServer,
|
||||
this.databaseFetcher,
|
||||
this.app.commands,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { CodeqlDatabase } from "./api";
|
||||
import type { DatabaseItem, DatabaseManager } from "../local-databases";
|
||||
import type { Octokit } from "@octokit/rest";
|
||||
import type { CodeQLCliServer } from "../../codeql-cli/cli";
|
||||
import type { AppCommandManager } from "../../common/commands";
|
||||
import { getLanguageDisplayName } from "../../common/query-language";
|
||||
import { showNeverAskAgainDialog } from "../../common/vscode/dialog";
|
||||
import { downloadGitHubDatabaseFromUrl } from "../database-fetcher";
|
||||
import type { DatabaseFetcher } from "../database-fetcher";
|
||||
import { withProgress } from "../../common/vscode/progress";
|
||||
import { window } from "vscode";
|
||||
import type { GitHubDatabaseConfig } from "../../config";
|
||||
@@ -156,8 +155,7 @@ export async function downloadDatabaseUpdateFromGitHub(
|
||||
repo: string,
|
||||
updates: DatabaseUpdate[],
|
||||
databaseManager: DatabaseManager,
|
||||
storagePath: string,
|
||||
cliServer: CodeQLCliServer,
|
||||
databaseFetcher: DatabaseFetcher,
|
||||
commandManager: AppCommandManager,
|
||||
): Promise<void> {
|
||||
const selectedDatabases = await promptForDatabases(
|
||||
@@ -179,21 +177,19 @@ export async function downloadDatabaseUpdateFromGitHub(
|
||||
|
||||
return withProgress(
|
||||
async (progress) => {
|
||||
const newDatabase = await downloadGitHubDatabaseFromUrl(
|
||||
database.url,
|
||||
database.id,
|
||||
database.created_at,
|
||||
database.commit_oid ?? null,
|
||||
owner,
|
||||
repo,
|
||||
octokit,
|
||||
progress,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
databaseManager.currentDatabaseItem === update.databaseItem,
|
||||
update.databaseItem.hasSourceArchiveInExplorer(),
|
||||
);
|
||||
const newDatabase =
|
||||
await databaseFetcher.downloadGitHubDatabaseFromUrl(
|
||||
database.url,
|
||||
database.id,
|
||||
database.created_at,
|
||||
database.commit_oid ?? null,
|
||||
owner,
|
||||
repo,
|
||||
octokit,
|
||||
progress,
|
||||
databaseManager.currentDatabaseItem === update.databaseItem,
|
||||
update.databaseItem.hasSourceArchiveInExplorer(),
|
||||
);
|
||||
if (newDatabase === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,11 +37,7 @@ import {
|
||||
showAndLogExceptionWithTelemetry,
|
||||
showAndLogErrorMessage,
|
||||
} from "../common/logging";
|
||||
import {
|
||||
importLocalDatabase,
|
||||
promptImportGithubDatabase,
|
||||
promptImportInternetDatabase,
|
||||
} from "./database-fetcher";
|
||||
import type { DatabaseFetcher } from "./database-fetcher";
|
||||
import { asError, asyncFilter, getErrorMessage } from "../common/helpers-pure";
|
||||
import type { QueryRunner } from "../query-server";
|
||||
import type { App } from "../common/app";
|
||||
@@ -248,6 +244,7 @@ export class DatabaseUI extends DisposableObject {
|
||||
public constructor(
|
||||
private app: App,
|
||||
private databaseManager: DatabaseManager,
|
||||
private readonly databaseFetcher: DatabaseFetcher,
|
||||
languageContext: LanguageContextStore,
|
||||
private readonly queryServer: QueryRunner,
|
||||
private readonly storagePath: string,
|
||||
@@ -535,13 +532,7 @@ export class DatabaseUI extends DisposableObject {
|
||||
private async handleChooseDatabaseInternet(): Promise<void> {
|
||||
return withProgress(
|
||||
async (progress) => {
|
||||
await promptImportInternetDatabase(
|
||||
this.app.commands,
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
progress,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
await this.databaseFetcher.promptImportInternetDatabase(progress);
|
||||
},
|
||||
{
|
||||
title: "Adding database from URL",
|
||||
@@ -552,13 +543,7 @@ export class DatabaseUI extends DisposableObject {
|
||||
private async handleChooseDatabaseGithub(): Promise<void> {
|
||||
return withProgress(
|
||||
async (progress) => {
|
||||
await promptImportGithubDatabase(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
progress,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
await this.databaseFetcher.promptImportGithubDatabase(progress);
|
||||
},
|
||||
{
|
||||
title: "Adding database from GitHub",
|
||||
@@ -707,13 +692,9 @@ export class DatabaseUI extends DisposableObject {
|
||||
try {
|
||||
// Assume user has selected an archive if the file has a .zip extension
|
||||
if (uri.path.endsWith(".zip")) {
|
||||
await importLocalDatabase(
|
||||
this.app.commands,
|
||||
await this.databaseFetcher.importLocalDatabase(
|
||||
uri.toString(true),
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
progress,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
} else {
|
||||
await this.databaseManager.openDatabase(uri, {
|
||||
@@ -758,13 +739,9 @@ export class DatabaseUI extends DisposableObject {
|
||||
await this.databaseManager.removeDatabaseItem(existingItem);
|
||||
}
|
||||
|
||||
await importLocalDatabase(
|
||||
this.app.commands,
|
||||
await this.databaseFetcher.importLocalDatabase(
|
||||
uri.toString(true),
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
progress,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
|
||||
if (existingItem !== undefined) {
|
||||
@@ -1005,13 +982,9 @@ export class DatabaseUI extends DisposableObject {
|
||||
// we are selecting a database archive or a testproj.
|
||||
// Unzip archives (if an archive) and copy into a workspace-controlled area
|
||||
// before importing.
|
||||
return await importLocalDatabase(
|
||||
this.app.commands,
|
||||
return await this.databaseFetcher.importLocalDatabase(
|
||||
uri.toString(true),
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
progress,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { pathExists, remove } from "fs-extra";
|
||||
import { join } from "path";
|
||||
import type { Uri } from "vscode";
|
||||
import { zip } from "zip-a-folder";
|
||||
|
||||
/**
|
||||
* The layout of the database.
|
||||
@@ -28,3 +31,26 @@ export interface DatabaseContents {
|
||||
export interface DatabaseContentsWithDbScheme extends DatabaseContents {
|
||||
dbSchemeUri: Uri; // Always present
|
||||
}
|
||||
|
||||
/**
|
||||
* Databases created by the old odasa tool will not have a zipped
|
||||
* source location. However, this extension works better if sources
|
||||
* are zipped.
|
||||
*
|
||||
* This function ensures that the source location is zipped. If the
|
||||
* `src` folder exists and the `src.zip` file does not, the `src`
|
||||
* folder will be zipped and then deleted.
|
||||
*
|
||||
* @param databasePath The full path to the unzipped database
|
||||
*/
|
||||
export async function ensureZippedSourceLocation(
|
||||
databasePath: string,
|
||||
): Promise<void> {
|
||||
const srcFolderPath = join(databasePath, "src");
|
||||
const srcZipPath = `${srcFolderPath}.zip`;
|
||||
|
||||
if ((await pathExists(srcFolderPath)) && !(await pathExists(srcZipPath))) {
|
||||
await zip(srcFolderPath, srcZipPath);
|
||||
await remove(srcFolderPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ import { DatabaseResolver } from "./database-resolver";
|
||||
import { telemetryListener } from "../../common/vscode/telemetry";
|
||||
import type { LanguageContextStore } from "../../language-context-store";
|
||||
import type { DatabaseOrigin } from "./database-origin";
|
||||
import { ensureZippedSourceLocation } from "../database-fetcher";
|
||||
import { ensureZippedSourceLocation } from "./database-contents";
|
||||
|
||||
/**
|
||||
* The name of the key in the workspaceState dictionary in which we
|
||||
|
||||
@@ -133,6 +133,7 @@ import { OpenReferencedFileCodeLensProvider } from "./local-queries/open-referen
|
||||
import { LanguageContextStore } from "./language-context-store";
|
||||
import { LanguageSelectionPanel } from "./language-selection-panel/language-selection-panel";
|
||||
import { GitHubDatabasesModule } from "./databases/github-databases";
|
||||
import { DatabaseFetcher } from "./databases/database-fetcher";
|
||||
|
||||
/**
|
||||
* extension.ts
|
||||
@@ -799,12 +800,20 @@ async function activateWithInstalledDistribution(
|
||||
// Let this run async.
|
||||
void dbm.loadPersistedState();
|
||||
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
app,
|
||||
dbm,
|
||||
getContextStoragePath(ctx),
|
||||
cliServer,
|
||||
);
|
||||
|
||||
ctx.subscriptions.push(dbm);
|
||||
|
||||
void extLogger.log("Initializing database panel.");
|
||||
const databaseUI = new DatabaseUI(
|
||||
app,
|
||||
dbm,
|
||||
databaseFetcher,
|
||||
languageContext,
|
||||
qs,
|
||||
getContextStoragePath(ctx),
|
||||
@@ -881,8 +890,7 @@ async function activateWithInstalledDistribution(
|
||||
await GitHubDatabasesModule.initialize(
|
||||
app,
|
||||
dbm,
|
||||
getContextStoragePath(ctx),
|
||||
cliServer,
|
||||
databaseFetcher,
|
||||
githubDatabaseConfigListener,
|
||||
);
|
||||
|
||||
@@ -953,6 +961,7 @@ async function activateWithInstalledDistribution(
|
||||
qs,
|
||||
qhm,
|
||||
dbm,
|
||||
databaseFetcher,
|
||||
cliServer,
|
||||
databaseUI,
|
||||
localQueryResultsView,
|
||||
@@ -977,6 +986,7 @@ async function activateWithInstalledDistribution(
|
||||
const modelEditorModule = await ModelEditorModule.initialize(
|
||||
app,
|
||||
dbm,
|
||||
databaseFetcher,
|
||||
variantAnalysisManager,
|
||||
cliServer,
|
||||
qs,
|
||||
|
||||
@@ -54,6 +54,7 @@ import type { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
|
||||
import { tryGetQueryLanguage } from "../common/query-language";
|
||||
import type { LanguageContextStore } from "../language-context-store";
|
||||
import type { ExtensionApp } from "../common/vscode/vscode-app";
|
||||
import type { DatabaseFetcher } from "../databases/database-fetcher";
|
||||
|
||||
export enum QuickEvalType {
|
||||
None,
|
||||
@@ -69,6 +70,7 @@ export class LocalQueries extends DisposableObject {
|
||||
private readonly queryRunner: QueryRunner,
|
||||
private readonly queryHistoryManager: QueryHistoryManager,
|
||||
private readonly databaseManager: DatabaseManager,
|
||||
private readonly databaseFetcher: DatabaseFetcher,
|
||||
private readonly cliServer: CodeQLCliServer,
|
||||
private readonly databaseUI: DatabaseUI,
|
||||
private readonly localQueryResultsView: ResultsView,
|
||||
@@ -319,15 +321,13 @@ export class LocalQueries extends DisposableObject {
|
||||
private async createSkeletonQuery(): Promise<void> {
|
||||
await withProgress(
|
||||
async (progress: ProgressCallback) => {
|
||||
const contextStoragePath =
|
||||
this.app.workspaceStoragePath || this.app.globalStoragePath;
|
||||
const language = this.languageContextStore.selectedLanguage;
|
||||
const skeletonQueryWizard = new SkeletonQueryWizard(
|
||||
this.cliServer,
|
||||
progress,
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
contextStoragePath,
|
||||
this.databaseFetcher,
|
||||
this.selectedQueryTreeViewItems,
|
||||
language,
|
||||
);
|
||||
|
||||
@@ -19,10 +19,7 @@ import {
|
||||
UserCancellationException,
|
||||
withProgress,
|
||||
} from "../common/vscode/progress";
|
||||
import {
|
||||
askForGitHubRepo,
|
||||
downloadGitHubDatabase,
|
||||
} from "../databases/database-fetcher";
|
||||
import type { DatabaseFetcher } from "../databases/database-fetcher";
|
||||
import {
|
||||
getQlPackLocation,
|
||||
isCodespacesTemplate,
|
||||
@@ -62,7 +59,7 @@ export class SkeletonQueryWizard {
|
||||
private readonly progress: ProgressCallback,
|
||||
private readonly app: App,
|
||||
private readonly databaseManager: DatabaseManager,
|
||||
private readonly databaseStoragePath: string | undefined,
|
||||
private readonly databaseFetcher: DatabaseFetcher,
|
||||
private readonly selectedItems: readonly QueryTreeViewItem[],
|
||||
private language: QueryLanguage | undefined = undefined,
|
||||
) {}
|
||||
@@ -363,10 +360,6 @@ export class SkeletonQueryWizard {
|
||||
}
|
||||
|
||||
private async downloadDatabase(progress: ProgressCallback) {
|
||||
if (this.databaseStoragePath === undefined) {
|
||||
throw new Error("Database storage path is undefined");
|
||||
}
|
||||
|
||||
if (this.language === undefined) {
|
||||
throw new Error("Language is undefined");
|
||||
}
|
||||
@@ -378,20 +371,10 @@ export class SkeletonQueryWizard {
|
||||
});
|
||||
|
||||
const githubRepoNwo = QUERY_LANGUAGE_TO_DATABASE_REPO[this.language];
|
||||
const chosenRepo = await askForGitHubRepo(undefined, githubRepoNwo);
|
||||
|
||||
if (!chosenRepo) {
|
||||
throw new UserCancellationException("No GitHub repository provided");
|
||||
}
|
||||
|
||||
await downloadGitHubDatabase(
|
||||
chosenRepo,
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.databaseStoragePath,
|
||||
await this.databaseFetcher.promptImportGithubDatabase(
|
||||
progress,
|
||||
this.cliServer,
|
||||
this.language,
|
||||
githubRepoNwo,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import { INITIAL_MODE } from "./shared/mode";
|
||||
import { isSupportedLanguage } from "./supported-languages";
|
||||
import { DefaultNotifier, checkConsistency } from "./consistency-check";
|
||||
import type { VariantAnalysisManager } from "../variant-analysis/variant-analysis-manager";
|
||||
import type { DatabaseFetcher } from "../databases/database-fetcher";
|
||||
|
||||
export class ModelEditorModule extends DisposableObject {
|
||||
private readonly queryStorageDir: string;
|
||||
@@ -42,6 +43,7 @@ export class ModelEditorModule extends DisposableObject {
|
||||
private constructor(
|
||||
private readonly app: App,
|
||||
private readonly databaseManager: DatabaseManager,
|
||||
private readonly databaseFetcher: DatabaseFetcher,
|
||||
private readonly variantAnalysisManager: VariantAnalysisManager,
|
||||
private readonly cliServer: CodeQLCliServer,
|
||||
private readonly queryRunner: QueryRunner,
|
||||
@@ -65,6 +67,7 @@ export class ModelEditorModule extends DisposableObject {
|
||||
public static async initialize(
|
||||
app: App,
|
||||
databaseManager: DatabaseManager,
|
||||
databaseFetcher: DatabaseFetcher,
|
||||
variantAnalysisManager: VariantAnalysisManager,
|
||||
cliServer: CodeQLCliServer,
|
||||
queryRunner: QueryRunner,
|
||||
@@ -73,6 +76,7 @@ export class ModelEditorModule extends DisposableObject {
|
||||
const modelEditorModule = new ModelEditorModule(
|
||||
app,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
variantAnalysisManager,
|
||||
cliServer,
|
||||
queryRunner,
|
||||
@@ -236,6 +240,7 @@ export class ModelEditorModule extends DisposableObject {
|
||||
this.modelingEvents,
|
||||
this.modelConfig,
|
||||
this.databaseManager,
|
||||
this.databaseFetcher,
|
||||
this.variantAnalysisManager,
|
||||
this.cliServer,
|
||||
this.queryRunner,
|
||||
|
||||
@@ -29,7 +29,7 @@ import type {
|
||||
} from "../databases/local-databases";
|
||||
import type { CodeQLCliServer } from "../codeql-cli/cli";
|
||||
import { asError, assertNever, getErrorMessage } from "../common/helpers-pure";
|
||||
import { promptImportGithubDatabase } from "../databases/database-fetcher";
|
||||
import type { DatabaseFetcher } from "../databases/database-fetcher";
|
||||
import type { App } from "../common/app";
|
||||
import { redactableError } from "../common/errors";
|
||||
import {
|
||||
@@ -86,6 +86,7 @@ export class ModelEditorView extends AbstractWebview<
|
||||
private readonly modelingEvents: ModelingEvents,
|
||||
private readonly modelConfig: ModelConfigListener,
|
||||
private readonly databaseManager: DatabaseManager,
|
||||
private readonly databaseFetcher: DatabaseFetcher,
|
||||
private readonly variantAnalysisManager: VariantAnalysisManager,
|
||||
private readonly cliServer: CodeQLCliServer,
|
||||
private readonly queryRunner: QueryRunner,
|
||||
@@ -852,6 +853,7 @@ export class ModelEditorView extends AbstractWebview<
|
||||
this.modelingEvents,
|
||||
this.modelConfig,
|
||||
this.databaseManager,
|
||||
this.databaseFetcher,
|
||||
this.variantAnalysisManager,
|
||||
this.cliServer,
|
||||
this.queryRunner,
|
||||
@@ -920,13 +922,10 @@ export class ModelEditorView extends AbstractWebview<
|
||||
// the user to import the library database. We need to have the database
|
||||
// imported to the query server, so we need to register it to our workspace.
|
||||
const makeSelected = false;
|
||||
const addedDatabase = await promptImportGithubDatabase(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.app.workspaceStoragePath ?? this.app.globalStoragePath,
|
||||
const addedDatabase = await this.databaseFetcher.promptImportGithubDatabase(
|
||||
progress,
|
||||
this.cliServer,
|
||||
this.databaseItem.language,
|
||||
undefined,
|
||||
makeSelected,
|
||||
false,
|
||||
);
|
||||
|
||||
@@ -3,10 +3,7 @@ import { Uri, window } from "vscode";
|
||||
|
||||
import type { CodeQLCliServer } from "../../../../src/codeql-cli/cli";
|
||||
import type { DatabaseManager } from "../../../../src/databases/local-databases";
|
||||
import {
|
||||
importLocalDatabase,
|
||||
promptImportInternetDatabase,
|
||||
} from "../../../../src/databases/database-fetcher";
|
||||
import { DatabaseFetcher } from "../../../../src/databases/database-fetcher";
|
||||
import {
|
||||
cleanDatabases,
|
||||
dbLoc,
|
||||
@@ -15,9 +12,8 @@ import {
|
||||
storagePath,
|
||||
testprojLoc,
|
||||
} from "../../global.helper";
|
||||
import { createMockCommandManager } from "../../../__mocks__/commandsMock";
|
||||
import { utimesSync } from "fs";
|
||||
import { remove, existsSync } from "fs-extra";
|
||||
import { existsSync, remove, utimesSync } from "fs-extra";
|
||||
import { createMockApp } from "../../../__mocks__/appMock";
|
||||
|
||||
/**
|
||||
* Run various integration tests for databases
|
||||
@@ -51,14 +47,16 @@ describe("database-fetcher", () => {
|
||||
describe("importLocalDatabase", () => {
|
||||
it("should add a database from an archive", async () => {
|
||||
const uri = Uri.file(dbLoc);
|
||||
let dbItem = await importLocalDatabase(
|
||||
createMockCommandManager(),
|
||||
uri.toString(true),
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
createMockApp(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
progressCallback,
|
||||
cli,
|
||||
);
|
||||
let dbItem = await databaseFetcher.importLocalDatabase(
|
||||
uri.toString(true),
|
||||
progressCallback,
|
||||
);
|
||||
expect(dbItem).toBe(databaseManager.currentDatabaseItem);
|
||||
expect(dbItem).toBe(databaseManager.databaseItems[0]);
|
||||
expect(dbItem).toBeDefined();
|
||||
@@ -68,14 +66,16 @@ describe("database-fetcher", () => {
|
||||
});
|
||||
|
||||
it("should import a testproj database", async () => {
|
||||
let dbItem = await importLocalDatabase(
|
||||
createMockCommandManager(),
|
||||
Uri.file(testprojLoc).toString(true),
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
createMockApp(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
progressCallback,
|
||||
cli,
|
||||
);
|
||||
let dbItem = await databaseFetcher.importLocalDatabase(
|
||||
Uri.file(testprojLoc).toString(true),
|
||||
progressCallback,
|
||||
);
|
||||
expect(dbItem).toBe(databaseManager.currentDatabaseItem);
|
||||
expect(dbItem).toBe(databaseManager.databaseItems[0]);
|
||||
expect(dbItem).toBeDefined();
|
||||
@@ -109,13 +109,14 @@ describe("database-fetcher", () => {
|
||||
// Provide a database URL when prompted
|
||||
inputBoxStub.mockResolvedValue(DB_URL);
|
||||
|
||||
let dbItem = await promptImportInternetDatabase(
|
||||
createMockCommandManager(),
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
createMockApp(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
progressCallback,
|
||||
cli,
|
||||
);
|
||||
let dbItem =
|
||||
await databaseFetcher.promptImportInternetDatabase(progressCallback);
|
||||
expect(dbItem).toBeDefined();
|
||||
dbItem = dbItem!;
|
||||
expect(dbItem.name).toBe("db");
|
||||
|
||||
@@ -23,7 +23,7 @@ import type {
|
||||
DatabaseManager,
|
||||
FullDatabaseOptions,
|
||||
} from "../../../../src/databases/local-databases";
|
||||
import * as databaseFetcher from "../../../../src/databases/database-fetcher";
|
||||
import type { DatabaseFetcher } from "../../../../src/databases/database-fetcher";
|
||||
import { createMockDB } from "../../../factories/databases/databases";
|
||||
import { asError } from "../../../../src/common/helpers-pure";
|
||||
import { Setting } from "../../../../src/config";
|
||||
@@ -42,6 +42,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
let mockApp: App;
|
||||
let wizard: SkeletonQueryWizard;
|
||||
let mockDatabaseManager: DatabaseManager;
|
||||
let databaseFetcher: DatabaseFetcher;
|
||||
let dir: DirResult;
|
||||
let storagePath: string;
|
||||
let quickPickSpy: jest.SpiedFunction<typeof window.showQuickPick>;
|
||||
@@ -55,11 +56,8 @@ describe("SkeletonQueryWizard", () => {
|
||||
let createExampleQlFileSpy: jest.SpiedFunction<
|
||||
typeof QlPackGenerator.prototype.createExampleQlFile
|
||||
>;
|
||||
let downloadGitHubDatabaseSpy: jest.SpiedFunction<
|
||||
typeof databaseFetcher.downloadGitHubDatabase
|
||||
>;
|
||||
let askForGitHubRepoSpy: jest.SpiedFunction<
|
||||
typeof databaseFetcher.askForGitHubRepo
|
||||
let promptImportGithubDatabaseMock: jest.MockedFunction<
|
||||
DatabaseFetcher["promptImportGithubDatabase"]
|
||||
>;
|
||||
let openTextDocumentSpy: jest.SpiedFunction<
|
||||
typeof workspace.openTextDocument
|
||||
@@ -115,6 +113,11 @@ describe("SkeletonQueryWizard", () => {
|
||||
},
|
||||
] as WorkspaceFolder[]);
|
||||
|
||||
promptImportGithubDatabaseMock = jest.fn().mockReturnValue(undefined);
|
||||
databaseFetcher = mockedObject<DatabaseFetcher>({
|
||||
promptImportGithubDatabase: promptImportGithubDatabaseMock,
|
||||
});
|
||||
|
||||
quickPickSpy = jest.spyOn(window, "showQuickPick").mockResolvedValueOnce(
|
||||
mockedQuickPickItem({
|
||||
label: chosenLanguage,
|
||||
@@ -133,9 +136,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
createExampleQlFileSpy = jest
|
||||
.spyOn(QlPackGenerator.prototype, "createExampleQlFile")
|
||||
.mockResolvedValue(undefined);
|
||||
downloadGitHubDatabaseSpy = jest
|
||||
.spyOn(databaseFetcher, "downloadGitHubDatabase")
|
||||
.mockResolvedValue(undefined);
|
||||
openTextDocumentSpy = jest
|
||||
.spyOn(workspace, "openTextDocument")
|
||||
.mockResolvedValue({} as TextDocument);
|
||||
@@ -145,13 +145,9 @@ describe("SkeletonQueryWizard", () => {
|
||||
jest.fn(),
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
databaseFetcher,
|
||||
selectedItems,
|
||||
);
|
||||
|
||||
askForGitHubRepoSpy = jest
|
||||
.spyOn(databaseFetcher, "askForGitHubRepo")
|
||||
.mockResolvedValue(QUERY_LANGUAGE_TO_DATABASE_REPO[chosenLanguage]);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -172,7 +168,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
jest.fn(),
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
databaseFetcher,
|
||||
selectedItems,
|
||||
QueryLanguage.Swift,
|
||||
);
|
||||
@@ -202,7 +198,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
title: "Download database",
|
||||
}),
|
||||
);
|
||||
expect(downloadGitHubDatabaseSpy).not.toHaveBeenCalled();
|
||||
expect(promptImportGithubDatabaseMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should download database for selected language when selecting download in prompt", async () => {
|
||||
@@ -219,7 +215,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
await wizard.execute();
|
||||
await wizard.waitForDownload();
|
||||
|
||||
expect(downloadGitHubDatabaseSpy).toHaveBeenCalled();
|
||||
expect(promptImportGithubDatabaseMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should open the query file", async () => {
|
||||
@@ -320,7 +316,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
jest.fn(),
|
||||
mockApp,
|
||||
mockDatabaseManagerWithItems,
|
||||
storagePath,
|
||||
databaseFetcher,
|
||||
selectedItems,
|
||||
);
|
||||
});
|
||||
@@ -328,7 +324,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
it("should not download a new database for language", async () => {
|
||||
await wizard.execute();
|
||||
|
||||
expect(downloadGitHubDatabaseSpy).not.toHaveBeenCalled();
|
||||
expect(promptImportGithubDatabaseMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should not select the database", async () => {
|
||||
@@ -369,7 +365,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
jest.fn(),
|
||||
mockApp,
|
||||
mockDatabaseManagerWithItems,
|
||||
storagePath,
|
||||
databaseFetcher,
|
||||
selectedItems,
|
||||
);
|
||||
});
|
||||
@@ -377,7 +373,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
it("should not download a new database for language", async () => {
|
||||
await wizard.execute();
|
||||
|
||||
expect(downloadGitHubDatabaseSpy).not.toHaveBeenCalled();
|
||||
expect(promptImportGithubDatabaseMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should select an existing database", async () => {
|
||||
@@ -409,54 +405,23 @@ describe("SkeletonQueryWizard", () => {
|
||||
});
|
||||
|
||||
describe("if database is missing", () => {
|
||||
describe("if the user chooses to downloaded the suggested database from GitHub", () => {
|
||||
beforeEach(() => {
|
||||
showInformationMessageSpy.mockImplementation(
|
||||
async (_message, options, item) => {
|
||||
if (item === undefined) {
|
||||
return options as MessageItem;
|
||||
}
|
||||
beforeEach(() => {
|
||||
showInformationMessageSpy.mockImplementation(
|
||||
async (_message, options, item) => {
|
||||
if (item === undefined) {
|
||||
return options as MessageItem;
|
||||
}
|
||||
|
||||
return item;
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("should download a new database for language", async () => {
|
||||
await wizard.execute();
|
||||
await wizard.waitForDownload();
|
||||
|
||||
expect(askForGitHubRepoSpy).toHaveBeenCalled();
|
||||
expect(downloadGitHubDatabaseSpy).toHaveBeenCalled();
|
||||
});
|
||||
return item;
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("if the user choses to download a different database from GitHub than the one suggested", () => {
|
||||
beforeEach(() => {
|
||||
showInformationMessageSpy.mockImplementation(
|
||||
async (_message, options, item) => {
|
||||
if (item === undefined) {
|
||||
return options as MessageItem;
|
||||
}
|
||||
it("should download a new database for language", async () => {
|
||||
await wizard.execute();
|
||||
await wizard.waitForDownload();
|
||||
|
||||
return item;
|
||||
},
|
||||
);
|
||||
|
||||
const chosenGitHubRepo = "pickles-owner/pickles-repo";
|
||||
|
||||
askForGitHubRepoSpy = jest
|
||||
.spyOn(databaseFetcher, "askForGitHubRepo")
|
||||
.mockResolvedValue(chosenGitHubRepo);
|
||||
});
|
||||
|
||||
it("should download the newly chosen database", async () => {
|
||||
await wizard.execute();
|
||||
await wizard.waitForDownload();
|
||||
|
||||
expect(askForGitHubRepoSpy).toHaveBeenCalled();
|
||||
expect(downloadGitHubDatabaseSpy).toHaveBeenCalled();
|
||||
});
|
||||
expect(promptImportGithubDatabaseMock).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -504,7 +469,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
jest.fn(),
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
databaseFetcher,
|
||||
selectedItems,
|
||||
QueryLanguage.Javascript,
|
||||
);
|
||||
@@ -725,7 +690,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
jest.fn(),
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
databaseFetcher,
|
||||
selectedItems,
|
||||
);
|
||||
});
|
||||
@@ -754,7 +719,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
jest.fn(),
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
databaseFetcher,
|
||||
selectedItems,
|
||||
);
|
||||
});
|
||||
@@ -787,7 +752,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
jest.fn(),
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
databaseFetcher,
|
||||
selectedItems,
|
||||
QueryLanguage.Swift,
|
||||
);
|
||||
@@ -830,7 +795,7 @@ describe("SkeletonQueryWizard", () => {
|
||||
jest.fn(),
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
databaseFetcher,
|
||||
selectedItems,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -7,8 +7,8 @@ import type {
|
||||
} from "../../src/databases/local-databases";
|
||||
import type { CodeQLCliServer } from "../../src/codeql-cli/cli";
|
||||
import type { CodeQLExtensionInterface } from "../../src/extension";
|
||||
import { importLocalDatabase } from "../../src/databases/database-fetcher";
|
||||
import { createMockCommandManager } from "../__mocks__/commandsMock";
|
||||
import { DatabaseFetcher } from "../../src/databases/database-fetcher";
|
||||
import { createMockApp } from "../__mocks__/appMock";
|
||||
|
||||
// This file contains helpers shared between tests that work with an activated extension.
|
||||
|
||||
@@ -40,15 +40,17 @@ export async function ensureTestDatabase(
|
||||
// Add a database, but make sure the database manager is empty first
|
||||
await cleanDatabases(databaseManager);
|
||||
const uri = Uri.file(dbLoc);
|
||||
const maybeDbItem = await importLocalDatabase(
|
||||
createMockCommandManager(),
|
||||
uri.toString(true),
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
createMockApp(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cli,
|
||||
);
|
||||
const maybeDbItem = await databaseFetcher.importLocalDatabase(
|
||||
uri.toString(true),
|
||||
(_p) => {
|
||||
/**/
|
||||
},
|
||||
cli,
|
||||
);
|
||||
|
||||
if (!maybeDbItem) {
|
||||
|
||||
@@ -10,13 +10,11 @@ import {
|
||||
askForGitHubDatabaseDownload,
|
||||
downloadDatabaseFromGitHub,
|
||||
} from "../../../../../src/databases/github-databases/download";
|
||||
import type { DatabaseManager } from "../../../../../src/databases/local-databases";
|
||||
import type { GitHubDatabaseConfig } from "../../../../../src/config";
|
||||
import type { CodeQLCliServer } from "../../../../../src/codeql-cli/cli";
|
||||
import { createMockCommandManager } from "../../../../__mocks__/commandsMock";
|
||||
import * as databaseFetcher from "../../../../../src/databases/database-fetcher";
|
||||
import type { DatabaseFetcher } from "../../../../../src/databases/database-fetcher";
|
||||
import * as dialog from "../../../../../src/common/vscode/dialog";
|
||||
import type { CodeqlDatabase } from "../../../../../src/databases/github-databases/api";
|
||||
import { createMockApp } from "../../../../__mocks__/appMock";
|
||||
|
||||
describe("askForGitHubDatabaseDownload", () => {
|
||||
const setDownload = jest.fn();
|
||||
@@ -96,11 +94,9 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
let octokit: Octokit;
|
||||
const owner = "github";
|
||||
const repo = "codeql";
|
||||
let databaseManager: DatabaseManager;
|
||||
let databaseFetcher: DatabaseFetcher;
|
||||
|
||||
const storagePath = "/a/b/c/d";
|
||||
let cliServer: CodeQLCliServer;
|
||||
const commandManager = createMockCommandManager();
|
||||
const app = createMockApp();
|
||||
|
||||
let databases = [
|
||||
mockedObject<CodeqlDatabase>({
|
||||
@@ -116,14 +112,17 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
];
|
||||
|
||||
let showQuickPickSpy: jest.SpiedFunction<typeof window.showQuickPick>;
|
||||
let downloadGitHubDatabaseFromUrlSpy: jest.SpiedFunction<
|
||||
typeof databaseFetcher.downloadGitHubDatabaseFromUrl
|
||||
let downloadGitHubDatabaseFromUrlMock: jest.MockedFunction<
|
||||
DatabaseFetcher["downloadGitHubDatabaseFromUrl"]
|
||||
>;
|
||||
|
||||
beforeEach(() => {
|
||||
octokit = mockedObject<Octokit>({});
|
||||
databaseManager = mockedObject<DatabaseManager>({});
|
||||
cliServer = mockedObject<CodeQLCliServer>({});
|
||||
|
||||
downloadGitHubDatabaseFromUrlMock = jest.fn().mockReturnValue(undefined);
|
||||
databaseFetcher = mockedObject<DatabaseFetcher>({
|
||||
downloadGitHubDatabaseFromUrl: downloadGitHubDatabaseFromUrlMock,
|
||||
});
|
||||
|
||||
showQuickPickSpy = jest.spyOn(window, "showQuickPick").mockResolvedValue(
|
||||
mockedQuickPickItem([
|
||||
@@ -132,9 +131,6 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
}),
|
||||
]),
|
||||
);
|
||||
downloadGitHubDatabaseFromUrlSpy = jest
|
||||
.spyOn(databaseFetcher, "downloadGitHubDatabaseFromUrl")
|
||||
.mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
it("downloads the database", async () => {
|
||||
@@ -143,14 +139,12 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
owner,
|
||||
repo,
|
||||
databases,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
databaseFetcher,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledTimes(1);
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledWith(
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledTimes(1);
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledWith(
|
||||
databases[0].url,
|
||||
databases[0].id,
|
||||
databases[0].created_at,
|
||||
@@ -159,9 +153,6 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
@@ -207,14 +198,12 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
owner,
|
||||
repo,
|
||||
databases,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
databaseFetcher,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledTimes(1);
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledWith(
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledTimes(1);
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledWith(
|
||||
databases[1].url,
|
||||
databases[1].id,
|
||||
databases[1].created_at,
|
||||
@@ -223,9 +212,6 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
@@ -263,14 +249,12 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
owner,
|
||||
repo,
|
||||
databases,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
databaseFetcher,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledTimes(2);
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledWith(
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledTimes(2);
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledWith(
|
||||
databases[0].url,
|
||||
databases[0].id,
|
||||
databases[0].created_at,
|
||||
@@ -279,13 +263,10 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledWith(
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledWith(
|
||||
databases[1].url,
|
||||
databases[1].id,
|
||||
databases[1].created_at,
|
||||
@@ -294,9 +275,6 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
@@ -328,13 +306,11 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
owner,
|
||||
repo,
|
||||
databases,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
databaseFetcher,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).not.toHaveBeenCalled();
|
||||
expect(downloadGitHubDatabaseFromUrlMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,6 @@ import { createMockApp } from "../../../../__mocks__/appMock";
|
||||
import type { App } from "../../../../../src/common/app";
|
||||
import type { DatabaseManager } from "../../../../../src/databases/local-databases";
|
||||
import { mockEmptyDatabaseManager } from "../../query-testing/test-runner-helpers";
|
||||
import type { CodeQLCliServer } from "../../../../../src/codeql-cli/cli";
|
||||
import { mockDatabaseItem, mockedObject } from "../../../utils/mocking.helpers";
|
||||
import type { GitHubDatabaseConfig } from "../../../../../src/config";
|
||||
import { GitHubDatabasesModule } from "../../../../../src/databases/github-databases";
|
||||
@@ -16,13 +15,13 @@ import * as githubDatabasesApi from "../../../../../src/databases/github-databas
|
||||
import * as githubDatabasesDownload from "../../../../../src/databases/github-databases/download";
|
||||
import * as githubDatabasesUpdates from "../../../../../src/databases/github-databases/updates";
|
||||
import type { DatabaseUpdate } from "../../../../../src/databases/github-databases/updates";
|
||||
import type { DatabaseFetcher } from "../../../../../src/databases/database-fetcher";
|
||||
|
||||
describe("GitHubDatabasesModule", () => {
|
||||
describe("promptGitHubRepositoryDownload", () => {
|
||||
let app: App;
|
||||
let databaseManager: DatabaseManager;
|
||||
let databaseStoragePath: string;
|
||||
let cliServer: CodeQLCliServer;
|
||||
const databaseFetcher = mockedObject<DatabaseFetcher>({});
|
||||
let config: GitHubDatabaseConfig;
|
||||
let gitHubDatabasesModule: GitHubDatabasesModule;
|
||||
|
||||
@@ -64,8 +63,6 @@ describe("GitHubDatabasesModule", () => {
|
||||
beforeEach(() => {
|
||||
app = createMockApp();
|
||||
databaseManager = mockEmptyDatabaseManager();
|
||||
databaseStoragePath = "/a/b/some-path";
|
||||
cliServer = mockedObject<CodeQLCliServer>({});
|
||||
config = mockedObject<GitHubDatabaseConfig>({
|
||||
download: "ask",
|
||||
update: "ask",
|
||||
@@ -74,8 +71,7 @@ describe("GitHubDatabasesModule", () => {
|
||||
gitHubDatabasesModule = new GitHubDatabasesModule(
|
||||
app,
|
||||
databaseManager,
|
||||
databaseStoragePath,
|
||||
cliServer,
|
||||
databaseFetcher,
|
||||
config,
|
||||
);
|
||||
|
||||
@@ -124,8 +120,7 @@ describe("GitHubDatabasesModule", () => {
|
||||
gitHubDatabasesModule = new GitHubDatabasesModule(
|
||||
app,
|
||||
databaseManager,
|
||||
databaseStoragePath,
|
||||
cliServer,
|
||||
databaseFetcher,
|
||||
config,
|
||||
);
|
||||
|
||||
@@ -206,9 +201,7 @@ describe("GitHubDatabasesModule", () => {
|
||||
owner,
|
||||
repo,
|
||||
databases,
|
||||
databaseManager,
|
||||
databaseStoragePath,
|
||||
cliServer,
|
||||
databaseFetcher,
|
||||
app.commands,
|
||||
);
|
||||
});
|
||||
@@ -250,8 +243,7 @@ describe("GitHubDatabasesModule", () => {
|
||||
repo,
|
||||
databaseUpdates,
|
||||
databaseManager,
|
||||
databaseStoragePath,
|
||||
cliServer,
|
||||
databaseFetcher,
|
||||
app.commands,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -10,9 +10,7 @@ import {
|
||||
import type { CodeqlDatabase } from "../../../../../src/databases/github-databases/api";
|
||||
import type { DatabaseManager } from "../../../../../src/databases/local-databases";
|
||||
import type { GitHubDatabaseConfig } from "../../../../../src/config";
|
||||
import type { CodeQLCliServer } from "../../../../../src/codeql-cli/cli";
|
||||
import { createMockCommandManager } from "../../../../__mocks__/commandsMock";
|
||||
import * as databaseFetcher from "../../../../../src/databases/database-fetcher";
|
||||
import type { DatabaseFetcher } from "../../../../../src/databases/database-fetcher";
|
||||
import * as dialog from "../../../../../src/common/vscode/dialog";
|
||||
import type { DatabaseUpdate } from "../../../../../src/databases/github-databases/updates";
|
||||
import {
|
||||
@@ -20,6 +18,7 @@ import {
|
||||
downloadDatabaseUpdateFromGitHub,
|
||||
isNewerDatabaseAvailable,
|
||||
} from "../../../../../src/databases/github-databases/updates";
|
||||
import { createMockApp } from "../../../../__mocks__/appMock";
|
||||
|
||||
describe("isNewerDatabaseAvailable", () => {
|
||||
const owner = "github";
|
||||
@@ -344,9 +343,8 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
const owner = "github";
|
||||
const repo = "codeql";
|
||||
let databaseManager: DatabaseManager;
|
||||
const storagePath = "/a/b/c/d";
|
||||
let cliServer: CodeQLCliServer;
|
||||
const commandManager = createMockCommandManager();
|
||||
let databaseFetcher: DatabaseFetcher;
|
||||
const app = createMockApp();
|
||||
|
||||
let updates: DatabaseUpdate[] = [
|
||||
{
|
||||
@@ -367,8 +365,8 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
];
|
||||
|
||||
let showQuickPickSpy: jest.SpiedFunction<typeof window.showQuickPick>;
|
||||
let downloadGitHubDatabaseFromUrlSpy: jest.SpiedFunction<
|
||||
typeof databaseFetcher.downloadGitHubDatabaseFromUrl
|
||||
let downloadGitHubDatabaseFromUrlMock: jest.MockedFunction<
|
||||
DatabaseFetcher["downloadGitHubDatabaseFromUrl"]
|
||||
>;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -376,7 +374,11 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
databaseManager = mockedObject<DatabaseManager>({
|
||||
currentDatabaseItem: mockDatabaseItem(),
|
||||
});
|
||||
cliServer = mockedObject<CodeQLCliServer>({});
|
||||
|
||||
downloadGitHubDatabaseFromUrlMock = jest.fn().mockReturnValue(undefined);
|
||||
databaseFetcher = mockedObject<DatabaseFetcher>({
|
||||
downloadGitHubDatabaseFromUrl: downloadGitHubDatabaseFromUrlMock,
|
||||
});
|
||||
|
||||
showQuickPickSpy = jest.spyOn(window, "showQuickPick").mockResolvedValue(
|
||||
mockedQuickPickItem([
|
||||
@@ -385,9 +387,6 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
}),
|
||||
]),
|
||||
);
|
||||
downloadGitHubDatabaseFromUrlSpy = jest
|
||||
.spyOn(databaseFetcher, "downloadGitHubDatabaseFromUrl")
|
||||
.mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
it("downloads the database", async () => {
|
||||
@@ -397,13 +396,12 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
repo,
|
||||
updates,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
databaseFetcher,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledTimes(1);
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledWith(
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledTimes(1);
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledWith(
|
||||
updates[0].database.url,
|
||||
updates[0].database.id,
|
||||
updates[0].database.created_at,
|
||||
@@ -412,9 +410,6 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
@@ -476,13 +471,12 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
repo,
|
||||
updates,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
databaseFetcher,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledTimes(1);
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledWith(
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledTimes(1);
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledWith(
|
||||
updates[1].database.url,
|
||||
updates[1].database.id,
|
||||
updates[1].database.created_at,
|
||||
@@ -491,9 +485,6 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
@@ -532,13 +523,12 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
repo,
|
||||
updates,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
databaseFetcher,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledTimes(2);
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledWith(
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledTimes(2);
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledWith(
|
||||
updates[0].database.url,
|
||||
updates[0].database.id,
|
||||
updates[0].database.created_at,
|
||||
@@ -547,13 +537,10 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledWith(
|
||||
expect(downloadGitHubDatabaseFromUrlMock).toHaveBeenCalledWith(
|
||||
updates[1].database.url,
|
||||
updates[1].database.id,
|
||||
updates[1].database.created_at,
|
||||
@@ -562,9 +549,6 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
@@ -597,12 +581,11 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
repo,
|
||||
updates,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
databaseFetcher,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).not.toHaveBeenCalled();
|
||||
expect(downloadGitHubDatabaseFromUrlMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,6 +20,7 @@ import { testDisposeHandler } from "../../test-dispose-handler";
|
||||
import { createMockApp } from "../../../__mocks__/appMock";
|
||||
import { QueryLanguage } from "../../../../src/common/query-language";
|
||||
import { mockedQuickPickItem, mockedObject } from "../../utils/mocking.helpers";
|
||||
import type { DatabaseFetcher } from "../../../../src/databases/database-fetcher";
|
||||
|
||||
describe("local-databases-ui", () => {
|
||||
const storageDir = dirSync({ unsafeCleanup: true }).name;
|
||||
@@ -104,6 +105,7 @@ describe("local-databases-ui", () => {
|
||||
},
|
||||
setCurrentDatabaseItem: () => {},
|
||||
} as any,
|
||||
mockedObject<DatabaseFetcher>({}),
|
||||
{
|
||||
onLanguageContextChanged: () => {
|
||||
/**/
|
||||
@@ -141,6 +143,7 @@ describe("local-databases-ui", () => {
|
||||
setCurrentDatabaseItem: () => {},
|
||||
currentDatabaseItem: { databaseUri: Uri.file(db1) },
|
||||
} as any,
|
||||
mockedObject<DatabaseFetcher>({}),
|
||||
{
|
||||
onLanguageContextChanged: () => {
|
||||
/**/
|
||||
@@ -177,6 +180,7 @@ describe("local-databases-ui", () => {
|
||||
const databaseUI = new DatabaseUI(
|
||||
app,
|
||||
databaseManager,
|
||||
mockedObject<DatabaseFetcher>({}),
|
||||
{
|
||||
onLanguageContextChanged: () => {
|
||||
/**/
|
||||
|
||||
@@ -13,6 +13,7 @@ import type { ModelConfigListener } from "../../../../src/config";
|
||||
import { createMockModelingEvents } from "../../../__mocks__/model-editor/modelingEventsMock";
|
||||
import { QueryLanguage } from "../../../../src/common/query-language";
|
||||
import type { VariantAnalysisManager } from "../../../../src/variant-analysis/variant-analysis-manager";
|
||||
import type { DatabaseFetcher } from "../../../../src/databases/database-fetcher";
|
||||
|
||||
describe("ModelEditorView", () => {
|
||||
const app = createMockApp({});
|
||||
@@ -22,6 +23,7 @@ describe("ModelEditorView", () => {
|
||||
onDidChangeConfiguration: jest.fn(),
|
||||
});
|
||||
const databaseManager = mockEmptyDatabaseManager();
|
||||
const databaseFetcher = mockedObject<DatabaseFetcher>({});
|
||||
const variantAnalysisManager = mockedObject<VariantAnalysisManager>({});
|
||||
const cliServer = mockedObject<CodeQLCliServer>({});
|
||||
const queryRunner = mockedObject<QueryRunner>({});
|
||||
@@ -50,6 +52,7 @@ describe("ModelEditorView", () => {
|
||||
modelingEvents,
|
||||
modelConfig,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
variantAnalysisManager,
|
||||
cliServer,
|
||||
queryRunner,
|
||||
|
||||
Reference in New Issue
Block a user