From 95f0a4660cd1db0c7a8ffca9693499a4362a54a2 Mon Sep 17 00:00:00 2001 From: Manabu Mccloskey Date: Wed, 28 Jun 2023 18:33:32 -0700 Subject: [PATCH] add more tests --- .../src/api/ArgoWorkflows.test.ts | 42 +- .../argo-workflows/src/api/ArgoWorkflows.ts | 11 +- plugins/argo-workflows/src/api/index.ts | 5 +- .../WorkflowOverview.test.tsx | 148 ++++ .../WorkflowOverview/WorkflowOverview.tsx | 27 +- plugins/argo-workflows/src/plugin.ts | 6 +- plugins/argo-workflows/src/test-data/error.ts | 53 -- .../argo-workflows/src/test-data/failed.ts | 43 -- .../src/test-data/in-progress.ts | 307 -------- .../src/test-data/testResponse.ts | 702 ++++++++++++++++++ 10 files changed, 879 insertions(+), 465 deletions(-) create mode 100644 plugins/argo-workflows/src/components/WorkflowOverview/WorkflowOverview.test.tsx delete mode 100644 plugins/argo-workflows/src/test-data/error.ts delete mode 100644 plugins/argo-workflows/src/test-data/failed.ts delete mode 100644 plugins/argo-workflows/src/test-data/in-progress.ts create mode 100644 plugins/argo-workflows/src/test-data/testResponse.ts diff --git a/plugins/argo-workflows/src/api/ArgoWorkflows.test.ts b/plugins/argo-workflows/src/api/ArgoWorkflows.test.ts index dc160ab..796035a 100644 --- a/plugins/argo-workflows/src/api/ArgoWorkflows.test.ts +++ b/plugins/argo-workflows/src/api/ArgoWorkflows.test.ts @@ -1,10 +1,10 @@ import { DiscoveryApi } from "@backstage/core-plugin-api"; import { ArgoWorkflows } from "./ArgoWorkflows"; import { KubernetesApi } from "@backstage/plugin-kubernetes"; -import { MockConfigApi, MockFetchApi } from "@backstage/test-utils"; +import { MockFetchApi } from "@backstage/test-utils"; import { FrontendHostDiscovery } from "@backstage/core-app-api"; import { UserIdentity } from "@backstage/core-components"; -import { inProgress } from "../test-data/in-progress"; +import { inProgress } from "../test-data/testResponse"; describe("ArgoWorkflowsClient", () => { const mockDiscoveryApi: jest.Mocked = { @@ -12,9 +12,6 @@ describe("ArgoWorkflowsClient", () => { return Promise.resolve(`https://backstage.io/${id}`); }), }; - const mockConfigApi = new MockConfigApi({ - app: { baseUrl: "https://backstage.io" }, - }); const noopFetchApi = new MockFetchApi({ baseImplementation: "none" }); const mockKClient: jest.Mocked = { @@ -49,12 +46,7 @@ describe("ArgoWorkflowsClient", () => { text: async () => JSON.stringify(inProgress), } as Response); - const a = new ArgoWorkflows( - mockDiscoveryApi, - mockKClient, - mockConfigApi, - noopFetchApi - ); + const a = new ArgoWorkflows(mockDiscoveryApi, mockKClient, noopFetchApi); const spy = jest.spyOn(mockKClient, "proxy"); const resp = await a.getWorkflowsFromK8s("abc", "default", "my=env"); expect(resp.items.length).toBe(1); @@ -76,12 +68,7 @@ describe("ArgoWorkflowsClient", () => { }, ]); - const a = new ArgoWorkflows( - mockDiscoveryApi, - mockKClient, - mockConfigApi, - noopFetchApi - ); + const a = new ArgoWorkflows(mockDiscoveryApi, mockKClient, noopFetchApi); const spy = jest.spyOn(a, "getFirstCluster"); const resp = await a.getWorkflowsFromK8s(undefined, "default", "my=env"); expect(resp.items.length).toBe(1); @@ -95,12 +82,7 @@ describe("ArgoWorkflowsClient", () => { text: async () => "oh no", } as Response); - const a = new ArgoWorkflows( - mockDiscoveryApi, - mockKClient, - mockConfigApi, - noopFetchApi - ); + const a = new ArgoWorkflows(mockDiscoveryApi, mockKClient, noopFetchApi); await expect( a.getWorkflowsFromK8s("abc", "default", "not used") ).rejects.toEqual( @@ -114,12 +96,7 @@ describe("ArgoWorkflowsClient", () => { text: async () => JSON.stringify(inProgress), }); const fetchApi = new MockFetchApi({ baseImplementation: impl }); - const a = new ArgoWorkflows( - mockDiscoveryApi, - mockKClient, - mockConfigApi, - fetchApi - ); + const a = new ArgoWorkflows(mockDiscoveryApi, mockKClient, fetchApi); const resp = await a.getWorkflowsFromProxy("default", "my=env"); expect(resp.items.length).toBe(1); }); @@ -131,12 +108,7 @@ describe("ArgoWorkflowsClient", () => { text: async () => "oh no", }); const fetchApi = new MockFetchApi({ baseImplementation: impl }); - const a = new ArgoWorkflows( - mockDiscoveryApi, - mockKClient, - mockConfigApi, - fetchApi - ); + const a = new ArgoWorkflows(mockDiscoveryApi, mockKClient, fetchApi); await expect(a.getWorkflowsFromProxy("default", "my=env")).rejects.toEqual( "failed to fetch resources: 500, something went wrong, oh no" ); diff --git a/plugins/argo-workflows/src/api/ArgoWorkflows.ts b/plugins/argo-workflows/src/api/ArgoWorkflows.ts index 2834552..caeaabe 100644 --- a/plugins/argo-workflows/src/api/ArgoWorkflows.ts +++ b/plugins/argo-workflows/src/api/ArgoWorkflows.ts @@ -1,4 +1,4 @@ -import { ConfigApi, DiscoveryApi, FetchApi } from "@backstage/core-plugin-api"; +import { DiscoveryApi, FetchApi } from "@backstage/core-plugin-api"; import { KubernetesApi } from "@backstage/plugin-kubernetes"; import { IoArgoprojWorkflowV1alpha1WorkflowList } from "./generated"; import { ArgoWorkflowsApi } from "./index"; @@ -11,20 +11,17 @@ const API_TIMEOUT = "listOptions.timeoutSeconds"; const K8s_API_TIMEOUT = "timeoutSeconds"; export class ArgoWorkflows implements ArgoWorkflowsApi { - discoveryApi: DiscoveryApi; - kubernetesApi: KubernetesApi; - configApi: ConfigApi; - fetchApi: FetchApi; + private discoveryApi: DiscoveryApi; + private kubernetesApi: KubernetesApi; + private fetchApi: FetchApi; constructor( discoveryApi: DiscoveryApi, kubernetesApi: KubernetesApi, - configApi: ConfigApi, fetchApi: FetchApi ) { this.discoveryApi = discoveryApi; this.kubernetesApi = kubernetesApi; - this.configApi = configApi; this.fetchApi = fetchApi; } diff --git a/plugins/argo-workflows/src/api/index.ts b/plugins/argo-workflows/src/api/index.ts index 942b149..b582c96 100644 --- a/plugins/argo-workflows/src/api/index.ts +++ b/plugins/argo-workflows/src/api/index.ts @@ -1,6 +1,5 @@ -import { createApiRef, DiscoveryApi } from "@backstage/core-plugin-api"; +import { createApiRef } from "@backstage/core-plugin-api"; -import { KubernetesApi } from "@backstage/plugin-kubernetes"; import { IoArgoprojWorkflowV1alpha1WorkflowList } from "./generated/"; export { ArgoWorkflows } from "./ArgoWorkflows"; @@ -9,8 +8,6 @@ export const argoWorkflowsApiRef = createApiRef({ id: "plugin.argoworkflows", }); export interface ArgoWorkflowsApi { - discoveryApi: DiscoveryApi; - kubernetesApi: KubernetesApi; getWorkflowsFromK8s( clusterName: string, namespace: string | undefined, diff --git a/plugins/argo-workflows/src/components/WorkflowOverview/WorkflowOverview.test.tsx b/plugins/argo-workflows/src/components/WorkflowOverview/WorkflowOverview.test.tsx new file mode 100644 index 0000000..4a4d26e --- /dev/null +++ b/plugins/argo-workflows/src/components/WorkflowOverview/WorkflowOverview.test.tsx @@ -0,0 +1,148 @@ +import React from "react"; +import { + MockConfigApi, + MockFetchApi, + renderInTestApp, + TestApiProvider, +} from "@backstage/test-utils"; +import { + AnyApiRef, + configApiRef, + DiscoveryApi, + discoveryApiRef, + fetchApiRef, +} from "@backstage/core-plugin-api"; +import { ArgoWorkflowsApi, argoWorkflowsApiRef } from "../../api"; +import { KubernetesApi, kubernetesApiRef } from "@backstage/plugin-kubernetes"; +import { EntityProvider } from "@backstage/plugin-catalog-react"; +import { WorkflowOverviewComponent } from "./WorkflowOverview"; +import { empty, inProgress, mixResponse } from "../../test-data/testResponse"; +import { IoArgoprojWorkflowV1alpha1WorkflowList } from "../../api/generated"; + +const BASE_URL = "https://backstage.io"; +const mockConfigApi = new MockConfigApi({ + argoWorkflows: { baseUrl: BASE_URL }, +}); +const mockDiscoveryApi: jest.Mocked = { + getBaseUrl: jest.fn().mockImplementation((id) => { + return Promise.resolve(`https://backstage.io/${id}`); + }), +}; +const mockKClient: jest.Mocked = { + getObjectsByEntity: jest.fn(), + getClusters: jest.fn(), + getWorkloadsByEntity: jest.fn(), + getCustomObjectsByEntity: jest.fn(), + proxy: jest.fn(), +}; +const noopFetchApi = new MockFetchApi({ baseImplementation: "none" }); +const mockArgoWorkflows: jest.Mocked = { + getWorkflows: jest.fn(), + getWorkflowsFromK8s: jest.fn(), + getWorkflowsFromProxy: jest.fn(), +}; + +const apis: [AnyApiRef, Partial][] = [ + [discoveryApiRef, mockDiscoveryApi], + [kubernetesApiRef, mockKClient], + [configApiRef, mockConfigApi], + [fetchApiRef, noopFetchApi], + [argoWorkflowsApiRef, mockArgoWorkflows], +]; + +const entity = { + metadata: { + namespace: "default", + annotations: { + "backstage.io/kubernetes-label-selector": "my=env", + "backstage.io/kubernetes-namespace": "default", + }, + name: "my-entity", + }, + apiVersion: "backstage.io/v1alpha1", + kind: "Component", +}; + +afterEach(() => { + jest.clearAllMocks(); +}); + +describe("WorkflowOverviewComponent", () => { + it("should display workflows without link", async () => { + jest + .spyOn(mockArgoWorkflows, "getWorkflows") + .mockImplementation( + (_n, _ns, _l): Promise => { + return Promise.resolve( + inProgress as unknown as IoArgoprojWorkflowV1alpha1WorkflowList + ); + } + ); + jest.spyOn(mockConfigApi, "getOptionalString").mockImplementation((_) => { + return undefined; + }); + const r = await renderInTestApp( + + + + + + ); + const c = r.getByText(inProgress.items[0].metadata.name); + expect(c).not.toHaveAttribute( + "href", + `${BASE_URL}/workflows/default/${inProgress.items[0].metadata.name}` + ); + }); + + it("should display workflows wth link", async () => { + const spyWorkflows = jest + .spyOn(mockArgoWorkflows, "getWorkflows") + .mockImplementation( + (_n, _ns, _l): Promise => { + return Promise.resolve( + mixResponse as unknown as IoArgoprojWorkflowV1alpha1WorkflowList + ); + } + ); + const spyConfigApi = jest + .spyOn(mockConfigApi, "getOptionalString") + .mockImplementation((_n) => { + return `https://backstage.io/`; + }); + const r = await renderInTestApp( + + + + + + ); + expect(spyWorkflows).toHaveBeenCalledWith(undefined, "default", "my=env"); + expect(spyConfigApi).toHaveBeenCalledWith("argoWorkflows.baseUrl"); + const c = r.getByText(mixResponse.items[0].metadata.name); + expect(c).toHaveAttribute( + "href", + `${BASE_URL}/workflows/default/${mixResponse.items[0].metadata.name}` + ); + }); + + it("should not display anything", async () => { + jest + .spyOn(mockArgoWorkflows, "getWorkflows") + .mockImplementation( + (_n, _ns, _l): Promise => { + return Promise.resolve( + empty as unknown as IoArgoprojWorkflowV1alpha1WorkflowList + ); + } + ); + const r = await renderInTestApp( + + + + + + ); + expect(r.queryByRole("table")).toBeNull(); + }); +}); diff --git a/plugins/argo-workflows/src/components/WorkflowOverview/WorkflowOverview.tsx b/plugins/argo-workflows/src/components/WorkflowOverview/WorkflowOverview.tsx index ca148fa..28d335c 100644 --- a/plugins/argo-workflows/src/components/WorkflowOverview/WorkflowOverview.tsx +++ b/plugins/argo-workflows/src/components/WorkflowOverview/WorkflowOverview.tsx @@ -16,6 +16,9 @@ type TableData = { finishedAt?: string; }; +const CLUSTER_NAME_ANNOTATION = "argo-workflows/cluster-name"; +const K8S_LABEL_SELECTOR_ANNOTATION = "backstage.io/kubernetes-label-selector"; +const K8S_NAMESPACE_ANNOTATION = "backstage.io/kubernetes-namespace"; export const WorkflowOverviewComponent = () => { const { entity } = useEntity(); const apiClient = useApi(argoWorkflowsApiRef); @@ -30,12 +33,18 @@ export const WorkflowOverviewComponent = () => { ); } - const ln = entity.metadata.annotations?.["backstage.io/kubernetes-namespace"]; + const ln = entity.metadata.annotations?.[K8S_NAMESPACE_ANNOTATION]; const ns = ln !== undefined ? ln : "default"; - const clusterName = - entity.metadata.annotations?.["argo-workflows/cluster-name"]; + const clusterName = entity.metadata.annotations?.[CLUSTER_NAME_ANNOTATION]; const k8sLabelSelector = - entity.metadata.annotations?.["backstage.io/kubernetes-label-selector"]; + entity.metadata.annotations?.[K8S_LABEL_SELECTOR_ANNOTATION]; + + const { value, loading, error } = useAsync( + async (): Promise => { + return await apiClient.getWorkflows(clusterName, ns, k8sLabelSelector); + } + ); + if (!k8sLabelSelector) { return null; } @@ -85,12 +94,6 @@ export const WorkflowOverviewComponent = () => { { title: "Namespace", field: "namespace", type: "string" }, ]; - const { value, loading, error } = useAsync( - async (): Promise => { - return await apiClient.getWorkflows(clusterName, ns, k8sLabelSelector); - } - ); - if (loading) { return ; } else if (error) { @@ -108,7 +111,7 @@ export const WorkflowOverviewComponent = () => { } as TableData; }); - if (data) { + if (data && data.length !== 0) { return ( { sorting: true, }} columns={columns} - data={data.sort()} + data={data} /> ); } diff --git a/plugins/argo-workflows/src/plugin.ts b/plugins/argo-workflows/src/plugin.ts index dea9c2a..d887c36 100644 --- a/plugins/argo-workflows/src/plugin.ts +++ b/plugins/argo-workflows/src/plugin.ts @@ -1,5 +1,4 @@ import { - configApiRef, createApiFactory, createPlugin, createRoutableExtension, @@ -22,11 +21,10 @@ export const argoWorkflowsPlugin = createPlugin({ deps: { discoveryApi: discoveryApiRef, kubernetesApi: kubernetesApiRef, - configApi: configApiRef, fetchApi: fetchApiRef, }, - factory: ({ discoveryApi, kubernetesApi, configApi, fetchApi }) => - new ArgoWorkflows(discoveryApi, kubernetesApi, configApi, fetchApi), + factory: ({ discoveryApi, kubernetesApi, fetchApi }) => + new ArgoWorkflows(discoveryApi, kubernetesApi, fetchApi), }), ], }); diff --git a/plugins/argo-workflows/src/test-data/error.ts b/plugins/argo-workflows/src/test-data/error.ts deleted file mode 100644 index ae94abb..0000000 --- a/plugins/argo-workflows/src/test-data/error.ts +++ /dev/null @@ -1,53 +0,0 @@ -export const errored = { - apiVersion: "v1", - kind: "List", - metadata: { - resourceVersion: "", - }, - items: [ - { - apiVersion: "argoproj.io/v1alpha1", - kind: "Workflow", - metadata: { - creationTimestamp: "2023-06-21T21:28:37Z", - generateName: "test-workflow-", - generation: 2, - labels: { - "workflows.argoproj.io/completed": "true", - "workflows.argoproj.io/phase": "Error", - }, - name: "test-workflow-2vphn", - namespace: "default", - resourceVersion: "43163381", - uid: "40700bb3-2bce-4080-b0c8-c48033820666", - }, - spec: { - arguments: { - parameters: [ - { - name: "message", - value: "from workflow", - }, - ], - }, - workflowTemplateRef: { - name: "workflow-template-whalesay-template", - }, - }, - status: { - conditions: [ - { - status: "True", - type: "Completed", - }, - ], - finishedAt: "2023-06-21T21:28:37Z", - message: - 'malformed workflow template "default/workflow-template-whalesay-template": cannot convert int64 to string', - phase: "Error", - progress: "0/0", - startedAt: "2023-06-21T21:28:37Z", - }, - }, - ], -}; diff --git a/plugins/argo-workflows/src/test-data/failed.ts b/plugins/argo-workflows/src/test-data/failed.ts deleted file mode 100644 index 8767d76..0000000 --- a/plugins/argo-workflows/src/test-data/failed.ts +++ /dev/null @@ -1,43 +0,0 @@ -export const failed = { - apiVersion: "v1", - kind: "List", - metadata: { - resourceVersion: "", - }, - items: [ - { - apiVersion: "argoproj.io/v1alpha1", - kind: "Workflow", - metadata: { - creationTimestamp: "2023-06-22T23:03:08Z", - generateName: "test-workflow-", - generation: 2, - labels: { - "backstage.io/kubernetes-id": "backstage", - "workflows.argoproj.io/completed": "true", - "workflows.argoproj.io/phase": "Failed", - }, - name: "test-workflow-6z6dc", - namespace: "default", - resourceVersion: "43485348", - uid: "98c95400-061a-4f9f-85ca-b95d4bf2ef2b", - }, - spec: { - arguments: {}, - }, - status: { - conditions: [ - { - status: "True", - type: "Completed", - }, - ], - finishedAt: "2023-06-22T23:03:08Z", - message: "cannot unmarshall spec: cannot restore struct from: slice", - phase: "Failed", - progress: "0/0", - startedAt: "2023-06-22T23:03:08Z", - }, - }, - ], -}; diff --git a/plugins/argo-workflows/src/test-data/in-progress.ts b/plugins/argo-workflows/src/test-data/in-progress.ts deleted file mode 100644 index 773ac5d..0000000 --- a/plugins/argo-workflows/src/test-data/in-progress.ts +++ /dev/null @@ -1,307 +0,0 @@ -export const inProgress = { - apiVersion: "v1", - items: [ - { - apiVersion: "argoproj.io/v1alpha1", - kind: "Workflow", - metadata: { - annotations: { - "workflows.argoproj.io/pod-name-format": "v2", - }, - creationTimestamp: "2023-06-27T21:41:33Z", - generateName: "test-workflow-", - generation: 3, - labels: { - "backstage.io/kubernetes-id": "backstage", - env: "dev", - my: "label", - "workflows.argoproj.io/phase": "Running", - }, - name: "test-workflow-f49nr", - namespace: "default", - resourceVersion: "44977391", - uid: "188b33ab-c877-4e04-901c-32babece9573", - }, - spec: { - arguments: { - parameters: [ - { - name: "message", - value: "from workflow", - }, - ], - }, - workflowTemplateRef: { - name: "workflow-template-whalesay-template", - }, - }, - status: { - artifactGCStatus: { - notSpecified: true, - }, - artifactRepositoryRef: { - artifactRepository: {}, - default: true, - }, - conditions: [ - { - status: "True", - type: "PodRunning", - }, - ], - finishedAt: null, - nodes: { - "test-workflow-f49nr": { - children: ["test-workflow-f49nr-1432144569"], - displayName: "test-workflow-f49nr", - finishedAt: null, - id: "test-workflow-f49nr", - inputs: { - parameters: [ - { - name: "message", - value: "from workflow", - }, - ], - }, - name: "test-workflow-f49nr", - phase: "Running", - progress: "1/2", - startedAt: "2023-06-27T21:41:33Z", - templateName: "whalesay-template", - templateScope: "local/", - type: "Steps", - }, - "test-workflow-f49nr-1432144569": { - boundaryID: "test-workflow-f49nr", - children: [ - "test-workflow-f49nr-1588075630", - "test-workflow-f49nr-2771663768", - ], - displayName: "[0]", - finishedAt: null, - id: "test-workflow-f49nr-1432144569", - name: "test-workflow-f49nr[0]", - phase: "Running", - progress: "1/2", - startedAt: "2023-06-27T21:41:33Z", - templateScope: "local/", - type: "StepGroup", - }, - "test-workflow-f49nr-1588075630": { - boundaryID: "test-workflow-f49nr", - displayName: "whalesay3", - finishedAt: "2023-06-27T21:41:37Z", - hostNodeName: "ip-192-168-10-135.us-west-2.compute.internal", - id: "test-workflow-f49nr-1588075630", - inputs: { - parameters: [ - { - name: "message", - value: "from workflow", - }, - ], - }, - name: "test-workflow-f49nr[0].whalesay3", - outputs: { - exitCode: "0", - }, - phase: "Succeeded", - progress: "1/1", - resourcesDuration: { - cpu: 4, - memory: 4, - }, - startedAt: "2023-06-27T21:41:33Z", - templateName: "whalesay-template-3", - templateScope: "local/", - type: "Pod", - }, - "test-workflow-f49nr-2771663768": { - boundaryID: "test-workflow-f49nr", - displayName: "sleep", - finishedAt: null, - hostNodeName: "ip-192-168-5-156.us-west-2.compute.internal", - id: "test-workflow-f49nr-2771663768", - name: "test-workflow-f49nr[0].sleep", - phase: "Running", - progress: "0/1", - startedAt: "2023-06-27T21:41:33Z", - templateName: "sleep", - templateScope: "local/", - type: "Pod", - }, - }, - phase: "Running", - progress: "1/2", - resourcesDuration: { - cpu: 4, - memory: 4, - }, - startedAt: "2023-06-27T21:41:33Z", - storedTemplates: { - "namespaced/workflow-template-whalesay-template/sleep": { - container: { - args: ["600"], - command: ["sleep"], - image: "docker/whalesay", - name: "", - resources: {}, - }, - inputs: {}, - metadata: {}, - name: "sleep", - outputs: {}, - }, - "namespaced/workflow-template-whalesay-template/whalesay-template": { - inputs: { - parameters: [ - { - name: "message", - }, - ], - }, - metadata: {}, - name: "whalesay-template", - outputs: {}, - steps: [ - [ - { - arguments: { - parameters: [ - { - name: "message", - value: "{{inputs.parameters.message}}", - }, - ], - }, - name: "whalesay3", - template: "whalesay-template-3", - }, - { - arguments: {}, - name: "sleep", - template: "sleep", - }, - ], - ], - }, - "namespaced/workflow-template-whalesay-template/whalesay-template-3": - { - container: { - args: ["{{inputs.parameters.message}}"], - command: ["cowsay"], - image: "docker/whalesay", - name: "", - resources: {}, - }, - inputs: { - parameters: [ - { - name: "message", - }, - ], - }, - metadata: {}, - name: "whalesay-template-3", - outputs: {}, - }, - }, - storedWorkflowTemplateSpec: { - arguments: { - parameters: [ - { - name: "message", - value: "from workflow", - }, - ], - }, - entrypoint: "whalesay-template", - templates: [ - { - inputs: { - parameters: [ - { - name: "message", - }, - ], - }, - metadata: {}, - name: "whalesay-template", - outputs: {}, - steps: [ - [ - { - arguments: { - parameters: [ - { - name: "message", - value: "{{inputs.parameters.message}}", - }, - ], - }, - name: "whalesay3", - template: "whalesay-template-3", - }, - { - arguments: {}, - name: "sleep", - template: "sleep", - }, - ], - ], - }, - { - container: { - args: ["600"], - command: ["sleep"], - image: "docker/whalesay", - name: "", - resources: {}, - }, - inputs: {}, - metadata: {}, - name: "sleep", - outputs: {}, - }, - { - container: { - args: ["{{inputs.parameters.message}}"], - command: ["cowsay"], - image: "docker/whalesay", - name: "", - resources: {}, - }, - inputs: { - parameters: [ - { - name: "message", - }, - ], - }, - metadata: {}, - name: "whalesay-template-3", - outputs: {}, - }, - ], - ttlStrategy: { - secondsAfterCompletion: 28800, - }, - workflowMetadata: { - labels: { - env: "dev", - my: "label", - }, - }, - workflowTemplateRef: { - name: "workflow-template-whalesay-template", - }, - }, - }, - }, - ], - kind: "List", - metadata: { - resourceVersion: "", - }, -}; diff --git a/plugins/argo-workflows/src/test-data/testResponse.ts b/plugins/argo-workflows/src/test-data/testResponse.ts new file mode 100644 index 0000000..663b196 --- /dev/null +++ b/plugins/argo-workflows/src/test-data/testResponse.ts @@ -0,0 +1,702 @@ +export const inProgress = { + apiVersion: "v1", + items: [ + { + apiVersion: "argoproj.io/v1alpha1", + kind: "Workflow", + metadata: { + annotations: { + "workflows.argoproj.io/pod-name-format": "v2", + }, + creationTimestamp: "2023-06-27T21:41:33Z", + generateName: "test-workflow-", + generation: 3, + labels: { + "backstage.io/kubernetes-id": "backstage", + env: "dev", + my: "label", + "workflows.argoproj.io/phase": "Running", + }, + name: "test-workflow-f49nr", + namespace: "default", + resourceVersion: "44977391", + uid: "188b33ab-c877-4e04-901c-32babece9573", + }, + spec: { + arguments: { + parameters: [ + { + name: "message", + value: "from workflow", + }, + ], + }, + workflowTemplateRef: { + name: "workflow-template-whalesay-template", + }, + }, + status: { + artifactGCStatus: { + notSpecified: true, + }, + artifactRepositoryRef: { + artifactRepository: {}, + default: true, + }, + conditions: [ + { + status: "True", + type: "PodRunning", + }, + ], + finishedAt: null, + nodes: { + "test-workflow-f49nr": { + children: ["test-workflow-f49nr-1432144569"], + displayName: "test-workflow-f49nr", + finishedAt: null, + id: "test-workflow-f49nr", + inputs: { + parameters: [ + { + name: "message", + value: "from workflow", + }, + ], + }, + name: "test-workflow-f49nr", + phase: "Running", + progress: "1/2", + startedAt: "2023-06-27T21:41:33Z", + templateName: "whalesay-template", + templateScope: "local/", + type: "Steps", + }, + "test-workflow-f49nr-1432144569": { + boundaryID: "test-workflow-f49nr", + children: [ + "test-workflow-f49nr-1588075630", + "test-workflow-f49nr-2771663768", + ], + displayName: "[0]", + finishedAt: null, + id: "test-workflow-f49nr-1432144569", + name: "test-workflow-f49nr[0]", + phase: "Running", + progress: "1/2", + startedAt: "2023-06-27T21:41:33Z", + templateScope: "local/", + type: "StepGroup", + }, + "test-workflow-f49nr-1588075630": { + boundaryID: "test-workflow-f49nr", + displayName: "whalesay3", + finishedAt: "2023-06-27T21:41:37Z", + hostNodeName: "ip-192-168-10-135.us-west-2.compute.internal", + id: "test-workflow-f49nr-1588075630", + inputs: { + parameters: [ + { + name: "message", + value: "from workflow", + }, + ], + }, + name: "test-workflow-f49nr[0].whalesay3", + outputs: { + exitCode: "0", + }, + phase: "Succeeded", + progress: "1/1", + resourcesDuration: { + cpu: 4, + memory: 4, + }, + startedAt: "2023-06-27T21:41:33Z", + templateName: "whalesay-template-3", + templateScope: "local/", + type: "Pod", + }, + "test-workflow-f49nr-2771663768": { + boundaryID: "test-workflow-f49nr", + displayName: "sleep", + finishedAt: null, + hostNodeName: "ip-192-168-5-156.us-west-2.compute.internal", + id: "test-workflow-f49nr-2771663768", + name: "test-workflow-f49nr[0].sleep", + phase: "Running", + progress: "0/1", + startedAt: "2023-06-27T21:41:33Z", + templateName: "sleep", + templateScope: "local/", + type: "Pod", + }, + }, + phase: "Running", + progress: "1/2", + resourcesDuration: { + cpu: 4, + memory: 4, + }, + startedAt: "2023-06-27T21:41:33Z", + storedTemplates: { + "namespaced/workflow-template-whalesay-template/sleep": { + container: { + args: ["600"], + command: ["sleep"], + image: "docker/whalesay", + name: "", + resources: {}, + }, + inputs: {}, + metadata: {}, + name: "sleep", + outputs: {}, + }, + "namespaced/workflow-template-whalesay-template/whalesay-template": { + inputs: { + parameters: [ + { + name: "message", + }, + ], + }, + metadata: {}, + name: "whalesay-template", + outputs: {}, + steps: [ + [ + { + arguments: { + parameters: [ + { + name: "message", + value: "{{inputs.parameters.message}}", + }, + ], + }, + name: "whalesay3", + template: "whalesay-template-3", + }, + { + arguments: {}, + name: "sleep", + template: "sleep", + }, + ], + ], + }, + "namespaced/workflow-template-whalesay-template/whalesay-template-3": + { + container: { + args: ["{{inputs.parameters.message}}"], + command: ["cowsay"], + image: "docker/whalesay", + name: "", + resources: {}, + }, + inputs: { + parameters: [ + { + name: "message", + }, + ], + }, + metadata: {}, + name: "whalesay-template-3", + outputs: {}, + }, + }, + storedWorkflowTemplateSpec: { + arguments: { + parameters: [ + { + name: "message", + value: "from workflow", + }, + ], + }, + entrypoint: "whalesay-template", + templates: [ + { + inputs: { + parameters: [ + { + name: "message", + }, + ], + }, + metadata: {}, + name: "whalesay-template", + outputs: {}, + steps: [ + [ + { + arguments: { + parameters: [ + { + name: "message", + value: "{{inputs.parameters.message}}", + }, + ], + }, + name: "whalesay3", + template: "whalesay-template-3", + }, + { + arguments: {}, + name: "sleep", + template: "sleep", + }, + ], + ], + }, + { + container: { + args: ["600"], + command: ["sleep"], + image: "docker/whalesay", + name: "", + resources: {}, + }, + inputs: {}, + metadata: {}, + name: "sleep", + outputs: {}, + }, + { + container: { + args: ["{{inputs.parameters.message}}"], + command: ["cowsay"], + image: "docker/whalesay", + name: "", + resources: {}, + }, + inputs: { + parameters: [ + { + name: "message", + }, + ], + }, + metadata: {}, + name: "whalesay-template-3", + outputs: {}, + }, + ], + ttlStrategy: { + secondsAfterCompletion: 28800, + }, + workflowMetadata: { + labels: { + env: "dev", + my: "label", + }, + }, + workflowTemplateRef: { + name: "workflow-template-whalesay-template", + }, + }, + }, + }, + ], + kind: "List", + metadata: { + resourceVersion: "", + }, +}; + +export const empty = { + apiVersion: "v1", + items: [], + kind: "List", + metadata: { + resourceVersion: "", + }, +}; + +export const mixResponse = { + apiVersion: "v1", + items: [ + { + apiVersion: "argoproj.io/v1alpha1", + kind: "Workflow", + metadata: { + annotations: { + "workflows.argoproj.io/pod-name-format": "v2", + }, + creationTimestamp: "2023-06-27T21:41:33Z", + generateName: "test-workflow-", + generation: 3, + labels: { + "backstage.io/kubernetes-id": "backstage", + env: "dev", + my: "label", + "workflows.argoproj.io/phase": "Running", + }, + name: "test-workflow-f49nr", + namespace: "default", + resourceVersion: "44977391", + uid: "188b33ab-c877-4e04-901c-32babece9573", + }, + spec: { + arguments: { + parameters: [ + { + name: "message", + value: "from workflow", + }, + ], + }, + workflowTemplateRef: { + name: "workflow-template-whalesay-template", + }, + }, + status: { + artifactGCStatus: { + notSpecified: true, + }, + artifactRepositoryRef: { + artifactRepository: {}, + default: true, + }, + conditions: [ + { + status: "True", + type: "PodRunning", + }, + ], + finishedAt: null, + nodes: { + "test-workflow-f49nr": { + children: ["test-workflow-f49nr-1432144569"], + displayName: "test-workflow-f49nr", + finishedAt: null, + id: "test-workflow-f49nr", + inputs: { + parameters: [ + { + name: "message", + value: "from workflow", + }, + ], + }, + name: "test-workflow-f49nr", + phase: "Running", + progress: "1/2", + startedAt: "2023-06-27T21:41:33Z", + templateName: "whalesay-template", + templateScope: "local/", + type: "Steps", + }, + "test-workflow-f49nr-1432144569": { + boundaryID: "test-workflow-f49nr", + children: [ + "test-workflow-f49nr-1588075630", + "test-workflow-f49nr-2771663768", + ], + displayName: "[0]", + finishedAt: null, + id: "test-workflow-f49nr-1432144569", + name: "test-workflow-f49nr[0]", + phase: "Running", + progress: "1/2", + startedAt: "2023-06-27T21:41:33Z", + templateScope: "local/", + type: "StepGroup", + }, + "test-workflow-f49nr-1588075630": { + boundaryID: "test-workflow-f49nr", + displayName: "whalesay3", + finishedAt: "2023-06-27T21:41:37Z", + hostNodeName: "ip-192-168-10-135.us-west-2.compute.internal", + id: "test-workflow-f49nr-1588075630", + inputs: { + parameters: [ + { + name: "message", + value: "from workflow", + }, + ], + }, + name: "test-workflow-f49nr[0].whalesay3", + outputs: { + exitCode: "0", + }, + phase: "Succeeded", + progress: "1/1", + resourcesDuration: { + cpu: 4, + memory: 4, + }, + startedAt: "2023-06-27T21:41:33Z", + templateName: "whalesay-template-3", + templateScope: "local/", + type: "Pod", + }, + "test-workflow-f49nr-2771663768": { + boundaryID: "test-workflow-f49nr", + displayName: "sleep", + finishedAt: null, + hostNodeName: "ip-192-168-5-156.us-west-2.compute.internal", + id: "test-workflow-f49nr-2771663768", + name: "test-workflow-f49nr[0].sleep", + phase: "Running", + progress: "0/1", + startedAt: "2023-06-27T21:41:33Z", + templateName: "sleep", + templateScope: "local/", + type: "Pod", + }, + }, + phase: "Running", + progress: "1/2", + resourcesDuration: { + cpu: 4, + memory: 4, + }, + startedAt: "2023-06-27T21:41:33Z", + storedTemplates: { + "namespaced/workflow-template-whalesay-template/sleep": { + container: { + args: ["600"], + command: ["sleep"], + image: "docker/whalesay", + name: "", + resources: {}, + }, + inputs: {}, + metadata: {}, + name: "sleep", + outputs: {}, + }, + "namespaced/workflow-template-whalesay-template/whalesay-template": { + inputs: { + parameters: [ + { + name: "message", + }, + ], + }, + metadata: {}, + name: "whalesay-template", + outputs: {}, + steps: [ + [ + { + arguments: { + parameters: [ + { + name: "message", + value: "{{inputs.parameters.message}}", + }, + ], + }, + name: "whalesay3", + template: "whalesay-template-3", + }, + { + arguments: {}, + name: "sleep", + template: "sleep", + }, + ], + ], + }, + "namespaced/workflow-template-whalesay-template/whalesay-template-3": + { + container: { + args: ["{{inputs.parameters.message}}"], + command: ["cowsay"], + image: "docker/whalesay", + name: "", + resources: {}, + }, + inputs: { + parameters: [ + { + name: "message", + }, + ], + }, + metadata: {}, + name: "whalesay-template-3", + outputs: {}, + }, + }, + storedWorkflowTemplateSpec: { + arguments: { + parameters: [ + { + name: "message", + value: "from workflow", + }, + ], + }, + entrypoint: "whalesay-template", + templates: [ + { + inputs: { + parameters: [ + { + name: "message", + }, + ], + }, + metadata: {}, + name: "whalesay-template", + outputs: {}, + steps: [ + [ + { + arguments: { + parameters: [ + { + name: "message", + value: "{{inputs.parameters.message}}", + }, + ], + }, + name: "whalesay3", + template: "whalesay-template-3", + }, + { + arguments: {}, + name: "sleep", + template: "sleep", + }, + ], + ], + }, + { + container: { + args: ["600"], + command: ["sleep"], + image: "docker/whalesay", + name: "", + resources: {}, + }, + inputs: {}, + metadata: {}, + name: "sleep", + outputs: {}, + }, + { + container: { + args: ["{{inputs.parameters.message}}"], + command: ["cowsay"], + image: "docker/whalesay", + name: "", + resources: {}, + }, + inputs: { + parameters: [ + { + name: "message", + }, + ], + }, + metadata: {}, + name: "whalesay-template-3", + outputs: {}, + }, + ], + ttlStrategy: { + secondsAfterCompletion: 28800, + }, + workflowMetadata: { + labels: { + env: "dev", + my: "label", + }, + }, + workflowTemplateRef: { + name: "workflow-template-whalesay-template", + }, + }, + }, + }, + { + apiVersion: "argoproj.io/v1alpha1", + kind: "Workflow", + metadata: { + creationTimestamp: "2023-06-22T23:03:08Z", + generateName: "test-workflow-", + generation: 2, + labels: { + "backstage.io/kubernetes-id": "backstage", + "workflows.argoproj.io/completed": "true", + "workflows.argoproj.io/phase": "Failed", + }, + name: "test-workflow-6z6dc", + namespace: "default", + resourceVersion: "43485348", + uid: "98c95400-061a-4f9f-85ca-b95d4bf2ef2b", + }, + spec: { + arguments: {}, + }, + status: { + conditions: [ + { + status: "True", + type: "Completed", + }, + ], + finishedAt: "2023-06-22T23:03:08Z", + message: "cannot unmarshall spec: cannot restore struct from: slice", + phase: "Failed", + progress: "0/0", + startedAt: "2023-06-22T23:03:08Z", + }, + }, + { + apiVersion: "argoproj.io/v1alpha1", + kind: "Workflow", + metadata: { + creationTimestamp: "2023-06-21T21:28:37Z", + generateName: "test-workflow-", + generation: 2, + labels: { + "workflows.argoproj.io/completed": "true", + "workflows.argoproj.io/phase": "Error", + }, + name: "test-workflow-2vphn", + namespace: "default", + resourceVersion: "43163381", + uid: "40700bb3-2bce-4080-b0c8-c48033820666", + }, + spec: { + arguments: { + parameters: [ + { + name: "message", + value: "from workflow", + }, + ], + }, + workflowTemplateRef: { + name: "workflow-template-whalesay-template", + }, + }, + status: { + conditions: [ + { + status: "True", + type: "Completed", + }, + ], + finishedAt: "2023-06-21T21:28:37Z", + message: + 'malformed workflow template "default/workflow-template-whalesay-template": cannot convert int64 to string', + phase: "Error", + progress: "0/0", + startedAt: "2023-06-21T21:28:37Z", + }, + }, + ], + kind: "List", + metadata: { + resourceVersion: "", + }, +};