mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Extracting dummy pods into mock file
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
209b67e1f1
commit
e1c4588156
@ -1,3 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* @jest-environment jsdom
|
||||||
|
*/
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import "@testing-library/jest-dom/extend-expect";
|
import "@testing-library/jest-dom/extend-expect";
|
||||||
import { render } from "@testing-library/react";
|
import { render } from "@testing-library/react";
|
||||||
@ -6,102 +10,7 @@ import selectEvent from "react-select-event";
|
|||||||
import { Pod } from "../../../api/endpoints";
|
import { Pod } from "../../../api/endpoints";
|
||||||
import { LogResourceSelector } from "../log-resource-selector";
|
import { LogResourceSelector } from "../log-resource-selector";
|
||||||
import { LogTabData } from "../log-tab.store";
|
import { LogTabData } from "../log-tab.store";
|
||||||
|
import { dockerPod, deploymentPod1 } from "./pod.mock";
|
||||||
const dummyPod = {
|
|
||||||
apiVersion: "v1",
|
|
||||||
kind: "dummy",
|
|
||||||
metadata: {
|
|
||||||
uid: "dummyPod",
|
|
||||||
name: "dummyPod",
|
|
||||||
creationTimestamp: "dummy",
|
|
||||||
resourceVersion: "dummy",
|
|
||||||
namespace: "default"
|
|
||||||
},
|
|
||||||
spec: {
|
|
||||||
initContainers: [] as any,
|
|
||||||
containers: [
|
|
||||||
{
|
|
||||||
name: "docker-exporter",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
serviceAccountName: "dummy",
|
|
||||||
serviceAccount: "dummy",
|
|
||||||
},
|
|
||||||
status: {
|
|
||||||
phase: "Running",
|
|
||||||
conditions: [{
|
|
||||||
type: "Running",
|
|
||||||
status: "Running",
|
|
||||||
lastProbeTime: 1,
|
|
||||||
lastTransitionTime: "Some time",
|
|
||||||
}],
|
|
||||||
hostIP: "dummy",
|
|
||||||
podIP: "dummy",
|
|
||||||
startTime: "dummy",
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const anotherDummyPod = {
|
|
||||||
apiVersion: "v1",
|
|
||||||
kind: "dummy",
|
|
||||||
metadata: {
|
|
||||||
uid: "anotherDummyPod",
|
|
||||||
name: "anotherDummyPod",
|
|
||||||
creationTimestamp: "dummy",
|
|
||||||
resourceVersion: "dummy",
|
|
||||||
namespace: "default",
|
|
||||||
ownerReferences: [{
|
|
||||||
apiVersion: "v1",
|
|
||||||
kind: "Deployment",
|
|
||||||
name: "super-deployment",
|
|
||||||
uid: "uuid",
|
|
||||||
controller: true,
|
|
||||||
blockOwnerDeletion: true,
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
spec: {
|
|
||||||
initContainers: [
|
|
||||||
{
|
|
||||||
name: "init-node-exporter",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "init-node-exporter-1",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
containers: [
|
|
||||||
{
|
|
||||||
name: "node-exporter",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "node-exporter-1",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
serviceAccountName: "dummy",
|
|
||||||
serviceAccount: "dummy",
|
|
||||||
},
|
|
||||||
status: {
|
|
||||||
phase: "Running",
|
|
||||||
conditions: [{
|
|
||||||
type: "Running",
|
|
||||||
status: "Running",
|
|
||||||
lastProbeTime: 1,
|
|
||||||
lastTransitionTime: "Some time",
|
|
||||||
}],
|
|
||||||
hostIP: "dummy",
|
|
||||||
podIP: "dummy",
|
|
||||||
startTime: "dummy",
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getComponent = (tabData: LogTabData) => {
|
const getComponent = (tabData: LogTabData) => {
|
||||||
return (
|
return (
|
||||||
@ -115,7 +24,7 @@ const getComponent = (tabData: LogTabData) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getOnePodTabData = (): LogTabData => {
|
const getOnePodTabData = (): LogTabData => {
|
||||||
const selectedPod = new Pod(dummyPod);
|
const selectedPod = new Pod(dockerPod);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pods: [] as Pod[],
|
pods: [] as Pod[],
|
||||||
@ -127,8 +36,8 @@ const getOnePodTabData = (): LogTabData => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getFewPodsTabData = (): LogTabData => {
|
const getFewPodsTabData = (): LogTabData => {
|
||||||
const selectedPod = new Pod(anotherDummyPod);
|
const selectedPod = new Pod(deploymentPod1);
|
||||||
const anotherPod = new Pod(dummyPod);
|
const anotherPod = new Pod(dockerPod);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pods: [anotherPod],
|
pods: [anotherPod],
|
||||||
@ -159,7 +68,7 @@ describe("<LogResourceSelector />", () => {
|
|||||||
const tabData = getOnePodTabData();
|
const tabData = getOnePodTabData();
|
||||||
const { getByText } = render(getComponent(tabData));
|
const { getByText } = render(getComponent(tabData));
|
||||||
|
|
||||||
expect(getByText("dummyPod")).toBeInTheDocument();
|
expect(getByText("dockerExporter")).toBeInTheDocument();
|
||||||
expect(getByText("docker-exporter")).toBeInTheDocument();
|
expect(getByText("docker-exporter")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -170,8 +79,8 @@ describe("<LogResourceSelector />", () => {
|
|||||||
|
|
||||||
selectEvent.openMenu(podSelector);
|
selectEvent.openMenu(podSelector);
|
||||||
|
|
||||||
expect(getByText("dummyPod")).toBeInTheDocument();
|
expect(getByText("dockerExporter")).toBeInTheDocument();
|
||||||
expect(getByText("anotherDummyPod")).toBeInTheDocument();
|
expect(getByText("deploymentPod1")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders sibling containers in dropdown", () => {
|
it("renders sibling containers in dropdown", () => {
|
||||||
|
|||||||
@ -6,166 +6,11 @@ import { podsStore } from "../../+workloads-pods/pods.store";
|
|||||||
import { Pod } from "../../../api/endpoints";
|
import { Pod } from "../../../api/endpoints";
|
||||||
import { dockStore } from "../dock.store";
|
import { dockStore } from "../dock.store";
|
||||||
import { LogTabStore } from "../log-tab.store";
|
import { LogTabStore } from "../log-tab.store";
|
||||||
|
import { deploymentPod1, deploymentPod2, dockerPod } from "./pod.mock";
|
||||||
|
|
||||||
let logTabStore: LogTabStore = null;
|
let logTabStore: LogTabStore = null;
|
||||||
|
|
||||||
const dummyPod = {
|
podsStore.items.push(new Pod(dockerPod));
|
||||||
apiVersion: "v1",
|
|
||||||
kind: "dummy",
|
|
||||||
metadata: {
|
|
||||||
uid: "dummyPod",
|
|
||||||
name: "dummyPod",
|
|
||||||
creationTimestamp: "dummy",
|
|
||||||
resourceVersion: "dummy",
|
|
||||||
namespace: "default"
|
|
||||||
},
|
|
||||||
spec: {
|
|
||||||
initContainers: [] as any,
|
|
||||||
containers: [
|
|
||||||
{
|
|
||||||
name: "docker-exporter",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
serviceAccountName: "dummy",
|
|
||||||
serviceAccount: "dummy",
|
|
||||||
},
|
|
||||||
status: {
|
|
||||||
phase: "Running",
|
|
||||||
conditions: [{
|
|
||||||
type: "Running",
|
|
||||||
status: "Running",
|
|
||||||
lastProbeTime: 1,
|
|
||||||
lastTransitionTime: "Some time",
|
|
||||||
}],
|
|
||||||
hostIP: "dummy",
|
|
||||||
podIP: "dummy",
|
|
||||||
startTime: "dummy",
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const deploymentPod1 = {
|
|
||||||
apiVersion: "v1",
|
|
||||||
kind: "dummy",
|
|
||||||
metadata: {
|
|
||||||
uid: "deploymentPod1",
|
|
||||||
name: "deploymentPod1",
|
|
||||||
creationTimestamp: "dummy",
|
|
||||||
resourceVersion: "dummy",
|
|
||||||
namespace: "default",
|
|
||||||
ownerReferences: [{
|
|
||||||
apiVersion: "v1",
|
|
||||||
kind: "Deployment",
|
|
||||||
name: "super-deployment",
|
|
||||||
uid: "uuid",
|
|
||||||
controller: true,
|
|
||||||
blockOwnerDeletion: true,
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
spec: {
|
|
||||||
initContainers: [
|
|
||||||
{
|
|
||||||
name: "init-node-exporter",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "init-node-exporter-1",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
containers: [
|
|
||||||
{
|
|
||||||
name: "node-exporter",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "node-exporter-1",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
serviceAccountName: "dummy",
|
|
||||||
serviceAccount: "dummy",
|
|
||||||
},
|
|
||||||
status: {
|
|
||||||
phase: "Running",
|
|
||||||
conditions: [{
|
|
||||||
type: "Running",
|
|
||||||
status: "Running",
|
|
||||||
lastProbeTime: 1,
|
|
||||||
lastTransitionTime: "Some time",
|
|
||||||
}],
|
|
||||||
hostIP: "dummy",
|
|
||||||
podIP: "dummy",
|
|
||||||
startTime: "dummy",
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const deploymentPod2 = {
|
|
||||||
apiVersion: "v1",
|
|
||||||
kind: "dummy",
|
|
||||||
metadata: {
|
|
||||||
uid: "deploymentPod2",
|
|
||||||
name: "deploymentPod2",
|
|
||||||
creationTimestamp: "dummy",
|
|
||||||
resourceVersion: "dummy",
|
|
||||||
namespace: "default",
|
|
||||||
ownerReferences: [{
|
|
||||||
apiVersion: "v1",
|
|
||||||
kind: "Deployment",
|
|
||||||
name: "super-deployment",
|
|
||||||
uid: "uuid",
|
|
||||||
controller: true,
|
|
||||||
blockOwnerDeletion: true,
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
spec: {
|
|
||||||
initContainers: [
|
|
||||||
{
|
|
||||||
name: "init-node-exporter",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "init-node-exporter-1",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
containers: [
|
|
||||||
{
|
|
||||||
name: "node-exporter",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "node-exporter-1",
|
|
||||||
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
|
||||||
imagePullPolicy: "pull"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
serviceAccountName: "dummy",
|
|
||||||
serviceAccount: "dummy",
|
|
||||||
},
|
|
||||||
status: {
|
|
||||||
phase: "Running",
|
|
||||||
conditions: [{
|
|
||||||
type: "Running",
|
|
||||||
status: "Running",
|
|
||||||
lastProbeTime: 1,
|
|
||||||
lastTransitionTime: "Some time",
|
|
||||||
}],
|
|
||||||
hostIP: "dummy",
|
|
||||||
podIP: "dummy",
|
|
||||||
startTime: "dummy",
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
podsStore.items.push(new Pod(dummyPod));
|
|
||||||
podsStore.items.push(new Pod(deploymentPod1));
|
podsStore.items.push(new Pod(deploymentPod1));
|
||||||
podsStore.items.push(new Pod(deploymentPod2));
|
podsStore.items.push(new Pod(deploymentPod2));
|
||||||
|
|
||||||
@ -175,7 +20,7 @@ describe("log tab store", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("creates log tab without sibling pods", () => {
|
it("creates log tab without sibling pods", () => {
|
||||||
const selectedPod = new Pod(dummyPod);
|
const selectedPod = new Pod(dockerPod);
|
||||||
const selectedContainer = selectedPod.getAllContainers()[0];
|
const selectedContainer = selectedPod.getAllContainers()[0];
|
||||||
|
|
||||||
logTabStore.createPodTab({
|
logTabStore.createPodTab({
|
||||||
|
|||||||
155
src/renderer/components/dock/__test__/pod.mock.ts
Normal file
155
src/renderer/components/dock/__test__/pod.mock.ts
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
export const dockerPod = {
|
||||||
|
apiVersion: "v1",
|
||||||
|
kind: "dummy",
|
||||||
|
metadata: {
|
||||||
|
uid: "dockerExporter",
|
||||||
|
name: "dockerExporter",
|
||||||
|
creationTimestamp: "dummy",
|
||||||
|
resourceVersion: "dummy",
|
||||||
|
namespace: "default"
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
initContainers: [] as any,
|
||||||
|
containers: [
|
||||||
|
{
|
||||||
|
name: "docker-exporter",
|
||||||
|
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||||
|
imagePullPolicy: "pull"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
serviceAccountName: "dummy",
|
||||||
|
serviceAccount: "dummy",
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
phase: "Running",
|
||||||
|
conditions: [{
|
||||||
|
type: "Running",
|
||||||
|
status: "Running",
|
||||||
|
lastProbeTime: 1,
|
||||||
|
lastTransitionTime: "Some time",
|
||||||
|
}],
|
||||||
|
hostIP: "dummy",
|
||||||
|
podIP: "dummy",
|
||||||
|
startTime: "dummy",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deploymentPod1 = {
|
||||||
|
apiVersion: "v1",
|
||||||
|
kind: "dummy",
|
||||||
|
metadata: {
|
||||||
|
uid: "deploymentPod1",
|
||||||
|
name: "deploymentPod1",
|
||||||
|
creationTimestamp: "dummy",
|
||||||
|
resourceVersion: "dummy",
|
||||||
|
namespace: "default",
|
||||||
|
ownerReferences: [{
|
||||||
|
apiVersion: "v1",
|
||||||
|
kind: "Deployment",
|
||||||
|
name: "super-deployment",
|
||||||
|
uid: "uuid",
|
||||||
|
controller: true,
|
||||||
|
blockOwnerDeletion: true,
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
initContainers: [
|
||||||
|
{
|
||||||
|
name: "init-node-exporter",
|
||||||
|
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||||
|
imagePullPolicy: "pull"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "init-node-exporter-1",
|
||||||
|
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||||
|
imagePullPolicy: "pull"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
containers: [
|
||||||
|
{
|
||||||
|
name: "node-exporter",
|
||||||
|
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||||
|
imagePullPolicy: "pull"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "node-exporter-1",
|
||||||
|
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||||
|
imagePullPolicy: "pull"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
serviceAccountName: "dummy",
|
||||||
|
serviceAccount: "dummy",
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
phase: "Running",
|
||||||
|
conditions: [{
|
||||||
|
type: "Running",
|
||||||
|
status: "Running",
|
||||||
|
lastProbeTime: 1,
|
||||||
|
lastTransitionTime: "Some time",
|
||||||
|
}],
|
||||||
|
hostIP: "dummy",
|
||||||
|
podIP: "dummy",
|
||||||
|
startTime: "dummy",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deploymentPod2 = {
|
||||||
|
apiVersion: "v1",
|
||||||
|
kind: "dummy",
|
||||||
|
metadata: {
|
||||||
|
uid: "deploymentPod2",
|
||||||
|
name: "deploymentPod2",
|
||||||
|
creationTimestamp: "dummy",
|
||||||
|
resourceVersion: "dummy",
|
||||||
|
namespace: "default",
|
||||||
|
ownerReferences: [{
|
||||||
|
apiVersion: "v1",
|
||||||
|
kind: "Deployment",
|
||||||
|
name: "super-deployment",
|
||||||
|
uid: "uuid",
|
||||||
|
controller: true,
|
||||||
|
blockOwnerDeletion: true,
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
initContainers: [
|
||||||
|
{
|
||||||
|
name: "init-node-exporter",
|
||||||
|
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||||
|
imagePullPolicy: "pull"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "init-node-exporter-1",
|
||||||
|
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||||
|
imagePullPolicy: "pull"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
containers: [
|
||||||
|
{
|
||||||
|
name: "node-exporter",
|
||||||
|
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||||
|
imagePullPolicy: "pull"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "node-exporter-1",
|
||||||
|
image: "docker.io/prom/node-exporter:v1.0.0-rc.0",
|
||||||
|
imagePullPolicy: "pull"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
serviceAccountName: "dummy",
|
||||||
|
serviceAccount: "dummy",
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
phase: "Running",
|
||||||
|
conditions: [{
|
||||||
|
type: "Running",
|
||||||
|
status: "Running",
|
||||||
|
lastProbeTime: 1,
|
||||||
|
lastTransitionTime: "Some time",
|
||||||
|
}],
|
||||||
|
hostIP: "dummy",
|
||||||
|
podIP: "dummy",
|
||||||
|
startTime: "dummy",
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user