Fix tests when no controller repo is set
This also extracts the helper to do so into a separate function to avoid duplicating this logic.
This commit is contained in:
Родитель
b3c4979358
Коммит
6114b591c5
|
@ -12,6 +12,7 @@ import {
|
|||
|
||||
import { CodeQLExtensionInterface } from "../../../../src/extension";
|
||||
import { MockGitHubApiServer } from "../../../../src/mocks/mock-gh-api-server";
|
||||
import { mockConfiguration } from "../../utils/configuration-helpers";
|
||||
|
||||
jest.setTimeout(30_000);
|
||||
|
||||
|
@ -35,50 +36,17 @@ describe("Variant Analysis Submission Integration", () => {
|
|||
let showErrorMessageSpy: jest.SpiedFunction<typeof window.showErrorMessage>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const originalGetConfiguration = workspace.getConfiguration;
|
||||
|
||||
jest
|
||||
.spyOn(workspace, "getConfiguration")
|
||||
.mockImplementation((section, scope) => {
|
||||
const configuration = originalGetConfiguration(section, scope);
|
||||
|
||||
return {
|
||||
get(key: string, defaultValue?: unknown) {
|
||||
if (section === "codeQL.variantAnalysis" && key === "liveResults") {
|
||||
return true;
|
||||
}
|
||||
if (section === "codeQL" && key == "canary") {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
section === "codeQL.variantAnalysis" &&
|
||||
key === "controllerRepo"
|
||||
) {
|
||||
return "github/vscode-codeql";
|
||||
}
|
||||
return configuration.get(key, defaultValue);
|
||||
},
|
||||
has(key: string) {
|
||||
return configuration.has(key);
|
||||
},
|
||||
inspect(key: string) {
|
||||
return configuration.inspect(key);
|
||||
},
|
||||
update(
|
||||
key: string,
|
||||
value: unknown,
|
||||
configurationTarget?: boolean,
|
||||
overrideInLanguage?: boolean,
|
||||
) {
|
||||
return configuration.update(
|
||||
key,
|
||||
value,
|
||||
configurationTarget,
|
||||
overrideInLanguage,
|
||||
);
|
||||
},
|
||||
};
|
||||
});
|
||||
mockConfiguration({
|
||||
values: {
|
||||
codeQL: {
|
||||
canary: true,
|
||||
},
|
||||
"codeQL.variantAnalysis": {
|
||||
liveResults: true,
|
||||
controllerRepo: "github/vscode-codeql",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
jest.spyOn(authentication, "getSession").mockResolvedValue({
|
||||
id: "test",
|
||||
|
|
|
@ -13,6 +13,7 @@ import { DbTreeViewItem } from "../../../../src/databases/ui/db-tree-view-item";
|
|||
import { ExtensionApp } from "../../../../src/common/vscode/vscode-app";
|
||||
import { createMockExtensionContext } from "../../../factories/extension-context";
|
||||
import { createDbConfig } from "../../../factories/db-config-factories";
|
||||
import { mockConfiguration } from "../../utils/configuration-helpers";
|
||||
|
||||
describe("db panel rendering nodes", () => {
|
||||
const workspaceStoragePath = join(__dirname, "test-workspace-storage");
|
||||
|
@ -42,6 +43,14 @@ describe("db panel rendering nodes", () => {
|
|||
|
||||
beforeEach(async () => {
|
||||
await ensureDir(workspaceStoragePath);
|
||||
|
||||
mockConfiguration({
|
||||
values: {
|
||||
"codeQL.variantAnalysis": {
|
||||
controllerRepo: "github/codeql",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
|
|
|
@ -9,6 +9,7 @@ import { DbTreeViewItem } from "../../../../src/databases/ui/db-tree-view-item";
|
|||
import { ExtensionApp } from "../../../../src/common/vscode/vscode-app";
|
||||
import { createMockExtensionContext } from "../../../factories/extension-context";
|
||||
import { createDbConfig } from "../../../factories/db-config-factories";
|
||||
import { mockConfiguration } from "../../utils/configuration-helpers";
|
||||
|
||||
describe("db panel", () => {
|
||||
const workspaceStoragePath = join(__dirname, "test-workspace-storage");
|
||||
|
@ -38,6 +39,14 @@ describe("db panel", () => {
|
|||
|
||||
beforeEach(async () => {
|
||||
await ensureDir(workspaceStoragePath);
|
||||
|
||||
mockConfiguration({
|
||||
values: {
|
||||
"codeQL.variantAnalysis": {
|
||||
controllerRepo: "github/codeql",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
|
|
|
@ -15,6 +15,7 @@ import {
|
|||
import { ExtensionApp } from "../../../../src/common/vscode/vscode-app";
|
||||
import { createMockExtensionContext } from "../../../factories/extension-context";
|
||||
import { createDbConfig } from "../../../factories/db-config-factories";
|
||||
import { mockConfiguration } from "../../utils/configuration-helpers";
|
||||
|
||||
describe("db panel selection", () => {
|
||||
const workspaceStoragePath = join(__dirname, "test-workspace-storage");
|
||||
|
@ -50,101 +51,150 @@ describe("db panel selection", () => {
|
|||
await remove(workspaceStoragePath);
|
||||
});
|
||||
|
||||
it("should mark selected remote db list as selected", async () => {
|
||||
const dbConfig: DbConfig = createDbConfig({
|
||||
remoteLists: [
|
||||
{
|
||||
name: "my-list-1",
|
||||
repositories: ["owner1/repo1", "owner1/repo2"],
|
||||
describe("when controller repo is not set", () => {
|
||||
beforeEach(() => {
|
||||
mockConfiguration({
|
||||
values: {
|
||||
"codeQL.variantAnalysis": {
|
||||
controllerRepo: undefined,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "my-list-2",
|
||||
repositories: ["owner2/repo1", "owner2/repo2"],
|
||||
},
|
||||
],
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.VariantAnalysisUserDefinedList,
|
||||
listName: "my-list-2",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
await saveDbConfig(dbConfig);
|
||||
it("should not have any items", async () => {
|
||||
const dbConfig: DbConfig = createDbConfig({
|
||||
remoteLists: [
|
||||
{
|
||||
name: "my-list-1",
|
||||
repositories: ["owner1/repo1", "owner1/repo2"],
|
||||
},
|
||||
{
|
||||
name: "my-list-2",
|
||||
repositories: ["owner2/repo1", "owner2/repo2"],
|
||||
},
|
||||
],
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.VariantAnalysisUserDefinedList,
|
||||
listName: "my-list-2",
|
||||
},
|
||||
});
|
||||
|
||||
const dbTreeItems = await dbTreeDataProvider.getChildren();
|
||||
await saveDbConfig(dbConfig);
|
||||
|
||||
expect(dbTreeItems).toBeTruthy();
|
||||
const items = dbTreeItems!;
|
||||
const dbTreeItems = await dbTreeDataProvider.getChildren();
|
||||
|
||||
const list1 = items.find(
|
||||
(c) =>
|
||||
c.dbItem?.kind === DbItemKind.RemoteUserDefinedList &&
|
||||
c.dbItem?.listName === "my-list-1",
|
||||
);
|
||||
const list2 = items.find(
|
||||
(c) =>
|
||||
c.dbItem?.kind === DbItemKind.RemoteUserDefinedList &&
|
||||
c.dbItem?.listName === "my-list-2",
|
||||
);
|
||||
|
||||
expect(list1).toBeTruthy();
|
||||
expect(list2).toBeTruthy();
|
||||
expect(isTreeViewItemSelectable(list1!)).toBeTruthy();
|
||||
expect(isTreeViewItemSelected(list2!)).toBeTruthy();
|
||||
expect(dbTreeItems).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
it("should mark selected remote db inside list as selected", async () => {
|
||||
const dbConfig: DbConfig = createDbConfig({
|
||||
remoteLists: [
|
||||
{
|
||||
name: "my-list-1",
|
||||
repositories: ["owner1/repo1", "owner1/repo2"],
|
||||
describe("when controller repo is set", () => {
|
||||
beforeEach(() => {
|
||||
mockConfiguration({
|
||||
values: {
|
||||
"codeQL.variantAnalysis": {
|
||||
controllerRepo: "github/codeql",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "my-list-2",
|
||||
repositories: ["owner1/repo1", "owner2/repo2"],
|
||||
},
|
||||
],
|
||||
remoteRepos: ["owner1/repo1"],
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.VariantAnalysisRepository,
|
||||
repositoryName: "owner1/repo1",
|
||||
listName: "my-list-2",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
await saveDbConfig(dbConfig);
|
||||
it("should mark selected remote db list as selected", async () => {
|
||||
const dbConfig: DbConfig = createDbConfig({
|
||||
remoteLists: [
|
||||
{
|
||||
name: "my-list-1",
|
||||
repositories: ["owner1/repo1", "owner1/repo2"],
|
||||
},
|
||||
{
|
||||
name: "my-list-2",
|
||||
repositories: ["owner2/repo1", "owner2/repo2"],
|
||||
},
|
||||
],
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.VariantAnalysisUserDefinedList,
|
||||
listName: "my-list-2",
|
||||
},
|
||||
});
|
||||
|
||||
const dbTreeItems = await dbTreeDataProvider.getChildren();
|
||||
await saveDbConfig(dbConfig);
|
||||
|
||||
expect(dbTreeItems).toBeTruthy();
|
||||
const items = dbTreeItems!;
|
||||
const dbTreeItems = await dbTreeDataProvider.getChildren();
|
||||
|
||||
const list2 = items.find(
|
||||
(c) =>
|
||||
c.dbItem?.kind === DbItemKind.RemoteUserDefinedList &&
|
||||
c.dbItem?.listName === "my-list-2",
|
||||
);
|
||||
expect(list2).toBeTruthy();
|
||||
expect(dbTreeItems).toBeTruthy();
|
||||
const items = dbTreeItems!;
|
||||
|
||||
const repo1Node = list2?.children.find(
|
||||
(c) =>
|
||||
c.dbItem?.kind === DbItemKind.RemoteRepo &&
|
||||
c.dbItem?.repoFullName === "owner1/repo1",
|
||||
);
|
||||
expect(repo1Node).toBeTruthy();
|
||||
expect(isTreeViewItemSelected(repo1Node!)).toBeTruthy();
|
||||
const list1 = items.find(
|
||||
(c) =>
|
||||
c.dbItem?.kind === DbItemKind.RemoteUserDefinedList &&
|
||||
c.dbItem?.listName === "my-list-1",
|
||||
);
|
||||
const list2 = items.find(
|
||||
(c) =>
|
||||
c.dbItem?.kind === DbItemKind.RemoteUserDefinedList &&
|
||||
c.dbItem?.listName === "my-list-2",
|
||||
);
|
||||
|
||||
const repo2Node = list2?.children.find(
|
||||
(c) =>
|
||||
c.dbItem?.kind === DbItemKind.RemoteRepo &&
|
||||
c.dbItem?.repoFullName === "owner2/repo2",
|
||||
);
|
||||
expect(repo2Node).toBeTruthy();
|
||||
expect(isTreeViewItemSelectable(repo2Node!)).toBeTruthy();
|
||||
expect(list1).toBeTruthy();
|
||||
expect(list2).toBeTruthy();
|
||||
expect(isTreeViewItemSelectable(list1!)).toBeTruthy();
|
||||
expect(isTreeViewItemSelected(list2!)).toBeTruthy();
|
||||
});
|
||||
|
||||
for (const item of items) {
|
||||
expect(isTreeViewItemSelectable(item)).toBeTruthy();
|
||||
}
|
||||
it("should mark selected remote db inside list as selected", async () => {
|
||||
const dbConfig: DbConfig = createDbConfig({
|
||||
remoteLists: [
|
||||
{
|
||||
name: "my-list-1",
|
||||
repositories: ["owner1/repo1", "owner1/repo2"],
|
||||
},
|
||||
{
|
||||
name: "my-list-2",
|
||||
repositories: ["owner1/repo1", "owner2/repo2"],
|
||||
},
|
||||
],
|
||||
remoteRepos: ["owner1/repo1"],
|
||||
selected: {
|
||||
kind: SelectedDbItemKind.VariantAnalysisRepository,
|
||||
repositoryName: "owner1/repo1",
|
||||
listName: "my-list-2",
|
||||
},
|
||||
});
|
||||
|
||||
await saveDbConfig(dbConfig);
|
||||
|
||||
const dbTreeItems = await dbTreeDataProvider.getChildren();
|
||||
|
||||
expect(dbTreeItems).toBeTruthy();
|
||||
const items = dbTreeItems!;
|
||||
|
||||
const list2 = items.find(
|
||||
(c) =>
|
||||
c.dbItem?.kind === DbItemKind.RemoteUserDefinedList &&
|
||||
c.dbItem?.listName === "my-list-2",
|
||||
);
|
||||
expect(list2).toBeTruthy();
|
||||
|
||||
const repo1Node = list2?.children.find(
|
||||
(c) =>
|
||||
c.dbItem?.kind === DbItemKind.RemoteRepo &&
|
||||
c.dbItem?.repoFullName === "owner1/repo1",
|
||||
);
|
||||
expect(repo1Node).toBeTruthy();
|
||||
expect(isTreeViewItemSelected(repo1Node!)).toBeTruthy();
|
||||
|
||||
const repo2Node = list2?.children.find(
|
||||
(c) =>
|
||||
c.dbItem?.kind === DbItemKind.RemoteRepo &&
|
||||
c.dbItem?.repoFullName === "owner2/repo2",
|
||||
);
|
||||
expect(repo2Node).toBeTruthy();
|
||||
expect(isTreeViewItemSelectable(repo2Node!)).toBeTruthy();
|
||||
|
||||
for (const item of items) {
|
||||
expect(isTreeViewItemSelectable(item)).toBeTruthy();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
async function saveDbConfig(dbConfig: DbConfig): Promise<void> {
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
import { workspace } from "vscode";
|
||||
|
||||
type MockConfigurationConfig = {
|
||||
values: {
|
||||
[section: string]: {
|
||||
[scope: string]: any | (() => any);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export function mockConfiguration(config: MockConfigurationConfig) {
|
||||
const originalGetConfiguration = workspace.getConfiguration;
|
||||
|
||||
jest
|
||||
.spyOn(workspace, "getConfiguration")
|
||||
.mockImplementation((section, scope) => {
|
||||
const configuration = originalGetConfiguration(section, scope);
|
||||
|
||||
return {
|
||||
get(key: string, defaultValue?: unknown) {
|
||||
if (
|
||||
section &&
|
||||
config.values[section] &&
|
||||
config.values[section][key]
|
||||
) {
|
||||
const value = config.values[section][key];
|
||||
return typeof value === "function" ? value() : value;
|
||||
}
|
||||
|
||||
return configuration.get(key, defaultValue);
|
||||
},
|
||||
has(key: string) {
|
||||
return configuration.has(key);
|
||||
},
|
||||
inspect(key: string) {
|
||||
return configuration.inspect(key);
|
||||
},
|
||||
update(
|
||||
key: string,
|
||||
value: unknown,
|
||||
configurationTarget?: boolean,
|
||||
overrideInLanguage?: boolean,
|
||||
) {
|
||||
return configuration.update(
|
||||
key,
|
||||
value,
|
||||
configurationTarget,
|
||||
overrideInLanguage,
|
||||
);
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
Загрузка…
Ссылка в новой задаче