mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Convert runMany and runManySync to use injectManyWithMeta + move to seperate package (#7244)
* Convert runMany and runManySync to use injectManyWithMeta Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup type errors due to new Runnable requirements Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add documentation for verifyRunnablesAreDAG Signed-off-by: Sebastian Malton <sebastian@malton.name> * Simplify convertToWithIdWith Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move all utility functions to separate package Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move testing utilities to separate package Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move run-many and run-many-sync to separate package Signed-off-by: Sebastian Malton <sebastian@malton.name> * Replace all internal uses of utilities with new packages Signed-off-by: Sebastian Malton <sebastian@malton.name> * Use new @k8slens/run-many package in core Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add dep to open-lens Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup uses of @k8slens/test-utils Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup getGlobalOverride Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move tests to new package too Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup uses of AsyncResult and autoBind Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup remaining import issues Signed-off-by: Sebastian Malton <sebastian@malton.name> * Finial fixups to fix build Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * Revert moving "testUsingFakeTime" to separate package - This fixes tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix integration tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix unit test failing due to spelling fix Signed-off-by: Sebastian Malton <sebastian@malton.name> --------- Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
ad9bafe2a5
commit
2789bcebcb
754 files changed
+2715
-2752
No files matched your search
@@ -6,14 +6,14 @@
|
||||
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||
import listHelmChartsInjectable from "../helm-service/list-helm-charts.injectable";
|
||||
import getActiveHelmRepositoriesInjectable from "../repositories/get-active-helm-repositories/get-active-helm-repositories.injectable";
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import type { HelmRepo } from "../../../common/helm/helm-repo";
|
||||
import { sortBySemverVersion } from "../../../common/utils";
|
||||
import { sortBySemverVersion } from "@k8slens/utilities";
|
||||
import helmChartManagerInjectable from "../helm-chart-manager.injectable";
|
||||
|
||||
describe("Helm Service tests", () => {
|
||||
let listHelmCharts: () => Promise<any>;
|
||||
let getActiveHelmRepositoriesMock: jest.Mock<Promise<AsyncResult<HelmRepo[]>>>;
|
||||
let getActiveHelmRepositoriesMock: jest.Mock<AsyncResult<HelmRepo[]>>;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { computed } from "mobx";
|
||||
import { getGlobalOverride } from "../../../common/test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import execHelmEnvInjectable from "./exec-env.injectable";
|
||||
|
||||
export default getGlobalOverride(execHelmEnvInjectable, () => computed(() => ({})));
|
||||
@@ -5,11 +5,11 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { ExecFileException } from "child_process";
|
||||
import execFileInjectable from "../../../common/fs/exec-file.injectable";
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import helmBinaryPathInjectable from "../helm-binary-path.injectable";
|
||||
import execHelmEnvInjectable from "./exec-env.injectable";
|
||||
|
||||
export type ExecHelm = (args: string[]) => Promise<AsyncResult<string, ExecFileException & { stderr: string }>>;
|
||||
export type ExecHelm = (args: string[]) => AsyncResult<string, ExecFileException & { stderr: string }>;
|
||||
|
||||
const execHelmInjectable = getInjectable({
|
||||
id: "exec-helm",
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import execHelmInjectable from "../exec-helm/exec-helm.injectable";
|
||||
import type { AsyncResult } from "../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
|
||||
export type HelmEnv = Record<string, string> & {
|
||||
HELM_REPOSITORY_CACHE?: string;
|
||||
@@ -17,7 +17,7 @@ const getHelmEnvInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const execHelm = di.inject(execHelmInjectable);
|
||||
|
||||
return async (): Promise<AsyncResult<HelmEnv>> => {
|
||||
return async (): AsyncResult<HelmEnv> => {
|
||||
const result = await execHelm(["env"]);
|
||||
|
||||
if (!result.callWasSuccessful) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import * as yaml from "js-yaml";
|
||||
import { iter, put, sortBySemverVersion } from "../../common/utils";
|
||||
import { iter, put, sortBySemverVersion } from "@k8slens/utilities";
|
||||
import type { HelmRepo } from "../../common/helm/helm-repo";
|
||||
import type { HelmChartManagerCache } from "./helm-chart-manager-cache.injectable";
|
||||
import type { Logger } from "../../common/logger";
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../../../common/test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import getHelmChartReadmeInjectable from "./get-helm-chart-readme.injectable";
|
||||
|
||||
export default getGlobalOverride(getHelmChartReadmeInjectable, () => () => {
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import execHelmInjectable from "../../../exec-helm/exec-helm.injectable";
|
||||
import yaml from "js-yaml";
|
||||
import type { KubeJsonApiData, KubeJsonApiDataList } from "../../../../../common/k8s-api/kube-json-api";
|
||||
@@ -18,7 +18,7 @@ const callForHelmManifestInjectable = getInjectable({
|
||||
name: string,
|
||||
namespace: string,
|
||||
kubeconfigPath: string,
|
||||
): Promise<AsyncResult<(KubeJsonApiData | KubeJsonApiDataList)[]>> => {
|
||||
): AsyncResult<(KubeJsonApiData | KubeJsonApiDataList)[]> => {
|
||||
const result = await execHelm([
|
||||
"get",
|
||||
"manifest",
|
||||
|
||||
+1
-2
@@ -4,7 +4,6 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { JsonObject } from "type-fest";
|
||||
import { json } from "../../../../../common/utils";
|
||||
import yaml from "js-yaml";
|
||||
import execFileWithInputInjectable from "./exec-file-with-input/exec-file-with-input.injectable";
|
||||
import { getErrorMessage } from "../../../../../common/utils/get-error-message";
|
||||
@@ -60,7 +59,7 @@ const callForKubeResourcesByManifestInjectable = getInjectable({
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
const output = json.parse(result.response) as { items: JsonObject[] };
|
||||
const output = JSON.parse(result.response) as { items: JsonObject[] };
|
||||
|
||||
return output.items;
|
||||
};
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getGlobalOverride } from "../../../../../../common/test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import execFileWithInputInjectable from "./exec-file-with-input.injectable";
|
||||
|
||||
export default getGlobalOverride(execFileWithInputInjectable, () => () => {
|
||||
|
||||
+3
-3
@@ -3,9 +3,9 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import nonPromiseExecFileInjectable from "./non-promise-exec-file.injectable";
|
||||
import { isNumber } from "../../../../../../common/utils";
|
||||
import { isNumber } from "@k8slens/utilities";
|
||||
import assert from "assert";
|
||||
import type { ChildProcess } from "child_process";
|
||||
|
||||
@@ -13,7 +13,7 @@ export type ExecFileWithInput = (options: {
|
||||
filePath: string;
|
||||
commandArguments: string[];
|
||||
input: string;
|
||||
}) => Promise<AsyncResult<string, unknown>>;
|
||||
}) => AsyncResult<string, unknown>;
|
||||
|
||||
const execFileWithInputInjectable = getInjectable({
|
||||
id: "exec-file-with-input",
|
||||
|
||||
+3
-3
@@ -5,9 +5,9 @@
|
||||
import { getDiForUnitTesting } from "../../../../../getDiForUnitTesting";
|
||||
import type { ExecFileWithInput } from "./exec-file-with-input.injectable";
|
||||
import execFileWithInputInjectable from "./exec-file-with-input.injectable";
|
||||
import type { AsyncResult } from "../../../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import nonPromiseExecFileInjectable from "./non-promise-exec-file.injectable";
|
||||
import { getPromiseStatus } from "../../../../../../common/test-utils/get-promise-status";
|
||||
import { getPromiseStatus } from "@k8slens/test-utils";
|
||||
import EventEmitter from "events";
|
||||
|
||||
describe("exec-file-with-input", () => {
|
||||
@@ -56,7 +56,7 @@ describe("exec-file-with-input", () => {
|
||||
});
|
||||
|
||||
describe("when called", () => {
|
||||
let actualPromise: Promise<AsyncResult<string, unknown>>;
|
||||
let actualPromise: AsyncResult<string, unknown>;
|
||||
|
||||
beforeEach(() => {
|
||||
actualPromise = execFileWithInput({
|
||||
|
||||
+2
-2
@@ -5,13 +5,13 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import callForHelmManifestInjectable from "./call-for-helm-manifest/call-for-helm-manifest.injectable";
|
||||
import type { KubeJsonApiData, KubeJsonApiDataList } from "../../../../common/k8s-api/kube-json-api";
|
||||
import type { AsyncResult } from "../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
|
||||
export type GetHelmReleaseResources = (
|
||||
name: string,
|
||||
namespace: string,
|
||||
kubeconfigPath: string,
|
||||
) => Promise<AsyncResult<KubeJsonApiData[], string>>;
|
||||
) => AsyncResult<KubeJsonApiData[], string>;
|
||||
|
||||
const getHelmReleaseResourcesInjectable = getInjectable({
|
||||
id: "get-helm-release-resources",
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import type { ExecFileWithInput } from "./call-for-kube-resources-by-manifest/exec-file-with-input/exec-file-with-input.injectable";
|
||||
import execFileWithInputInjectable from "./call-for-kube-resources-by-manifest/exec-file-with-input/exec-file-with-input.injectable";
|
||||
import type { AsyncResult } from "../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import type { KubeJsonApiData } from "../../../../common/k8s-api/kube-json-api";
|
||||
|
||||
describe("get helm release resources", () => {
|
||||
@@ -37,7 +37,7 @@ describe("get helm release resources", () => {
|
||||
});
|
||||
|
||||
describe("when called", () => {
|
||||
let actualPromise: Promise<AsyncResult<KubeJsonApiData[], string>>;
|
||||
let actualPromise: AsyncResult<KubeJsonApiData[], string>;
|
||||
|
||||
beforeEach(() => {
|
||||
actualPromise = getHelmReleaseResources(
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getGlobalOverride } from "../../../common/test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import getHelmReleaseInjectable from "./get-helm-release.injectable";
|
||||
|
||||
export default getGlobalOverride(getHelmReleaseInjectable, () => () => {
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Cluster } from "../../../common/cluster/cluster";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
import { isObject, json } from "../../../common/utils";
|
||||
import kubeconfigManagerInjectable from "../../kubeconfig-manager/kubeconfig-manager.injectable";
|
||||
import { isObject, json } from "@k8slens/utilities";
|
||||
import execHelmInjectable from "../exec-helm/exec-helm.injectable";
|
||||
import getHelmReleaseResourcesInjectable from "./get-helm-release-resources/get-helm-release-resources.injectable";
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import assert from "assert";
|
||||
import { object } from "../../../common/utils";
|
||||
import { object } from "@k8slens/utilities";
|
||||
import getActiveHelmRepositoriesInjectable from "../repositories/get-active-helm-repositories/get-active-helm-repositories.injectable";
|
||||
import type { HelmRepo } from "../../../common/helm/helm-repo";
|
||||
import helmChartManagerInjectable from "../helm-chart-manager.injectable";
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getGlobalOverride } from "../../../common/test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import updateHelmReleaseInjectable from "./update-helm-release.injectable";
|
||||
|
||||
export default getGlobalOverride(updateHelmReleaseInjectable, () => () => {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import execHelmInjectable from "./exec-helm/exec-helm.injectable";
|
||||
import { isObject, json, toCamelCase } from "../../common/utils";
|
||||
import { toCamelCase, isObject } from "@k8slens/utilities";
|
||||
|
||||
export type ListHelmReleases = (pathToKubeconfig: string, namespace?: string) => Promise<Record<string, any>[]>;
|
||||
|
||||
@@ -34,7 +34,7 @@ const listHelmReleasesInjectable = getInjectable({
|
||||
throw result.error;
|
||||
}
|
||||
|
||||
const output = json.parse(result.response);
|
||||
const output = JSON.parse(result.response);
|
||||
|
||||
if (!Array.isArray(output) || output.length == 0) {
|
||||
return [];
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ import readYamlFileInjectable from "../../../../common/fs/read-yaml-file.injecta
|
||||
import getHelmEnvInjectable from "../../get-helm-env/get-helm-env.injectable";
|
||||
import execHelmInjectable from "../../exec-helm/exec-helm.injectable";
|
||||
import loggerInjectable from "../../../../common/logger.injectable";
|
||||
import type { AsyncResult } from "../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
|
||||
interface HelmRepositoryFromYaml {
|
||||
name: string;
|
||||
@@ -38,7 +38,7 @@ const getActiveHelmRepositoriesInjectable = getInjectable({
|
||||
|
||||
const getRepositories = getRepositoriesFor(readYamlFile);
|
||||
|
||||
return async (): Promise<AsyncResult<HelmRepo[]>> => {
|
||||
return async (): AsyncResult<HelmRepo[]> => {
|
||||
const envResult = await getHelmEnv();
|
||||
|
||||
if (!envResult.callWasSuccessful) {
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import execHelmInjectable from "../../exec-helm/exec-helm.injectable";
|
||||
import type { HelmRepo } from "../../../../common/helm/helm-repo";
|
||||
import loggerInjectable from "../../../../common/logger.injectable";
|
||||
import type { AsyncResult } from "../../../../common/utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
|
||||
const removeHelmRepositoryInjectable = getInjectable({
|
||||
id: "remove-helm-repository",
|
||||
@@ -15,7 +15,7 @@ const removeHelmRepositoryInjectable = getInjectable({
|
||||
const execHelm = di.inject(execHelmInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
|
||||
return async (repo: HelmRepo): Promise<AsyncResult<void, string>> => {
|
||||
return async (repo: HelmRepo): AsyncResult<void, string> => {
|
||||
logger.info(`[HELM]: removing repo ${repo.name} (${repo.url})`);
|
||||
|
||||
const result = await execHelm([
|
||||
|
||||
Reference in new issue
Block a user