Fix cluster frame display issue (#5518)

* Fix cluster frame display issue

- Add some defensive code to prevent this sort of infinite loop

- Add some unit tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix unit tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix build

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix lint

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Factor out injectable for getting of cluster config data

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-06-20 22:23:15 -04:00
1 parent 8c31e56462
commit de43df1cca
40 files changed
+2126 -815

No files matched your search

+5 -34
View File
@@ -8,11 +8,10 @@ jest.mock("request");
jest.mock("request-promise-native");
import { Console } from "console";
import mockFs from "mock-fs";
import type { Cluster } from "../../common/cluster/cluster";
import { Kubectl } from "../kubectl/kubectl";
import { getDiForUnitTesting } from "../getDiForUnitTesting";
import type { ClusterModel } from "../../common/cluster-types";
import type { CreateCluster } from "../../common/cluster/create-cluster-injection-token";
import { createClusterInjectionToken } from "../../common/cluster/create-cluster-injection-token";
import authorizationReviewInjectable from "../../common/cluster/authorization-review.injectable";
import listNamespacesInjectable from "../../common/cluster/list-namespaces.injectable";
@@ -29,36 +28,13 @@ console = new Console(process.stdout, process.stderr); // fix mockFS
describe("create clusters", () => {
let cluster: Cluster;
let createCluster: (model: ClusterModel) => Cluster;
let createCluster: CreateCluster;
beforeEach(() => {
jest.clearAllMocks();
const di = getDiForUnitTesting({ doGeneralOverrides: true });
mockFs({
"minikube-config.yml": JSON.stringify({
apiVersion: "v1",
clusters: [{
name: "minikube",
cluster: {
server: "https://192.168.64.3:8443",
},
}],
contexts: [{
context: {
cluster: "minikube",
user: "minikube",
},
name: "minikube",
}],
users: [{
name: "minikube",
}],
kind: "Config",
preferences: {},
}),
});
const clusterServerUrl = "https://192.168.64.3:8443";
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
di.override(directoryForTempInjectable, () => "some-directory-for-temp");
@@ -87,12 +63,13 @@ describe("create clusters", () => {
id: "foo",
contextName: "minikube",
kubeConfigPath: "minikube-config.yml",
}, {
clusterServerUrl,
});
});
afterEach(() => {
cluster.disconnect();
mockFs.restore();
});
it("should be able to create a cluster from a cluster model and apiURL should be decoded", () => {
@@ -108,12 +85,6 @@ describe("create clusters", () => {
});
it("activating cluster should try to connect to cluster and do a refresh", async () => {
const cluster = createCluster({
id: "foo",
contextName: "minikube",
kubeConfigPath: "minikube-config.yml",
});
jest.spyOn(cluster, "reconnect");
jest.spyOn(cluster, "refreshConnectionStatus");
+8 -4
View File
@@ -3,8 +3,6 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { ClusterModel } from "../../common/cluster-types";
jest.mock("winston", () => ({
format: {
colorize: jest.fn(),
@@ -51,6 +49,7 @@ import { stdout, stderr } from "process";
import mockFs from "mock-fs";
import { getDiForUnitTesting } from "../getDiForUnitTesting";
import createKubeAuthProxyInjectable from "../kube-auth-proxy/create-kube-auth-proxy.injectable";
import type { CreateCluster } from "../../common/cluster/create-cluster-injection-token";
import { createClusterInjectionToken } from "../../common/cluster/create-cluster-injection-token";
import path from "path";
import spawnInjectable from "../child-process/spawn.injectable";
@@ -67,9 +66,10 @@ console = new Console(stdout, stderr);
const mockBroadcastIpc = broadcastMessage as jest.MockedFunction<typeof broadcastMessage>;
const mockSpawn = spawn as jest.MockedFunction<typeof spawn>;
const mockWaitUntilUsed = waitUntilUsed as jest.MockedFunction<typeof waitUntilUsed>;
const clusterServerUrl = "https://192.168.64.3:8443";
describe("kube auth proxy tests", () => {
let createCluster: (model: ClusterModel) => Cluster;
let createCluster: CreateCluster;
let createKubeAuthProxy: (cluster: Cluster, environmentVariables: NodeJS.ProcessEnv) => KubeAuthProxy;
beforeEach(async () => {
@@ -81,7 +81,7 @@ describe("kube auth proxy tests", () => {
clusters: [{
name: "minikube",
cluster: {
server: "https://192.168.64.3:8443",
server: clusterServerUrl,
},
}],
"current-context": "minikube",
@@ -130,6 +130,8 @@ describe("kube auth proxy tests", () => {
id: "foobar",
kubeConfigPath: "minikube-config.yml",
contextName: "minikube",
}, {
clusterServerUrl,
});
const kap = createKubeAuthProxy(cluster, {});
@@ -222,6 +224,8 @@ describe("kube auth proxy tests", () => {
id: "foobar",
kubeConfigPath: "minikube-config.yml",
contextName: "minikube",
}, {
clusterServerUrl,
});
proxy = createKubeAuthProxy(cluster, {});
+5 -1
View File
@@ -26,6 +26,8 @@ import kubectlDownloadingNormalizedArchInjectable from "../kubectl/normalized-ar
console = new Console(process.stdout, process.stderr); // fix mockFS
const clusterServerUrl = "https://192.168.64.3:8443";
describe("kubeconfig manager tests", () => {
let clusterFake: Cluster;
let createKubeconfigManager: (cluster: Cluster) => KubeconfigManager | undefined;
@@ -57,7 +59,7 @@ describe("kubeconfig manager tests", () => {
clusters: [{
name: "minikube",
cluster: {
server: "https://192.168.64.3:8443",
server: clusterServerUrl,
},
}],
contexts: [{
@@ -95,6 +97,8 @@ describe("kubeconfig manager tests", () => {
id: "foo",
contextName: "minikube",
kubeConfigPath: "minikube-config.yml",
}, {
clusterServerUrl,
});
jest.spyOn(KubeconfigManager.prototype, "resolveProxyUrl", "get").mockReturnValue("http://127.0.0.1:9191/foo");