add more tests
This commit is contained in:
parent
a0ba50d39f
commit
1514b1b5c4
5 changed files with 139 additions and 10 deletions
|
@ -82,12 +82,12 @@ describe("ArgoWorkflowsClient", () => {
|
|||
mockConfigApi,
|
||||
noopFetchApi
|
||||
);
|
||||
const spy = jest.spyOn(a, "getCluster");
|
||||
const spy = jest.spyOn(a, "getFirstCluster");
|
||||
const resp = await a.getWorkflowsFromK8s(undefined, "default", "my=env");
|
||||
expect(resp.items.length).toBe(1);
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
it("non ok status returned", async () => {
|
||||
it("rejects when non-ok status returned", async () => {
|
||||
mockKClient.proxy.mockResolvedValue({
|
||||
status: 500,
|
||||
ok: false,
|
||||
|
@ -107,4 +107,38 @@ describe("ArgoWorkflowsClient", () => {
|
|||
"failed to fetch resources: 500, something went wrong, oh no"
|
||||
);
|
||||
});
|
||||
it("can get workflow from proxy", async () => {
|
||||
const impl = jest.fn().mockResolvedValue({
|
||||
status: 200,
|
||||
ok: true,
|
||||
text: async () => JSON.stringify(inProgress),
|
||||
});
|
||||
const fetchApi = new MockFetchApi({ baseImplementation: impl });
|
||||
const a = new ArgoWorkflows(
|
||||
mockDiscoveryApi,
|
||||
mockKClient,
|
||||
mockConfigApi,
|
||||
fetchApi
|
||||
);
|
||||
const resp = await a.getWorkflowsFromProxy("default", "my=env");
|
||||
expect(resp.items.length).toBe(1);
|
||||
});
|
||||
it("rejects when error is returned", async () => {
|
||||
const impl = jest.fn().mockResolvedValue({
|
||||
status: 500,
|
||||
ok: false,
|
||||
statusText: "something went wrong",
|
||||
text: async () => "oh no",
|
||||
});
|
||||
const fetchApi = new MockFetchApi({ baseImplementation: impl });
|
||||
const a = new ArgoWorkflows(
|
||||
mockDiscoveryApi,
|
||||
mockKClient,
|
||||
mockConfigApi,
|
||||
fetchApi
|
||||
);
|
||||
await expect(a.getWorkflowsFromProxy("default", "my=env")).rejects.toEqual(
|
||||
"failed to fetch resources: 500, something went wrong, oh no"
|
||||
);
|
||||
});
|
||||
});
|
|
@ -44,7 +44,7 @@ export class ArgoWorkflows implements ArgoWorkflowsApi {
|
|||
// need limits and pagination
|
||||
const resp = await this.kubernetesApi.proxy({
|
||||
clusterName:
|
||||
clusterName !== undefined ? clusterName : await this.getCluster(),
|
||||
clusterName !== undefined ? clusterName : await this.getFirstCluster(),
|
||||
path: `${path}?${query.toString()}`,
|
||||
});
|
||||
|
||||
|
@ -91,7 +91,7 @@ export class ArgoWorkflows implements ArgoWorkflowsApi {
|
|||
return Promise.reject(
|
||||
`failed to fetch resources: ${resp.status}, ${
|
||||
resp.statusText
|
||||
}, ${await resp.json()}`
|
||||
}, ${await resp.text()}`
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ export class ArgoWorkflows implements ArgoWorkflowsApi {
|
|||
);
|
||||
}
|
||||
|
||||
async getCluster(): Promise<string> {
|
||||
async getFirstCluster(): Promise<string> {
|
||||
const clusters = await this.kubernetesApi.getClusters();
|
||||
if (clusters.length > 0) {
|
||||
return Promise.resolve(clusters[0].name);
|
||||
|
|
|
@ -36,6 +36,9 @@ export const WorkflowOverviewComponent = () => {
|
|||
entity.metadata.annotations?.["argo-workflows/cluster-name"];
|
||||
const k8sLabelSelector =
|
||||
entity.metadata.annotations?.["backstage.io/kubernetes-label-selector"];
|
||||
if (!k8sLabelSelector) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const columns: TableColumn[] = [
|
||||
{
|
||||
|
@ -119,9 +122,5 @@ export const WorkflowOverviewComponent = () => {
|
|||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Alert severity="warning">
|
||||
No Workflows found with given filter. Check your entity's annotations.
|
||||
</Alert>
|
||||
);
|
||||
return null;
|
||||
};
|
||||
|
|
53
plugins/argo-workflows/src/test-data/error.ts
Normal file
53
plugins/argo-workflows/src/test-data/error.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
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",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
43
plugins/argo-workflows/src/test-data/failed.ts
Normal file
43
plugins/argo-workflows/src/test-data/failed.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
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",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
Loading…
Reference in a new issue