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

Refactor validateKubeconfig unit tests

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2021-01-15 11:42:56 +02:00
parent 7c8ca4085a
commit 1b963b4473

View File

@ -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();
});
});