Extract config file to constant
This commit is contained in:
@@ -32,6 +32,8 @@ import {
|
|||||||
} from "../db-item";
|
} from "../db-item";
|
||||||
|
|
||||||
export class DbConfigStore extends DisposableObject {
|
export class DbConfigStore extends DisposableObject {
|
||||||
|
static readonly databaseConfigFileName = "workspace-databases.json";
|
||||||
|
|
||||||
public readonly onDidChangeConfig: AppEvent<void>;
|
public readonly onDidChangeConfig: AppEvent<void>;
|
||||||
private readonly onDidChangeConfigEventEmitter: AppEventEmitter<void>;
|
private readonly onDidChangeConfigEventEmitter: AppEventEmitter<void>;
|
||||||
|
|
||||||
@@ -49,7 +51,7 @@ export class DbConfigStore extends DisposableObject {
|
|||||||
super();
|
super();
|
||||||
|
|
||||||
const storagePath = app.workspaceStoragePath || app.globalStoragePath;
|
const storagePath = app.workspaceStoragePath || app.globalStoragePath;
|
||||||
this.configPath = join(storagePath, "workspace-databases.json");
|
this.configPath = join(storagePath, DbConfigStore.databaseConfigFileName);
|
||||||
|
|
||||||
this.config = this.createEmptyConfig();
|
this.config = this.createEmptyConfig();
|
||||||
this.configErrors = [];
|
this.configErrors = [];
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ describe("db config store", () => {
|
|||||||
|
|
||||||
const configPath = join(
|
const configPath = join(
|
||||||
tempWorkspaceStoragePath,
|
tempWorkspaceStoragePath,
|
||||||
"workspace-databases.json",
|
DbConfigStore.databaseConfigFileName,
|
||||||
);
|
);
|
||||||
|
|
||||||
const configStore = new DbConfigStore(app, false);
|
const configStore = new DbConfigStore(app, false);
|
||||||
@@ -195,7 +195,10 @@ describe("db config store", () => {
|
|||||||
workspaceStoragePath: tempWorkspaceStoragePath,
|
workspaceStoragePath: tempWorkspaceStoragePath,
|
||||||
});
|
});
|
||||||
|
|
||||||
configPath = join(tempWorkspaceStoragePath, "workspace-databases.json");
|
configPath = join(
|
||||||
|
tempWorkspaceStoragePath,
|
||||||
|
DbConfigStore.databaseConfigFileName,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should add a remote repository", async () => {
|
it("should add a remote repository", async () => {
|
||||||
@@ -320,7 +323,10 @@ describe("db config store", () => {
|
|||||||
workspaceStoragePath: tempWorkspaceStoragePath,
|
workspaceStoragePath: tempWorkspaceStoragePath,
|
||||||
});
|
});
|
||||||
|
|
||||||
configPath = join(tempWorkspaceStoragePath, "workspace-databases.json");
|
configPath = join(
|
||||||
|
tempWorkspaceStoragePath,
|
||||||
|
DbConfigStore.databaseConfigFileName,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow renaming a remote list", async () => {
|
it("should allow renaming a remote list", async () => {
|
||||||
@@ -492,7 +498,10 @@ describe("db config store", () => {
|
|||||||
workspaceStoragePath: tempWorkspaceStoragePath,
|
workspaceStoragePath: tempWorkspaceStoragePath,
|
||||||
});
|
});
|
||||||
|
|
||||||
configPath = join(tempWorkspaceStoragePath, "workspace-databases.json");
|
configPath = join(
|
||||||
|
tempWorkspaceStoragePath,
|
||||||
|
DbConfigStore.databaseConfigFileName,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should remove a single db item", async () => {
|
it("should remove a single db item", async () => {
|
||||||
@@ -612,7 +621,10 @@ describe("db config store", () => {
|
|||||||
workspaceStoragePath: tempWorkspaceStoragePath,
|
workspaceStoragePath: tempWorkspaceStoragePath,
|
||||||
});
|
});
|
||||||
|
|
||||||
configPath = join(tempWorkspaceStoragePath, "workspace-databases.json");
|
configPath = join(
|
||||||
|
tempWorkspaceStoragePath,
|
||||||
|
DbConfigStore.databaseConfigFileName,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should set the selected item", async () => {
|
it("should set the selected item", async () => {
|
||||||
@@ -648,7 +660,10 @@ describe("db config store", () => {
|
|||||||
workspaceStoragePath: tempWorkspaceStoragePath,
|
workspaceStoragePath: tempWorkspaceStoragePath,
|
||||||
});
|
});
|
||||||
|
|
||||||
configPath = join(tempWorkspaceStoragePath, "workspace-databases.json");
|
configPath = join(
|
||||||
|
tempWorkspaceStoragePath,
|
||||||
|
DbConfigStore.databaseConfigFileName,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return true if a remote owner exists", async () => {
|
it("should return true if a remote owner exists", async () => {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ describe("db manager", () => {
|
|||||||
|
|
||||||
dbConfigFilePath = join(
|
dbConfigFilePath = join(
|
||||||
tempWorkspaceStoragePath,
|
tempWorkspaceStoragePath,
|
||||||
"workspace-databases.json",
|
DbConfigStore.databaseConfigFileName,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
import { DbListKind } from "../../../../src/databases/db-item";
|
import { DbListKind } from "../../../../src/databases/db-item";
|
||||||
import { createDbTreeViewItemSystemDefinedList } from "../../../../src/databases/ui/db-tree-view-item";
|
import { createDbTreeViewItemSystemDefinedList } from "../../../../src/databases/ui/db-tree-view-item";
|
||||||
import { createRemoteSystemDefinedListDbItem } from "../../../factories/db-item-factories";
|
import { createRemoteSystemDefinedListDbItem } from "../../../factories/db-item-factories";
|
||||||
|
import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
|
||||||
|
|
||||||
jest.setTimeout(60_000);
|
jest.setTimeout(60_000);
|
||||||
|
|
||||||
@@ -43,7 +44,10 @@ describe("Db panel UI commands", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Check db config
|
// Check db config
|
||||||
const dbConfigFilePath = path.join(storagePath, "workspace-databases.json");
|
const dbConfigFilePath = path.join(
|
||||||
|
storagePath,
|
||||||
|
DbConfigStore.databaseConfigFileName,
|
||||||
|
);
|
||||||
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
|
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
|
||||||
expect(dbConfig.databases.variantAnalysis.repositoryLists).toHaveLength(1);
|
expect(dbConfig.databases.variantAnalysis.repositoryLists).toHaveLength(1);
|
||||||
expect(dbConfig.databases.variantAnalysis.repositoryLists[0].name).toBe(
|
expect(dbConfig.databases.variantAnalysis.repositoryLists[0].name).toBe(
|
||||||
@@ -62,7 +66,10 @@ describe("Db panel UI commands", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Check db config
|
// Check db config
|
||||||
const dbConfigFilePath = path.join(storagePath, "workspace-databases.json");
|
const dbConfigFilePath = path.join(
|
||||||
|
storagePath,
|
||||||
|
DbConfigStore.databaseConfigFileName,
|
||||||
|
);
|
||||||
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
|
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
|
||||||
expect(dbConfig.databases.local.lists).toHaveLength(1);
|
expect(dbConfig.databases.local.lists).toHaveLength(1);
|
||||||
expect(dbConfig.databases.local.lists[0].name).toBe("my-list-1");
|
expect(dbConfig.databases.local.lists[0].name).toBe("my-list-1");
|
||||||
@@ -80,7 +87,10 @@ describe("Db panel UI commands", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Check db config
|
// Check db config
|
||||||
const dbConfigFilePath = path.join(storagePath, "workspace-databases.json");
|
const dbConfigFilePath = path.join(
|
||||||
|
storagePath,
|
||||||
|
DbConfigStore.databaseConfigFileName,
|
||||||
|
);
|
||||||
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
|
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
|
||||||
expect(dbConfig.databases.variantAnalysis.repositories).toHaveLength(1);
|
expect(dbConfig.databases.variantAnalysis.repositories).toHaveLength(1);
|
||||||
expect(dbConfig.databases.variantAnalysis.repositories[0]).toBe(
|
expect(dbConfig.databases.variantAnalysis.repositories[0]).toBe(
|
||||||
@@ -100,7 +110,10 @@ describe("Db panel UI commands", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Check db config
|
// Check db config
|
||||||
const dbConfigFilePath = path.join(storagePath, "workspace-databases.json");
|
const dbConfigFilePath = path.join(
|
||||||
|
storagePath,
|
||||||
|
DbConfigStore.databaseConfigFileName,
|
||||||
|
);
|
||||||
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
|
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
|
||||||
expect(dbConfig.databases.variantAnalysis.owners).toHaveLength(1);
|
expect(dbConfig.databases.variantAnalysis.owners).toHaveLength(1);
|
||||||
expect(dbConfig.databases.variantAnalysis.owners[0]).toBe("owner1");
|
expect(dbConfig.databases.variantAnalysis.owners[0]).toBe("owner1");
|
||||||
@@ -120,7 +133,10 @@ describe("Db panel UI commands", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Check db config
|
// Check db config
|
||||||
const dbConfigFilePath = path.join(storagePath, "workspace-databases.json");
|
const dbConfigFilePath = path.join(
|
||||||
|
storagePath,
|
||||||
|
DbConfigStore.databaseConfigFileName,
|
||||||
|
);
|
||||||
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
|
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
|
||||||
expect(dbConfig.selected).toBeDefined();
|
expect(dbConfig.selected).toBeDefined();
|
||||||
expect(dbConfig.selected).toEqual({
|
expect(dbConfig.selected).toEqual({
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ describe("db panel", () => {
|
|||||||
const extensionPath = join(__dirname, "../../../../");
|
const extensionPath = join(__dirname, "../../../../");
|
||||||
const dbConfigFilePath = join(
|
const dbConfigFilePath = join(
|
||||||
workspaceStoragePath,
|
workspaceStoragePath,
|
||||||
"workspace-databases.json",
|
DbConfigStore.databaseConfigFileName,
|
||||||
);
|
);
|
||||||
let dbTreeDataProvider: DbTreeDataProvider;
|
let dbTreeDataProvider: DbTreeDataProvider;
|
||||||
let dbManager: DbManager;
|
let dbManager: DbManager;
|
||||||
|
|||||||
Reference in New Issue
Block a user