mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix pods.test.ts
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
42f6b2de82
commit
977c83502d
@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import assert from "assert";
|
||||
import type { PodContainer, PodContainerStatus } from "../endpoints";
|
||||
import { Pod } from "../endpoints";
|
||||
|
||||
interface GetDummyPodOptions {
|
||||
@ -13,15 +14,18 @@ interface GetDummyPodOptions {
|
||||
initDead?: number;
|
||||
}
|
||||
|
||||
function getDummyPod(rawOpts?: GetDummyPodOptions): Pod {
|
||||
const opts = {
|
||||
...(rawOpts ?? {}),
|
||||
running: 0,
|
||||
dead: 0,
|
||||
initDead: 0,
|
||||
initRunning: 0,
|
||||
};
|
||||
function getDummyPod(rawOpts: GetDummyPodOptions = {}): Pod {
|
||||
const {
|
||||
running = 0,
|
||||
dead = 0,
|
||||
initDead = 0,
|
||||
initRunning = 0,
|
||||
} = rawOpts;
|
||||
|
||||
const containers: PodContainer[] = [];
|
||||
const initContainers: PodContainer[] = [];
|
||||
const containerStatuses: PodContainerStatus[] = [];
|
||||
const initContainerStatuses: PodContainerStatus[] = [];
|
||||
const pod = new Pod({
|
||||
apiVersion: "v1",
|
||||
kind: "Pod",
|
||||
@ -33,8 +37,8 @@ function getDummyPod(rawOpts?: GetDummyPodOptions): Pod {
|
||||
selfLink: "/api/v1/pods/default/test",
|
||||
},
|
||||
spec: {
|
||||
containers: [],
|
||||
initContainers: [],
|
||||
containers,
|
||||
initContainers,
|
||||
serviceAccount: "dummy",
|
||||
serviceAccountName: "dummy",
|
||||
},
|
||||
@ -44,20 +48,20 @@ function getDummyPod(rawOpts?: GetDummyPodOptions): Pod {
|
||||
hostIP: "10.0.0.1",
|
||||
podIP: "10.0.0.1",
|
||||
startTime: "now",
|
||||
containerStatuses: [],
|
||||
initContainerStatuses: [],
|
||||
containerStatuses,
|
||||
initContainerStatuses,
|
||||
},
|
||||
});
|
||||
|
||||
for (let i = 0; i < opts.running; i += 1) {
|
||||
const name = `container_r_${i}`;
|
||||
for (let i = 0; i < running; i += 1) {
|
||||
const name = `container_running_${i}`;
|
||||
|
||||
pod.spec.containers?.push({
|
||||
containers.push({
|
||||
image: "dummy",
|
||||
imagePullPolicy: "dummy",
|
||||
name,
|
||||
});
|
||||
pod.status?.containerStatuses?.push({
|
||||
containerStatuses.push({
|
||||
image: "dummy",
|
||||
imageID: "dummy",
|
||||
name,
|
||||
@ -71,15 +75,15 @@ function getDummyPod(rawOpts?: GetDummyPodOptions): Pod {
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 0; i < opts.dead; i += 1) {
|
||||
const name = `container_d_${i}`;
|
||||
for (let i = 0; i < dead; i += 1) {
|
||||
const name = `container_dead_${i}`;
|
||||
|
||||
pod.spec.containers?.push({
|
||||
containers.push({
|
||||
image: "dummy",
|
||||
imagePullPolicy: "dummy",
|
||||
name,
|
||||
});
|
||||
pod.status?.containerStatuses?.push({
|
||||
containerStatuses.push({
|
||||
image: "dummy",
|
||||
imageID: "dummy",
|
||||
name,
|
||||
@ -96,15 +100,15 @@ function getDummyPod(rawOpts?: GetDummyPodOptions): Pod {
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 0; i < opts.initRunning; i += 1) {
|
||||
const name = `container_ir_${i}`;
|
||||
for (let i = 0; i < initRunning; i += 1) {
|
||||
const name = `container_init-running_${i}`;
|
||||
|
||||
pod.spec.initContainers?.push({
|
||||
initContainers.push({
|
||||
image: "dummy",
|
||||
imagePullPolicy: "dummy",
|
||||
name,
|
||||
});
|
||||
pod.status?.initContainerStatuses?.push({
|
||||
initContainerStatuses.push({
|
||||
image: "dummy",
|
||||
imageID: "dummy",
|
||||
name,
|
||||
@ -118,15 +122,15 @@ function getDummyPod(rawOpts?: GetDummyPodOptions): Pod {
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 0; i < opts.initDead; i += 1) {
|
||||
const name = `container_id_${i}`;
|
||||
for (let i = 0; i < initDead; i += 1) {
|
||||
const name = `container_init-dead_${i}`;
|
||||
|
||||
pod.spec.initContainers?.push({
|
||||
initContainers.push({
|
||||
image: "dummy",
|
||||
imagePullPolicy: "dummy",
|
||||
name,
|
||||
});
|
||||
pod.status?.initContainerStatuses?.push({
|
||||
initContainerStatuses.push({
|
||||
image: "dummy",
|
||||
imageID: "dummy",
|
||||
name,
|
||||
@ -172,8 +176,8 @@ describe("Pods", () => {
|
||||
|
||||
it("getRunningContainers should return only running and init running", () => {
|
||||
const res = [
|
||||
...Array.from(new Array(running), (val, index) => getNamedContainer(`container_r_${index}`)),
|
||||
...Array.from(new Array(initRunning), (val, index) => getNamedContainer(`container_ir_${index}`)),
|
||||
...Array.from(new Array(running), (val, index) => getNamedContainer(`container_running_${index}`)),
|
||||
...Array.from(new Array(initRunning), (val, index) => getNamedContainer(`container_init-running_${index}`)),
|
||||
];
|
||||
|
||||
expect(pod.getRunningContainers()).toStrictEqual(res);
|
||||
@ -181,10 +185,10 @@ describe("Pods", () => {
|
||||
|
||||
it("getAllContainers should return all containers", () => {
|
||||
const res = [
|
||||
...Array.from(new Array(running), (val, index) => getNamedContainer(`container_r_${index}`)),
|
||||
...Array.from(new Array(dead), (val, index) => getNamedContainer(`container_d_${index}`)),
|
||||
...Array.from(new Array(initRunning), (val, index) => getNamedContainer(`container_ir_${index}`)),
|
||||
...Array.from(new Array(initDead), (val, index) => getNamedContainer(`container_id_${index}`)),
|
||||
...Array.from(new Array(running), (val, index) => getNamedContainer(`container_running_${index}`)),
|
||||
...Array.from(new Array(dead), (val, index) => getNamedContainer(`container_dead_${index}`)),
|
||||
...Array.from(new Array(initRunning), (val, index) => getNamedContainer(`container_init-running_${index}`)),
|
||||
...Array.from(new Array(initDead), (val, index) => getNamedContainer(`container_init-dead_${index}`)),
|
||||
];
|
||||
|
||||
expect(pod.getAllContainers()).toStrictEqual(res);
|
||||
|
||||
@ -201,7 +201,7 @@ export interface ContainerState {
|
||||
terminated?: ContainerStateTerminated;
|
||||
}
|
||||
|
||||
export interface IPodContainerStatus {
|
||||
export interface PodContainerStatus {
|
||||
name: string;
|
||||
state?: ContainerState;
|
||||
lastState?: ContainerState;
|
||||
@ -753,8 +753,8 @@ export interface PodStatus {
|
||||
ip: string;
|
||||
}[];
|
||||
startTime: string;
|
||||
initContainerStatuses?: IPodContainerStatus[];
|
||||
containerStatuses?: IPodContainerStatus[];
|
||||
initContainerStatuses?: PodContainerStatus[];
|
||||
containerStatuses?: PodContainerStatus[];
|
||||
qosClass?: string;
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ export { CustomResourceDefinition, crdApi } from "../../common/k8s-api/endpoints
|
||||
|
||||
// types
|
||||
export type { ILocalKubeApiConfig, IRemoteKubeApiConfig, IKubeApiCluster } from "../../common/k8s-api/kube-api";
|
||||
export type { PodContainer as IPodContainer, IPodContainerStatus } from "../../common/k8s-api/endpoints/pods.api";
|
||||
export type { PodContainer as IPodContainer, PodContainerStatus as IPodContainerStatus } from "../../common/k8s-api/endpoints/pods.api";
|
||||
export type { SecretReference as ISecretRef } from "../../common/k8s-api/endpoints/secret.api";
|
||||
export type { KubeObjectMetadata, KubeJsonApiObjectMetadata, KubeStatusData } from "../../common/k8s-api/kube-object";
|
||||
export type { KubeObjectStoreLoadAllParams, KubeObjectStoreLoadingParams, KubeObjectStoreSubscribeParams } from "../../common/k8s-api/kube-object.store";
|
||||
|
||||
@ -73,7 +73,7 @@ export { KubeJsonApi } from "../../common/k8s-api/kube-json-api";
|
||||
|
||||
// types
|
||||
export type { ILocalKubeApiConfig, IRemoteKubeApiConfig, IKubeApiCluster } from "../../common/k8s-api/kube-api";
|
||||
export type { PodContainer as IPodContainer, IPodContainerStatus } from "../../common/k8s-api/endpoints";
|
||||
export type { PodContainer as IPodContainer, PodContainerStatus as IPodContainerStatus } from "../../common/k8s-api/endpoints";
|
||||
export type { SecretReference as ISecretRef } from "../../common/k8s-api/endpoints";
|
||||
export type { KubeObjectStatus } from "./kube-object-status";
|
||||
export type { KubeJsonApiObjectMetadata as KubeObjectMetadata, KubeStatusData } from "../../common/k8s-api/kube-object";
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
import "./pod-details-container.scss";
|
||||
|
||||
import React from "react";
|
||||
import type { PodContainer, IPodContainerStatus, Pod } from "../../../common/k8s-api/endpoints";
|
||||
import type { PodContainer, PodContainerStatus, Pod } from "../../../common/k8s-api/endpoints";
|
||||
import { DrawerItem } from "../drawer";
|
||||
import { cssNames, isDefined } from "../../utils";
|
||||
import { StatusBrick } from "../status-brick";
|
||||
@ -43,7 +43,7 @@ class NonInjectedPodDetailsContainer extends React.Component<PodDetailsContainer
|
||||
]);
|
||||
}
|
||||
|
||||
renderStatus(state: string, status: IPodContainerStatus | null | undefined) {
|
||||
renderStatus(state: string, status: PodContainerStatus | null | undefined) {
|
||||
const { ready = false, state: containerState = {}} = status ?? {};
|
||||
const { terminated } = containerState;
|
||||
|
||||
@ -56,7 +56,7 @@ class NonInjectedPodDetailsContainer extends React.Component<PodDetailsContainer
|
||||
);
|
||||
}
|
||||
|
||||
renderLastState(lastState: string, status: IPodContainerStatus | null | undefined) {
|
||||
renderLastState(lastState: string, status: PodContainerStatus | null | undefined) {
|
||||
const { lastState: lastContainerState = {}} = status ?? {};
|
||||
const { terminated } = lastContainerState;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user