1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/main/shell-session/local-shell-session/techincal.test.ts
Sebastian Malton 40c81d74f3
Release 6.1.12 (#6408)
* Release 6.1.12

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

* Adding asc provider (#6302)

* Fix windows shell not having all environment variables (#6402)

* Fix windows shell not having all environment variables

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

* Fix startup due to buildVersion dependency

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

* Call cleanup in computeShellEnvironment

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

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

* Fix lint

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

* Fix lints

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

* Fix build issue

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

* Fix test invocation

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

Signed-off-by: Sebastian Malton <sebastian@malton.name>
Co-authored-by: Billy Tobon <billy.tobon@gmail.com>
2022-10-13 09:56:49 -04:00

91 lines
3.1 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DiContainer } from "@ogre-tools/injectable";
import { WebSocket } from "ws";
import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
import type { Cluster } from "../../../common/cluster/cluster";
import resolvedShellInjectable from "../../../common/user-store/resolved-shell.injectable";
import platformInjectable from "../../../common/vars/platform.injectable";
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
import createKubectlInjectable from "../../kubectl/create-kubectl.injectable";
import type { Kubectl } from "../../kubectl/kubectl";
import buildVersionInjectable from "../../vars/build-version/build-version.injectable";
import type { SpawnPty } from "../spawn-pty.injectable";
import spawnPtyInjectable from "../spawn-pty.injectable";
import localShellSessionInjectable from "./local-shell-session.injectable";
describe("technical unit tests for local shell sessions", () => {
let di: DiContainer;
beforeEach(() => {
di = getDiForUnitTesting({
doGeneralOverrides: true,
});
di.override(resolvedShellInjectable, () => "powershell.exe");
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
di.override(buildVersionInjectable, () => ({
get: () => "1.1.1",
}));
});
describe("when on windows", () => {
let spawnPtyMock: jest.MockedFunction<SpawnPty>;
beforeEach(() => {
di.override(platformInjectable, () => "win32");
spawnPtyMock = jest.fn();
di.override(spawnPtyInjectable, () => spawnPtyMock);
di.override(createKubectlInjectable, () => () => ({
binDir: async () => "/some-kubectl-binary-dir",
getBundledPath: () => "/some-bundled-kubectl-path",
}) as Partial<Kubectl> as Kubectl);
});
describe("when opening a local shell session", () => {
it("should pass through all environment variables to shell", async () => {
process.env.MY_TEST_ENV_VAR = "true";
spawnPtyMock.mockImplementationOnce((file, args, options) => {
expect(options.env).toMatchObject({
MY_TEST_ENV_VAR: "true",
});
return {
cols: 80,
rows: 40,
pid: 12343,
handleFlowControl: false,
kill: jest.fn(),
onData: jest.fn(),
onExit: jest.fn(),
pause: jest.fn(),
process: "my-pty",
resize: jest.fn(),
resume: jest.fn(),
write: jest.fn(),
on: jest.fn(),
};
});
const session = di.inject(localShellSessionInjectable, {
cluster: {
getProxyKubeconfigPath: async () => "/some-proxy-kubeconfig",
preferences: {},
} as Partial<Cluster> as Cluster,
tabId: "my-tab-id",
websocket: new WebSocket(null),
});
await session.open();
});
});
});
});