1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix unit tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-07-06 16:35:06 -04:00
parent cedf82b1c2
commit c79bdbb42e
4 changed files with 40 additions and 58 deletions

View File

@ -1,25 +0,0 @@
{
"name": "kube-object-event-status",
"version": "0.1.0",
"description": "Adds kube object status from events",
"renderer": "dist/renderer.js",
"lens": {
"metadata": {},
"styles": []
},
"scripts": {
"build": "webpack && npm pack",
"dev": "webpack --watch",
"test": "echo NO TESTS"
},
"files": [
"dist/**/*"
],
"dependencies": {},
"devDependencies": {
"@k8slens/extensions": "file:../../src/extensions/npm/extensions",
"ts-loader": "^8.0.4",
"typescript": "^4.0.3",
"webpack": "^4.44.2"
}
}

View File

@ -148,8 +148,8 @@ export default {
store.set("hotbars", hotbars);
} catch (error) {
if (!(error.code === "ENOENT" && error.path.endsWith("lens-workspace-store.json"))) {
// ignore lens-workspace-store.json being missing
if (error.code !== "ENOENT") {
// ignore files being missing
throw error;
}
}

View File

@ -30,37 +30,46 @@ import { MigrationDeclaration, migrationLog } from "../helpers";
export default {
version: "5.0.3-beta.1",
run(store) {
const { syncKubeconfigEntries = [], ...preferences }: UserPreferencesModel = store.get("preferences") ?? {};
const { clusters = [] }: ClusterStoreModel = readJsonSync(path.resolve(app.getPath("userData"), "lens-cluster-store.json"));
const syncPaths = new Set(syncKubeconfigEntries.map(s => s.filePath));
try {
const { syncKubeconfigEntries = [], ...preferences }: UserPreferencesModel = store.get("preferences") ?? {};
const { clusters = [] }: ClusterStoreModel = readJsonSync(path.resolve(app.getPath("userData"), "lens-cluster-store.json")) ?? {};
const syncPaths = new Set(syncKubeconfigEntries.map(s => s.filePath));
syncPaths.add(path.join(os.homedir(), ".kube"));
syncPaths.add(path.join(os.homedir(), ".kube"));
for (const cluster of clusters) {
const dirOfKubeconfig = path.dirname(cluster.kubeConfigPath);
for (const cluster of clusters) {
const dirOfKubeconfig = path.dirname(cluster.kubeConfigPath);
if (dirOfKubeconfig === ClusterStore.storedKubeConfigFolder) {
migrationLog(`Skipping ${cluster.id} because kubeConfigPath is under ClusterStore.storedKubeConfigFolder`);
continue;
if (dirOfKubeconfig === ClusterStore.storedKubeConfigFolder) {
migrationLog(`Skipping ${cluster.id} because kubeConfigPath is under ClusterStore.storedKubeConfigFolder`);
continue;
}
if (syncPaths.has(cluster.kubeConfigPath) || syncPaths.has(dirOfKubeconfig)) {
migrationLog(`Skipping ${cluster.id} because kubeConfigPath is already being synced`);
continue;
}
if (!existsSync(cluster.kubeConfigPath)) {
migrationLog(`Skipping ${cluster.id} because kubeConfigPath no longer exists`);
continue;
}
migrationLog(`Adding ${cluster.kubeConfigPath} from ${cluster.id} to sync paths`);
syncPaths.add(cluster.kubeConfigPath);
}
if (syncPaths.has(cluster.kubeConfigPath) || syncPaths.has(dirOfKubeconfig)) {
migrationLog(`Skipping ${cluster.id} because kubeConfigPath is already being synced`);
continue;
}
const updatedSyncEntries: KubeconfigSyncEntry[] = [...syncPaths].map(filePath => ({ filePath }));
if (!existsSync(cluster.kubeConfigPath)) {
migrationLog(`Skipping ${cluster.id} because kubeConfigPath no longer exists`);
continue;
}
migrationLog("Final list of synced paths", updatedSyncEntries);
store.set("preferences", { ...preferences, syncKubeconfigEntries: updatedSyncEntries });
} catch (error) {
console.log(error);
migrationLog(`Adding ${cluster.kubeConfigPath} from ${cluster.id} to sync paths`);
syncPaths.add(cluster.kubeConfigPath);
if (error.code !== "ENOENT") {
// ignore files being missing
throw error;
}
}
const updatedSyncEntries: KubeconfigSyncEntry[] = [...syncPaths].map(filePath => ({ filePath }));
migrationLog("Final list of synced paths", updatedSyncEntries);
store.set("preferences", { ...preferences, syncKubeconfigEntries: updatedSyncEntries });
},
} as MigrationDeclaration;

View File

@ -59,14 +59,7 @@ describe("Extensions", () => {
});
ExtensionInstallationStateStore.reset();
UserStore.resetInstance();
UserStore.createInstance();
ExtensionDiscovery.resetInstance();
ExtensionDiscovery.createInstance().uninstallExtension = jest.fn(() => Promise.resolve());
ExtensionLoader.resetInstance();
ExtensionLoader.createInstance().addExtension({
id: "extensionId",
manifest: {
@ -79,10 +72,15 @@ describe("Extensions", () => {
isEnabled: true,
isCompatible: true
});
ExtensionDiscovery.createInstance().uninstallExtension = jest.fn(() => Promise.resolve());
UserStore.createInstance();
});
afterEach(() => {
mockFs.restore();
UserStore.resetInstance();
ExtensionDiscovery.resetInstance();
ExtensionLoader.resetInstance();
});
it("disables uninstall and disable buttons while uninstalling", async () => {