mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove a lot of usages of legacy globals (#6825)
* Remove all usages of legacy global logger Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global storageClassApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global serviceApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global secretApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global resourceQuotaApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global persistentVolumeClaimApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global nodeApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global networkPolicyApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix formatting Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global configMapApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global jobApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global cronJobApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global podApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global roleApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove exports of NonInjected components - To improve auto-complete Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global catalogEntityRegistry Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add lint against using legacy global works Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint in KubeObject file Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global catalogCategoryRegistry Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global navigation Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global navigate Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unneeded index file Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global customResourceDefinitionStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global eventStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global podSecurityPolicyStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global storageClassStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global persistentVolumeStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global clusterRoleBindingStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global clusterRoleStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global roleBindingStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move files around Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global roleStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global serviceAccountStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global podStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove final uses of asLegacyGlobalForExtensionApi in application code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint rule and start fixing lint errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make listHelmReleases injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make installHelmChart injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make deleteHelmRelease injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make getHelmReleaseValues injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make getHelmReleaseHistory injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make rollbackHelmRelease injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary overrides from getDiForUnitTesting Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for logger Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for history Signed-off-by: Sebastian Malton <sebastian@malton.name> * Cleanup typing around getting injectables within jest Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move some more overrides to global if needed Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for forcusWindow Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint in KubeApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint in catalog/index.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last usages of legacy global getDetailsUrl Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last usages of legacy global showDetails Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add functions back to extension API Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove all uses of legacy global Notification functions Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove no longer existing export Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary overrides Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix injecting side effects by using more injectables Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix cluster role binding dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix cluster role dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix create service account dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix history override Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make KubeApi consume its dependencies while not breaking the extension API Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix CephFs tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix user store tests by using override of config Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in hotbar store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add direct devDep of memfs Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in cluster store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in router tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in kube auth proxy tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in log resource selector tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in hotbar remove command tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in the select component tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove mock-fs as a dependency Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove no longer necessary mocks Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix namespace select filter tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in the extension loader tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixing edit-namespace-from-new-tab test Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix app paths tests by making the tests run in "production" mode Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last vestiges of isTestEnv and the is* globals Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix delete-cluster-dialog tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix install-helm-chart-from-previously-opened-tab tests - Split out storage initialization to a runnable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary override of non side effect injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix disable-kube-object-detail-items-when-cluster-is-not-relevant tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix reactively-hide-kube-object-detail-item tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix sidebar-and-tab-navigation-for-core tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove need to override lensLocalStoragePath in tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Replace more overrides with global ones Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix typings Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove no longer needed technical test Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
900a8bbda3
commit
2b33d5eed6
530 files changed
+11320
-5399
No files matched your search
@@ -3,34 +3,33 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import fs from "fs";
|
||||
import mockFs from "mock-fs";
|
||||
import path from "path";
|
||||
import fse from "fs-extra";
|
||||
import type { ClusterStore } from "../cluster-store/cluster-store";
|
||||
import { Console } from "console";
|
||||
import { stdout, stderr } from "process";
|
||||
import getCustomKubeConfigDirectoryInjectable from "../app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable";
|
||||
import type { GetCustomKubeConfigFilePath } from "../app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable";
|
||||
import getCustomKubeConfigFilePathInjectable from "../app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable";
|
||||
import clusterStoreInjectable from "../cluster-store/cluster-store.injectable";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import type { CreateCluster } from "../cluster/create-cluster-injection-token";
|
||||
import { createClusterInjectionToken } from "../cluster/create-cluster-injection-token";
|
||||
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
||||
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
||||
import assert from "assert";
|
||||
import directoryForTempInjectable from "../app-paths/directory-for-temp/directory-for-temp.injectable";
|
||||
import kubectlBinaryNameInjectable from "../../main/kubectl/binary-name.injectable";
|
||||
import kubectlDownloadingNormalizedArchInjectable from "../../main/kubectl/normalized-arch.injectable";
|
||||
import normalizedPlatformInjectable from "../vars/normalized-platform.injectable";
|
||||
import fsInjectable from "../fs/fs.injectable";
|
||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
||||
import type { WriteJsonSync } from "../fs/write-json-sync.injectable";
|
||||
import writeJsonSyncInjectable from "../fs/write-json-sync.injectable";
|
||||
import type { ReadFileSync } from "../fs/read-file-sync.injectable";
|
||||
import readFileSyncInjectable from "../fs/read-file-sync.injectable";
|
||||
import { readFileSync } from "fs";
|
||||
import type { WriteFileSync } from "../fs/write-file-sync.injectable";
|
||||
import writeFileSyncInjectable from "../fs/write-file-sync.injectable";
|
||||
import type { WriteBufferSync } from "../fs/write-buffer-sync.injectable";
|
||||
import writeBufferSyncInjectable from "../fs/write-buffer-sync.injectable";
|
||||
|
||||
console = new Console(stdout, stderr);
|
||||
|
||||
const testDataIcon = fs.readFileSync(
|
||||
"test-data/cluster-store-migration-icon.png",
|
||||
);
|
||||
// NOTE: this is intended to read the actual file system
|
||||
const testDataIcon = readFileSync("test-data/cluster-store-migration-icon.png");
|
||||
const clusterServerUrl = "https://localhost";
|
||||
const kubeconfig = `
|
||||
apiVersion: v1
|
||||
@@ -56,75 +55,41 @@ users:
|
||||
token: kubeconfig-user-q4lm4:xxxyyyy
|
||||
`;
|
||||
|
||||
const embed = (directoryName: string, contents: any): string => {
|
||||
fse.ensureDirSync(path.dirname(directoryName));
|
||||
fse.writeFileSync(directoryName, contents, {
|
||||
encoding: "utf-8",
|
||||
mode: 0o600,
|
||||
});
|
||||
|
||||
return directoryName;
|
||||
};
|
||||
|
||||
jest.mock("electron", () => ({
|
||||
ipcMain: {
|
||||
handle: jest.fn(),
|
||||
on: jest.fn(),
|
||||
removeAllListeners: jest.fn(),
|
||||
off: jest.fn(),
|
||||
send: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe("cluster-store", () => {
|
||||
let mainDi: DiContainer;
|
||||
let di: DiContainer;
|
||||
let clusterStore: ClusterStore;
|
||||
let createCluster: CreateCluster;
|
||||
let writeJsonSync: WriteJsonSync;
|
||||
let writeFileSync: WriteFileSync;
|
||||
let writeBufferSync: WriteBufferSync;
|
||||
let readFileSync: ReadFileSync;
|
||||
let getCustomKubeConfigFilePath: GetCustomKubeConfigFilePath;
|
||||
let writeFileSyncAndReturnPath: (filePath: string, contents: string) => string;
|
||||
|
||||
beforeEach(async () => {
|
||||
mainDi = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
mockFs();
|
||||
|
||||
mainDi.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||
mainDi.override(directoryForTempInjectable, () => "some-temp-directory");
|
||||
mainDi.override(kubectlBinaryNameInjectable, () => "kubectl");
|
||||
mainDi.override(kubectlDownloadingNormalizedArchInjectable, () => "amd64");
|
||||
mainDi.override(normalizedPlatformInjectable, () => "darwin");
|
||||
|
||||
mainDi.permitSideEffects(getConfigurationFileModelInjectable);
|
||||
mainDi.unoverride(getConfigurationFileModelInjectable);
|
||||
|
||||
mainDi.permitSideEffects(fsInjectable);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
|
||||
di.override(directoryForTempInjectable, () => "/some-temp-directory");
|
||||
di.override(kubectlBinaryNameInjectable, () => "kubectl");
|
||||
di.override(kubectlDownloadingNormalizedArchInjectable, () => "amd64");
|
||||
di.override(normalizedPlatformInjectable, () => "darwin");
|
||||
createCluster = di.inject(createClusterInjectionToken);
|
||||
getCustomKubeConfigFilePath = di.inject(getCustomKubeConfigFilePathInjectable);
|
||||
writeJsonSync = di.inject(writeJsonSyncInjectable);
|
||||
writeFileSync = di.inject(writeFileSyncInjectable);
|
||||
writeBufferSync = di.inject(writeBufferSyncInjectable);
|
||||
readFileSync = di.inject(readFileSyncInjectable);
|
||||
writeFileSyncAndReturnPath = (filePath, contents) => (writeFileSync(filePath, contents), filePath);
|
||||
});
|
||||
|
||||
describe("empty config", () => {
|
||||
let getCustomKubeConfigDirectory: (directoryName: string) => string;
|
||||
|
||||
beforeEach(async () => {
|
||||
getCustomKubeConfigDirectory = mainDi.inject(getCustomKubeConfigDirectoryInjectable);
|
||||
|
||||
mockFs({
|
||||
"some-directory-for-user-data": {
|
||||
"lens-cluster-store.json": JSON.stringify({}),
|
||||
},
|
||||
});
|
||||
|
||||
createCluster = mainDi.inject(createClusterInjectionToken);
|
||||
|
||||
clusterStore = mainDi.inject(clusterStoreInjectable);
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/lens-cluster-store.json", {});
|
||||
clusterStore = di.inject(clusterStoreInjectable);
|
||||
clusterStore.load();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
describe("with foo cluster added", () => {
|
||||
beforeEach(() => {
|
||||
const cluster = createCluster({
|
||||
@@ -135,8 +100,8 @@ describe("cluster-store", () => {
|
||||
icon: "data:image/jpeg;base64, iVBORw0KGgoAAAANSUhEUgAAA1wAAAKoCAYAAABjkf5",
|
||||
clusterName: "minikube",
|
||||
},
|
||||
kubeConfigPath: embed(
|
||||
getCustomKubeConfigDirectory("foo"),
|
||||
kubeConfigPath: writeFileSyncAndReturnPath(
|
||||
getCustomKubeConfigFilePath("foo"),
|
||||
kubeconfig,
|
||||
),
|
||||
}, {
|
||||
@@ -169,8 +134,8 @@ describe("cluster-store", () => {
|
||||
preferences: {
|
||||
clusterName: "prod",
|
||||
},
|
||||
kubeConfigPath: embed(
|
||||
getCustomKubeConfigDirectory("prod"),
|
||||
kubeConfigPath: writeFileSyncAndReturnPath(
|
||||
getCustomKubeConfigFilePath("prod"),
|
||||
kubeconfig,
|
||||
),
|
||||
});
|
||||
@@ -180,8 +145,8 @@ describe("cluster-store", () => {
|
||||
preferences: {
|
||||
clusterName: "dev",
|
||||
},
|
||||
kubeConfigPath: embed(
|
||||
getCustomKubeConfigDirectory("dev"),
|
||||
kubeConfigPath: writeFileSyncAndReturnPath(
|
||||
getCustomKubeConfigFilePath("dev"),
|
||||
kubeconfig,
|
||||
),
|
||||
});
|
||||
@@ -193,61 +158,49 @@ describe("cluster-store", () => {
|
||||
});
|
||||
|
||||
it("check if cluster's kubeconfig file saved", () => {
|
||||
const file = embed(getCustomKubeConfigDirectory("boo"), "kubeconfig");
|
||||
const file = writeFileSyncAndReturnPath(getCustomKubeConfigFilePath("boo"), "kubeconfig");
|
||||
|
||||
expect(fs.readFileSync(file, "utf8")).toBe("kubeconfig");
|
||||
expect(readFileSync(file)).toBe("kubeconfig");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("config with existing clusters", () => {
|
||||
beforeEach(() => {
|
||||
mockFs({
|
||||
"temp-kube-config": kubeconfig,
|
||||
"some-directory-for-user-data": {
|
||||
"lens-cluster-store.json": JSON.stringify({
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "99.99.99",
|
||||
},
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: "cluster1",
|
||||
kubeConfigPath: "./temp-kube-config",
|
||||
contextName: "foo",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "default",
|
||||
},
|
||||
{
|
||||
id: "cluster2",
|
||||
kubeConfigPath: "./temp-kube-config",
|
||||
contextName: "foo2",
|
||||
preferences: { terminalCWD: "/foo2" },
|
||||
},
|
||||
{
|
||||
id: "cluster3",
|
||||
kubeConfigPath: "./temp-kube-config",
|
||||
contextName: "foo",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "foo",
|
||||
ownerRef: "foo",
|
||||
},
|
||||
],
|
||||
}),
|
||||
writeFileSync("/temp-kube-config", kubeconfig);
|
||||
writeJsonSync("/some-directory-for-user-data/lens-cluster-store.json", {
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "99.99.99",
|
||||
},
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: "cluster1",
|
||||
kubeConfigPath: "/temp-kube-config",
|
||||
contextName: "foo",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "default",
|
||||
},
|
||||
{
|
||||
id: "cluster2",
|
||||
kubeConfigPath: "/temp-kube-config",
|
||||
contextName: "foo2",
|
||||
preferences: { terminalCWD: "/foo2" },
|
||||
},
|
||||
{
|
||||
id: "cluster3",
|
||||
kubeConfigPath: "/temp-kube-config",
|
||||
contextName: "foo",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "foo",
|
||||
ownerRef: "foo",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
createCluster = mainDi.inject(createClusterInjectionToken);
|
||||
|
||||
clusterStore = mainDi.inject(clusterStoreInjectable);
|
||||
clusterStore = di.inject(clusterStoreInjectable);
|
||||
clusterStore.load();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
it("allows to retrieve a cluster", () => {
|
||||
const storedCluster = clusterStore.getById("cluster1");
|
||||
|
||||
@@ -271,66 +224,35 @@ describe("cluster-store", () => {
|
||||
|
||||
describe("config with invalid cluster kubeconfig", () => {
|
||||
beforeEach(() => {
|
||||
const invalidKubeconfig = `
|
||||
apiVersion: v1
|
||||
clusters:
|
||||
- cluster:
|
||||
server: https://localhost
|
||||
name: test2
|
||||
contexts:
|
||||
- context:
|
||||
cluster: test
|
||||
user: test
|
||||
name: test
|
||||
current-context: test
|
||||
kind: Config
|
||||
preferences: {}
|
||||
users:
|
||||
- name: test
|
||||
user:
|
||||
token: kubeconfig-user-q4lm4:xxxyyyy
|
||||
`;
|
||||
|
||||
mockFs({
|
||||
"invalid-kube-config": invalidKubeconfig,
|
||||
"valid-kube-config": kubeconfig,
|
||||
"some-directory-for-user-data": {
|
||||
"lens-cluster-store.json": JSON.stringify({
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "99.99.99",
|
||||
},
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: "cluster1",
|
||||
kubeConfigPath: "./invalid-kube-config",
|
||||
contextName: "test",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "foo",
|
||||
},
|
||||
{
|
||||
id: "cluster2",
|
||||
kubeConfigPath: "./valid-kube-config",
|
||||
contextName: "foo",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "default",
|
||||
},
|
||||
],
|
||||
}),
|
||||
writeFileSync("/invalid-kube-config", invalidKubeconfig);
|
||||
writeFileSync("/valid-kube-config", kubeconfig);
|
||||
writeJsonSync("/some-directory-for-user-data/lens-cluster-store.json", {
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "99.99.99",
|
||||
},
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: "cluster1",
|
||||
kubeConfigPath: "/invalid-kube-config",
|
||||
contextName: "test",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "foo",
|
||||
},
|
||||
{
|
||||
id: "cluster2",
|
||||
kubeConfigPath: "/valid-kube-config",
|
||||
contextName: "foo",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "default",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
createCluster = mainDi.inject(createClusterInjectionToken);
|
||||
|
||||
clusterStore = mainDi.inject(clusterStoreInjectable);
|
||||
clusterStore = di.inject(clusterStoreInjectable);
|
||||
clusterStore.load();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
it("does not enable clusters with invalid kubeconfig", () => {
|
||||
const storedClusters = clusterStore.clustersList;
|
||||
|
||||
@@ -340,56 +262,69 @@ users:
|
||||
|
||||
describe("pre 3.6.0-beta.1 config with an existing cluster", () => {
|
||||
beforeEach(() => {
|
||||
mockFs({
|
||||
"some-directory-for-user-data": {
|
||||
"lens-cluster-store.json": JSON.stringify({
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "3.5.0",
|
||||
},
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: "cluster1",
|
||||
kubeConfig: minimalValidKubeConfig,
|
||||
contextName: "cluster",
|
||||
preferences: {
|
||||
icon: "store://icon_path",
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
icon_path: testDataIcon,
|
||||
writeJsonSync("/some-directory-for-user-data/lens-cluster-store.json", {
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "3.5.0",
|
||||
},
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: "cluster1",
|
||||
kubeConfig: minimalValidKubeConfig,
|
||||
contextName: "cluster",
|
||||
preferences: {
|
||||
icon: "store://icon_path",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
writeBufferSync("/some-directory-for-user-data/icon_path", testDataIcon);
|
||||
|
||||
mainDi.override(storeMigrationVersionInjectable, () => "3.6.0");
|
||||
di.override(storeMigrationVersionInjectable, () => "3.6.0");
|
||||
|
||||
createCluster = mainDi.inject(createClusterInjectionToken);
|
||||
|
||||
clusterStore = mainDi.inject(clusterStoreInjectable);
|
||||
clusterStore = di.inject(clusterStoreInjectable);
|
||||
clusterStore.load();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
it("migrates to modern format with kubeconfig in a file", async () => {
|
||||
const config = clusterStore.clustersList[0].kubeConfigPath;
|
||||
|
||||
expect(fs.readFileSync(config, "utf8")).toBe(minimalValidKubeConfig);
|
||||
expect(readFileSync(config)).toBe(minimalValidKubeConfig);
|
||||
});
|
||||
|
||||
it("migrates to modern format with icon not in file", async () => {
|
||||
const { icon } = clusterStore.clustersList[0].preferences;
|
||||
|
||||
assert(icon);
|
||||
expect(icon.startsWith("data:;base64,")).toBe(true);
|
||||
expect(clusterStore.clustersList[0].preferences.icon).toMatch(/data:;base64,/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const invalidKubeconfig = JSON.stringify({
|
||||
apiVersion: "v1",
|
||||
clusters: [{
|
||||
cluster: {
|
||||
server: "https://localhost",
|
||||
},
|
||||
name: "test2",
|
||||
}],
|
||||
contexts: [{
|
||||
context: {
|
||||
cluster: "test",
|
||||
user: "test",
|
||||
},
|
||||
name: "test",
|
||||
}],
|
||||
"current-context": "test",
|
||||
kind: "Config",
|
||||
preferences: {},
|
||||
users: [{
|
||||
user: {
|
||||
token: "kubeconfig-user-q4lm4:xxxyyyy",
|
||||
},
|
||||
name: "test",
|
||||
}],
|
||||
});
|
||||
|
||||
const minimalValidKubeConfig = JSON.stringify({
|
||||
apiVersion: "v1",
|
||||
clusters: [
|
||||
|
||||
@@ -4,10 +4,8 @@
|
||||
*/
|
||||
|
||||
import { anyObject } from "jest-mock-extended";
|
||||
import mockFs from "mock-fs";
|
||||
import type { CatalogEntity, CatalogEntityData, CatalogEntityKindData } from "../catalog";
|
||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
||||
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import hotbarStoreInjectable from "../hotbars/store.injectable";
|
||||
import type { HotbarStore } from "../hotbars/store";
|
||||
@@ -19,7 +17,7 @@ import loggerInjectable from "../logger.injectable";
|
||||
import type { Logger } from "../logger";
|
||||
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
||||
import fsInjectable from "../fs/fs.injectable";
|
||||
import writeJsonSyncInjectable from "../fs/write-json-sync.injectable";
|
||||
|
||||
function getMockCatalogEntity(data: Partial<CatalogEntityData> & CatalogEntityKindData): CatalogEntity {
|
||||
return {
|
||||
@@ -47,8 +45,6 @@ describe("HotbarStore", () => {
|
||||
beforeEach(async () => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
di.unoverride(hotbarStoreInjectable);
|
||||
|
||||
testCluster = getMockCatalogEntity({
|
||||
apiVersion: "v1",
|
||||
kind: "Cluster",
|
||||
@@ -101,7 +97,7 @@ describe("HotbarStore", () => {
|
||||
|
||||
di.override(loggerInjectable, () => loggerMock);
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
|
||||
|
||||
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
|
||||
const catalogCatalogEntity = di.inject(catalogCatalogEntityInjectable);
|
||||
@@ -112,20 +108,10 @@ describe("HotbarStore", () => {
|
||||
awsCluster,
|
||||
catalogCatalogEntity,
|
||||
]));
|
||||
|
||||
di.permitSideEffects(fsInjectable);
|
||||
di.permitSideEffects(getConfigurationFileModelInjectable);
|
||||
di.unoverride(getConfigurationFileModelInjectable);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
describe("given no previous data in store, running all migrations", () => {
|
||||
beforeEach(() => {
|
||||
mockFs();
|
||||
|
||||
hotbarStore = di.inject(hotbarStoreInjectable);
|
||||
|
||||
hotbarStore.load();
|
||||
@@ -276,66 +262,64 @@ describe("HotbarStore", () => {
|
||||
|
||||
describe("given data from 5.0.0-beta.3 and version being 5.0.0-beta.10", () => {
|
||||
beforeEach(() => {
|
||||
mockFs({
|
||||
"some-directory-for-user-data": {
|
||||
"lens-hotbar-store.json": JSON.stringify({
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "5.0.0-beta.3",
|
||||
},
|
||||
},
|
||||
hotbars: [
|
||||
{
|
||||
id: "3caac17f-aec2-4723-9694-ad204465d935",
|
||||
name: "myhotbar",
|
||||
items: [
|
||||
{
|
||||
entity: {
|
||||
uid: "some-aws-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "55b42c3c7ba3b04193416cda405269a5",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "176fd331968660832f62283219d7eb6e",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "61c4fb45528840ebad1badc25da41d14",
|
||||
name: "user1-context",
|
||||
source: "local",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "27d6f99fe9e7548a6e306760bfe19969",
|
||||
name: "foo2",
|
||||
source: "local",
|
||||
},
|
||||
},
|
||||
null,
|
||||
{
|
||||
entity: {
|
||||
uid: "c0b20040646849bb4dcf773e43a0bf27",
|
||||
name: "multinode-demo",
|
||||
source: "local",
|
||||
},
|
||||
},
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
},
|
||||
],
|
||||
}),
|
||||
const writeJsonSync = di.inject(writeJsonSyncInjectable);
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/lens-hotbar-store.json", {
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "5.0.0-beta.3",
|
||||
},
|
||||
},
|
||||
hotbars: [
|
||||
{
|
||||
id: "3caac17f-aec2-4723-9694-ad204465d935",
|
||||
name: "myhotbar",
|
||||
items: [
|
||||
{
|
||||
entity: {
|
||||
uid: "some-aws-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "55b42c3c7ba3b04193416cda405269a5",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "176fd331968660832f62283219d7eb6e",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "61c4fb45528840ebad1badc25da41d14",
|
||||
name: "user1-context",
|
||||
source: "local",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "27d6f99fe9e7548a6e306760bfe19969",
|
||||
name: "foo2",
|
||||
source: "local",
|
||||
},
|
||||
},
|
||||
null,
|
||||
{
|
||||
entity: {
|
||||
uid: "c0b20040646849bb4dcf773e43a0bf27",
|
||||
name: "multinode-demo",
|
||||
source: "local",
|
||||
},
|
||||
},
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
di.override(storeMigrationVersionInjectable, () => "5.0.0-beta.10");
|
||||
|
||||
@@ -2,28 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import mockFs from "mock-fs";
|
||||
|
||||
jest.mock("electron", () => ({
|
||||
app: {
|
||||
getVersion: () => "99.99.99",
|
||||
getName: () => "lens",
|
||||
setName: jest.fn(),
|
||||
setPath: jest.fn(),
|
||||
getPath: () => "tmp",
|
||||
getLocale: () => "en",
|
||||
setLoginItemSettings: jest.fn(),
|
||||
},
|
||||
ipcMain: {
|
||||
on: jest.fn(),
|
||||
handle: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
import type { UserStore } from "../user-store";
|
||||
import { Console } from "console";
|
||||
import { stdout, stderr } from "process";
|
||||
import userStoreInjectable from "../user-store/user-store.injectable";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
@@ -31,13 +10,11 @@ import type { ClusterStoreModel } from "../cluster-store/cluster-store";
|
||||
import { defaultThemeId } from "../vars";
|
||||
import writeFileInjectable from "../fs/write-file.injectable";
|
||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
||||
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
||||
import releaseChannelInjectable from "../vars/release-channel.injectable";
|
||||
import defaultUpdateChannelInjectable from "../../features/application-update/common/selected-update-channel/default-update-channel.injectable";
|
||||
import fsInjectable from "../fs/fs.injectable";
|
||||
|
||||
console = new Console(stdout, stderr);
|
||||
import writeJsonSyncInjectable from "../fs/write-json-sync.injectable";
|
||||
import writeFileSyncInjectable from "../fs/write-file-sync.injectable";
|
||||
|
||||
describe("user store tests", () => {
|
||||
let userStore: UserStore;
|
||||
@@ -46,14 +23,8 @@ describe("user store tests", () => {
|
||||
beforeEach(async () => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
mockFs();
|
||||
|
||||
di.override(writeFileInjectable, () => () => Promise.resolve());
|
||||
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||
|
||||
di.permitSideEffects(getConfigurationFileModelInjectable);
|
||||
di.unoverride(getConfigurationFileModelInjectable);
|
||||
di.permitSideEffects(fsInjectable);
|
||||
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
|
||||
|
||||
di.override(releaseChannelInjectable, () => ({
|
||||
get: () => "latest" as const,
|
||||
@@ -64,13 +35,12 @@ describe("user store tests", () => {
|
||||
userStore = di.inject(userStoreInjectable);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
describe("for an empty config", () => {
|
||||
beforeEach(() => {
|
||||
mockFs({ "some-directory-for-user-data": { "lens-user-store.json": "{}", "kube_config": "{}" }});
|
||||
const writeJsonSync = di.inject(writeJsonSyncInjectable);
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/lens-user-store.json", {});
|
||||
writeJsonSync("/some-directory-for-user-data/kube_config", {});
|
||||
|
||||
userStore.load();
|
||||
});
|
||||
@@ -94,40 +64,38 @@ describe("user store tests", () => {
|
||||
|
||||
describe("migrations", () => {
|
||||
beforeEach(() => {
|
||||
mockFs({
|
||||
"some-directory-for-user-data": {
|
||||
"lens-user-store.json": JSON.stringify({
|
||||
preferences: { colorTheme: "light" },
|
||||
}),
|
||||
"lens-cluster-store.json": JSON.stringify({
|
||||
clusters: [
|
||||
{
|
||||
id: "foobar",
|
||||
kubeConfigPath: "some-directory-for-user-data/extension_data/foo/bar",
|
||||
},
|
||||
{
|
||||
id: "barfoo",
|
||||
kubeConfigPath: "some/other/path",
|
||||
},
|
||||
],
|
||||
} as ClusterStoreModel),
|
||||
"extension_data": {},
|
||||
},
|
||||
"some": {
|
||||
"other": {
|
||||
"path": "is file",
|
||||
},
|
||||
},
|
||||
const writeJsonSync = di.inject(writeJsonSyncInjectable);
|
||||
const writeFileSync = di.inject(writeFileSyncInjectable);
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/lens-user-store.json", {
|
||||
preferences: { colorTheme: "light" },
|
||||
});
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/lens-cluster-store.json", {
|
||||
clusters: [
|
||||
{
|
||||
id: "foobar",
|
||||
kubeConfigPath: "/some-directory-for-user-data/extension_data/foo/bar",
|
||||
},
|
||||
{
|
||||
id: "barfoo",
|
||||
kubeConfigPath: "/some/other/path",
|
||||
},
|
||||
],
|
||||
} as ClusterStoreModel);
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/extension_data", {});
|
||||
|
||||
writeFileSync("/some/other/path", "is file");
|
||||
|
||||
di.override(storeMigrationVersionInjectable, () => "10.0.0");
|
||||
|
||||
userStore.load();
|
||||
});
|
||||
|
||||
it("skips clusters for adding to kube-sync with files under extension_data/", () => {
|
||||
expect(userStore.syncKubeconfigEntries.has("some-directory-for-user-data/extension_data/foo/bar")).toBe(false);
|
||||
expect(userStore.syncKubeconfigEntries.has("some/other/path")).toBe(true);
|
||||
expect(userStore.syncKubeconfigEntries.has("/some-directory-for-user-data/extension_data/foo/bar")).toBe(false);
|
||||
expect(userStore.syncKubeconfigEntries.has("/some/other/path")).toBe(true);
|
||||
});
|
||||
|
||||
it("allows access to the colorTheme preference", () => {
|
||||
|
||||
Reference in new issue
Block a user