fix unit tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2021-05-17 11:11:06 -04:00
1 parent f9bf2a1864
commit 3a0e4bf20d
9 files changed
+53 -3

No files matched your search

@@ -23,6 +23,12 @@ import { SearchStore } from "../search-store";
import { Console } from "console";
import { stdout, stderr } from "process";
jest.mock("electron", () => ({
app: {
getPath: () => "/foo",
},
}));
console = new Console(stdout, stderr);
let searchStore: SearchStore = null;
@@ -44,6 +44,12 @@ jest.mock("winston", () => ({
}
}));
jest.mock("electron", () => ({
app: {
getPath: () => "/foo",
},
}));
jest.mock("../../common/ipc");
jest.mock("child_process");
jest.mock("tcp-port-used");
+10 -2
View File
@@ -28,6 +28,12 @@ const logger = {
crit: jest.fn(),
};
jest.mock("electron", () => ({
app: {
getPath: () => `/tmp`,
},
}));
jest.mock("winston", () => ({
format: {
colorize: jest.fn(),
@@ -91,7 +97,9 @@ describe("kubeconfig manager tests", () => {
contextName: "minikube",
kubeConfigPath: "minikube-config.yml",
});
contextHandler = jest.fn() as any;
contextHandler = {
ensureServer: () => Promise.resolve(),
} as any;
jest.spyOn(KubeconfigManager.prototype, "resolveProxyUrl", "get").mockReturnValue("http://127.0.0.1:9191/foo");
});
@@ -103,7 +111,7 @@ describe("kubeconfig manager tests", () => {
const kubeConfManager = new KubeconfigManager(cluster, contextHandler);
expect(logger.error).not.toBeCalled();
expect(await kubeConfManager.getPath()).toBe(`tmp${path.sep}kubeconfig-foo`);
expect(await kubeConfManager.getPath()).toBe(`${path.sep}tmp${path.sep}kubeconfig-foo`);
// this causes an intermittent "ENXIO: no such device or address, read" error
// const file = await fse.readFile(await kubeConfManager.getPath());
const file = fse.readFileSync(await kubeConfManager.getPath());
+2 -1
View File
@@ -71,6 +71,7 @@ export class KubeconfigManager {
await this.contextHandler.ensureServer();
this.tempFile = await this.createProxyKubeconfig();
} catch (err) {
console.log(err);
logger.error(`Failed to created temp config for auth-proxy`, { err });
}
}
@@ -86,7 +87,7 @@ export class KubeconfigManager {
protected async createProxyKubeconfig(): Promise<string> {
const { configDir, cluster } = this;
const { contextName, kubeConfigPath, id } = cluster;
const tempFile = path.join(configDir, `kubeconfig-${id}`);
const tempFile = path.normalize(path.join(configDir, `kubeconfig-${id}`));
const kubeConfig = loadConfig(kubeConfigPath);
const proxyConfig: Partial<KubeConfig> = {
currentContext: contextName,
@@ -25,6 +25,12 @@ import { fireEvent, render } from "@testing-library/react";
import type { IToleration } from "../../../api/workload-kube-object";
import { PodTolerations } from "../pod-tolerations";
jest.mock("electron", () => ({
app: {
getPath: () => "/foo",
},
}));
const tolerations: IToleration[] =[
{
key: "CriticalAddonsOnly",
@@ -23,6 +23,12 @@ import React from "react";
import { render } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
jest.mock("electron", () => ({
app: {
getPath: () => "/foo",
},
}));
import { BottomBar } from "./bottom-bar";
jest.mock("../../../extensions/registries");
import { statusBarRegistry } from "../../../extensions/registries";
@@ -26,6 +26,12 @@ import "@testing-library/jest-dom/extend-expect";
import { DockTabs } from "../dock-tabs";
import { dockStore, IDockTab, TabKind } from "../dock.store";
jest.mock("electron", () => ({
app: {
getPath: () => "/foo",
},
}));
const onChangeTab = jest.fn();
const getComponent = () => (
@@ -31,6 +31,12 @@ import { dockerPod, deploymentPod1 } from "./pod.mock";
import { ThemeStore } from "../../../theme.store";
import { UserStore } from "../../../../common/user-store";
jest.mock("electron", () => ({
app: {
getPath: () => "/foo",
},
}));
const getComponent = (tabData: LogTabData) => {
return (
<LogResourceSelector
@@ -25,6 +25,11 @@ import { dockStore } from "../dock.store";
import { logTabStore } from "../log-tab.store";
import { deploymentPod1, deploymentPod2, deploymentPod3, dockerPod } from "./pod.mock";
jest.mock("electron", () => ({
app: {
getPath: () => "/foo",
},
}));
podsStore.items.push(new Pod(dockerPod));
podsStore.items.push(new Pod(deploymentPod1));