diff --git a/src/common/__tests__/kube-helpers.test.ts b/src/common/__tests__/kube-helpers.test.ts index b4e6f8dedd..94a2cae10c 100644 --- a/src/common/__tests__/kube-helpers.test.ts +++ b/src/common/__tests__/kube-helpers.test.ts @@ -1,7 +1,7 @@ import { KubeConfig } from "@kubernetes/client-node"; import { validateKubeConfig } from "../kube-helpers"; -const validKubeconfig = ` +const kubeconfig = ` apiVersion: v1 clusters: - cluster: @@ -38,48 +38,38 @@ users: command: foo `; +const kc = new KubeConfig(); + describe("validateKubeconfig", () => { + beforeAll(() => { + kc.loadFromString(kubeconfig); + }); describe("with default validation options", () => { describe("with valid kubeconfig", () => { it("does not raise exceptions", () => { - const kc = new KubeConfig(); - - kc.loadFromString(validKubeconfig); expect(() => { validateKubeConfig(kc, "valid");}).not.toThrow(); }); }); describe("with invalid context object", () => { it("it raises exception", () => { - const kc = new KubeConfig(); - - kc.loadFromString(validKubeconfig); expect(() => { validateKubeConfig(kc, "invalid");}).toThrow("No valid context object provided in kubeconfig for context 'invalid'"); }); }); describe("with invalid cluster object", () => { it("it raises exception", () => { - const kc = new KubeConfig(); - - kc.loadFromString(validKubeconfig); expect(() => { validateKubeConfig(kc, "invalidCluster");}).toThrow("No valid cluster object provided in kubeconfig for context 'invalidCluster'"); }); }); describe("with invalid user object", () => { it("it raises exception", () => { - const kc = new KubeConfig(); - - kc.loadFromString(validKubeconfig); expect(() => { validateKubeConfig(kc, "invalidUser");}).toThrow("No valid user object provided in kubeconfig for context 'invalidUser'"); }); }); describe("with invalid exec command", () => { it("it raises exception", () => { - const kc = new KubeConfig(); - - kc.loadFromString(validKubeconfig); expect(() => { validateKubeConfig(kc, "invalidExec");}).toThrow("User Exec command \"foo\" not found on host. Please ensure binary is found in PATH or use absolute path to binary in Kubeconfig"); }); }); @@ -88,9 +78,6 @@ describe("validateKubeconfig", () => { describe("with validateCluster as false", () => { describe("with invalid cluster object", () => { it("does not raise exception", () => { - const kc = new KubeConfig(); - - kc.loadFromString(validKubeconfig); expect(() => { validateKubeConfig(kc, "invalidCluster", { validateCluster: false });}).not.toThrow(); }); }); @@ -99,9 +86,6 @@ describe("validateKubeconfig", () => { describe("with validateUser as false", () => { describe("with invalid user object", () => { it("does not raise excpetions", () => { - const kc = new KubeConfig(); - - kc.loadFromString(validKubeconfig); expect(() => { validateKubeConfig(kc, "invalidUser", { validateUser: false });}).not.toThrow(); }); }); @@ -110,9 +94,6 @@ describe("validateKubeconfig", () => { describe("with validateExec as false", () => { describe("with invalid exec object", () => { it("does not raise excpetions", () => { - const kc = new KubeConfig(); - - kc.loadFromString(validKubeconfig); expect(() => { validateKubeConfig(kc, "invalidExec", { validateExec: false });}).not.toThrow(); }); });