mirror of
https://github.com/lensapp/lens.git
synced 2024-09-11 09:25:26 +03:00
chore: move kube-api related tests from core
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
e8be89eb51
commit
7b8bd1e758
@ -1,51 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
|
||||
import storesAndApisCanBeCreatedInjectable from "../../../renderer/stores-apis-can-be-created.injectable";
|
||||
import apiKubeInjectable from "../../../renderer/k8s/api-kube.injectable";
|
||||
import deploymentApiInjectable from "../endpoints/deployment.api.injectable";
|
||||
import type { KubeJsonApi, DeploymentApi } from "@k8slens/kube-api";
|
||||
|
||||
describe("DeploymentApi", () => {
|
||||
let deploymentApi: DeploymentApi;
|
||||
let kubeJsonApi: jest.Mocked<KubeJsonApi>;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
kubeJsonApi = {
|
||||
getResponse: jest.fn(),
|
||||
get: jest.fn(),
|
||||
post: jest.fn(),
|
||||
put: jest.fn(),
|
||||
patch: jest.fn(),
|
||||
del: jest.fn(),
|
||||
} as never;
|
||||
di.override(apiKubeInjectable, () => kubeJsonApi);
|
||||
|
||||
deploymentApi = di.inject(deploymentApiInjectable);
|
||||
});
|
||||
|
||||
describe("scale", () => {
|
||||
it("requests Kubernetes API with PATCH verb and correct amount of replicas", async () => {
|
||||
await deploymentApi.scale({ namespace: "default", name: "deployment-1" }, 5);
|
||||
|
||||
expect(kubeJsonApi.patch).toHaveBeenCalledWith("/apis/apps/v1/namespaces/default/deployments/deployment-1/scale", {
|
||||
data: {
|
||||
spec: {
|
||||
replicas: 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"content-type": "application/merge-patch+json",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { KubeJsonApi, DeploymentApi } from "@k8slens/kube-api";
|
||||
|
||||
describe("DeploymentApi", () => {
|
||||
let deploymentApi: DeploymentApi;
|
||||
let kubeJsonApi: jest.Mocked<KubeJsonApi>;
|
||||
|
||||
beforeEach(() => {
|
||||
kubeJsonApi = {
|
||||
getResponse: jest.fn(),
|
||||
get: jest.fn(),
|
||||
post: jest.fn(),
|
||||
put: jest.fn(),
|
||||
patch: jest.fn(),
|
||||
del: jest.fn(),
|
||||
} as never;
|
||||
|
||||
deploymentApi = new DeploymentApi({
|
||||
logger: {
|
||||
info: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
error: jest.fn(),
|
||||
} as any,
|
||||
maybeKubeApi: kubeJsonApi,
|
||||
});
|
||||
});
|
||||
|
||||
describe("scale", () => {
|
||||
it("requests Kubernetes API with PATCH verb and correct amount of replicas", async () => {
|
||||
await deploymentApi.scale({ namespace: "default", name: "deployment-1" }, 5);
|
||||
|
||||
expect(kubeJsonApi.patch).toHaveBeenCalledWith(
|
||||
"/apis/apps/v1/namespaces/default/deployments/deployment-1/scale",
|
||||
{
|
||||
data: {
|
||||
spec: {
|
||||
replicas: 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"content-type": "application/merge-patch+json",
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
@ -3,32 +3,32 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import storesAndApisCanBeCreatedInjectable from "../../../renderer/stores-apis-can-be-created.injectable";
|
||||
import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
|
||||
import apiKubeInjectable from "../../../renderer/k8s/api-kube.injectable";
|
||||
import statefulSetApiInjectable from "../endpoints/stateful-set.api.injectable";
|
||||
import type { KubeJsonApi, StatefulSetApi } from "@k8slens/kube-api";
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import { KubeJsonApi, StatefulSetApi } from "@k8slens/kube-api";
|
||||
import { flushPromises } from "@k8slens/test-utils";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
|
||||
describe("StatefulSetApi", () => {
|
||||
let statefulSetApi: StatefulSetApi;
|
||||
let kubeJsonApi: KubeJsonApi;
|
||||
let kubeJsonApiPatchMock: AsyncFnMock<KubeJsonApi["patch"]>;
|
||||
let kubeJsonApiGetMock: AsyncFnMock<KubeJsonApi["get"]>;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
kubeJsonApiPatchMock = asyncFn();
|
||||
kubeJsonApiGetMock = asyncFn();
|
||||
di.override(apiKubeInjectable, () => ({
|
||||
kubeJsonApiGetMock = asyncFn<KubeJsonApi["get"]>();
|
||||
kubeJsonApiPatchMock = asyncFn<KubeJsonApi["patch"]>();
|
||||
kubeJsonApi = {
|
||||
get: kubeJsonApiGetMock,
|
||||
patch: kubeJsonApiPatchMock,
|
||||
} as Partial<KubeJsonApi> as KubeJsonApi));
|
||||
|
||||
statefulSetApi = di.inject(statefulSetApiInjectable);
|
||||
} as Partial<KubeJsonApi> as KubeJsonApi;
|
||||
statefulSetApi = new StatefulSetApi({
|
||||
logger: {
|
||||
info: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
error: jest.fn(),
|
||||
} as any,
|
||||
maybeKubeApi: kubeJsonApi,
|
||||
});
|
||||
});
|
||||
|
||||
describe("scale", () => {
|
||||
@ -36,18 +36,21 @@ describe("StatefulSetApi", () => {
|
||||
const req = statefulSetApi.scale({ namespace: "default", name: "statefulset-1" }, 5);
|
||||
|
||||
await flushPromises();
|
||||
expect(kubeJsonApiPatchMock).toHaveBeenCalledWith("/apis/apps/v1/namespaces/default/statefulsets/statefulset-1/scale", {
|
||||
data: {
|
||||
spec: {
|
||||
replicas: 5,
|
||||
expect(kubeJsonApiPatchMock).toHaveBeenCalledWith(
|
||||
"/apis/apps/v1/namespaces/default/statefulsets/statefulset-1/scale",
|
||||
{
|
||||
data: {
|
||||
spec: {
|
||||
replicas: 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"content-type": "application/merge-patch+json",
|
||||
{
|
||||
headers: {
|
||||
"content-type": "application/merge-patch+json",
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
|
||||
await kubeJsonApiPatchMock.resolve({});
|
||||
await req;
|
||||
@ -57,8 +60,8 @@ describe("StatefulSetApi", () => {
|
||||
const req = statefulSetApi.getReplicas({ namespace: "default", name: "statefulset-1" });
|
||||
|
||||
await flushPromises();
|
||||
expect(kubeJsonApiGetMock).toHaveBeenCalledWith("/apis/apps/v1/namespaces/default/statefulsets/statefulset-1/scale");
|
||||
await kubeJsonApiGetMock.resolve({ status: { replicas: 10 }});
|
||||
expect(kubeJsonApi.get).toHaveBeenCalledWith("/apis/apps/v1/namespaces/default/statefulsets/statefulset-1/scale");
|
||||
await kubeJsonApiGetMock.resolve({ status: { replicas: 10 } });
|
||||
|
||||
expect(await req).toBe(10);
|
||||
});
|
Loading…
Reference in New Issue
Block a user