Introduce way for execute file

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen committed 2022-06-09 14:37:44 +03:00
1 parent 2b5d54e8d9
commit 0ba16a81de
2 files changed
+29

No files matched your search

+23
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;
+6
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,