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

Introduce way for execute file

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-02-14 16:04:58 +02:00
parent 2b5d54e8d9
commit 0ba16a81de
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,23 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { execFile } from "child_process";
export type ExecFile = (filePath: string, args: string[]) => Promise<string>;
const execFileInjectable = getInjectable({
id: "exec-file",
instantiate: (): ExecFile => async (filePath, args) =>
new Promise((resolve) => {
execFile(filePath, args, (error, stdout) => {
resolve(stdout);
});
}),
causesSideEffects: true,
});
export default execFileInjectable;

View File

@ -84,6 +84,7 @@ import startKubeConfigSyncInjectable from "./start-main-application/runnables/ku
import appVersionInjectable from "../common/get-configuration-file-model/app-version/app-version.injectable";
import getRandomIdInjectable from "../common/utils/get-random-id.injectable";
import periodicalCheckForUpdatesInjectable from "./application-update/periodical-check-for-updates/periodical-check-for-updates.injectable";
import execFileInjectable from "../common/fs/exec-file.injectable";
export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) {
const {
@ -162,6 +163,11 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
throw new Error("Tried to read file from file system without specifying explicit override.");
});
di.override(execFileInjectable, () => () => {
throw new Error("Tried to exec file from file system without specifying explicit override.");
});
di.override(loggerInjectable, () => ({
warn: noop,
debug: noop,