mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix tests and impl
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
7c5b14123c
commit
25d6b544ea
@ -6,8 +6,6 @@ import type { ApiManager } from "../api-manager";
|
|||||||
import type { IngressApi } from "../endpoints";
|
import type { IngressApi } from "../endpoints";
|
||||||
import { Ingress, HorizontalPodAutoscalerApi } from "../endpoints";
|
import { Ingress, HorizontalPodAutoscalerApi } from "../endpoints";
|
||||||
import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
|
import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
|
||||||
import type { Fetch } from "../../fetch/fetch.injectable";
|
|
||||||
import fetchInjectable from "../../fetch/fetch.injectable";
|
|
||||||
import type { AsyncFnMock } from "@async-fn/jest";
|
import type { AsyncFnMock } from "@async-fn/jest";
|
||||||
import asyncFn from "@async-fn/jest";
|
import asyncFn from "@async-fn/jest";
|
||||||
import { flushPromises } from "@k8slens/test-utils";
|
import { flushPromises } from "@k8slens/test-utils";
|
||||||
@ -23,17 +21,19 @@ import ingressApiInjectable from "../endpoints/ingress.api.injectable";
|
|||||||
import loggerInjectable from "../../logger.injectable";
|
import loggerInjectable from "../../logger.injectable";
|
||||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||||
import { Cluster } from "../../cluster/cluster";
|
import { Cluster } from "../../cluster/cluster";
|
||||||
|
import type { LensFetch } from "../../../features/lens-fetch/common/lens-fetch.injectable";
|
||||||
|
import lensFetchInjectable from "../../../features/lens-fetch/common/lens-fetch.injectable";
|
||||||
|
|
||||||
describe("KubeApi", () => {
|
describe("KubeApi", () => {
|
||||||
let fetchMock: AsyncFnMock<Fetch>;
|
let lensFetchMock: AsyncFnMock<LensFetch>;
|
||||||
let apiManager: ApiManager;
|
let apiManager: ApiManager;
|
||||||
let di: DiContainer;
|
let di: DiContainer;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
di = getDiForUnitTesting();
|
di = getDiForUnitTesting();
|
||||||
|
|
||||||
fetchMock = asyncFn();
|
lensFetchMock = asyncFn();
|
||||||
di.override(fetchInjectable, () => fetchMock);
|
di.override(lensFetchInjectable, () => lensFetchMock);
|
||||||
|
|
||||||
di.override(directoryForUserDataInjectable, () => "/some-user-store-path");
|
di.override(directoryForUserDataInjectable, () => "/some-user-store-path");
|
||||||
di.override(directoryForKubeConfigsInjectable, () => "/some-kube-configs");
|
di.override(directoryForKubeConfigsInjectable, () => "/some-kube-configs");
|
||||||
@ -70,8 +70,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests version list from the api group from the initial apiBase", () => {
|
it("requests version list from the api group from the initial apiBase", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/networking.k8s.io",
|
"/api-kube/apis/networking.k8s.io",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -83,8 +83,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the version list from the api group resolves", () => {
|
describe("when the version list from the api group resolves", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io"],
|
["/api-kube/apis/networking.k8s.io"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io", JSON.stringify({
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io", JSON.stringify({
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
kind: "APIGroup",
|
kind: "APIGroup",
|
||||||
@ -108,8 +108,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests resources from the versioned api group from the initial apiBase", () => {
|
it("requests resources from the versioned api group from the initial apiBase", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1",
|
"/api-kube/apis/networking.k8s.io/v1",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -121,8 +121,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when resource request fulfills with a resource", () => {
|
describe("when resource request fulfills with a resource", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1"],
|
["/api-kube/apis/networking.k8s.io/v1"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1", JSON.stringify({
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1", JSON.stringify({
|
||||||
resources: [{
|
resources: [{
|
||||||
name: "ingresses",
|
name: "ingresses",
|
||||||
@ -132,8 +132,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("makes the request to get the resource", () => {
|
it("makes the request to get the resource", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo",
|
"/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -159,8 +159,8 @@ describe("KubeApi", () => {
|
|||||||
let result: Ingress | null;
|
let result: Ingress | null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo"],
|
["/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo", JSON.stringify({})),
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo", JSON.stringify({})),
|
||||||
);
|
);
|
||||||
result = await getCall;
|
result = await getCall;
|
||||||
@ -184,8 +184,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("makes the request to get the resource", () => {
|
it("makes the request to get the resource", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo1",
|
"/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo1",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -199,8 +199,8 @@ describe("KubeApi", () => {
|
|||||||
let result: Ingress | null;
|
let result: Ingress | null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo1"],
|
["/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo1"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo1", JSON.stringify({})),
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo1", JSON.stringify({})),
|
||||||
);
|
);
|
||||||
result = await getCall;
|
result = await getCall;
|
||||||
@ -217,8 +217,8 @@ describe("KubeApi", () => {
|
|||||||
let result: Ingress | null;
|
let result: Ingress | null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo"],
|
["/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo", JSON.stringify({
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo", JSON.stringify({
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
kind: "Ingress",
|
kind: "Ingress",
|
||||||
@ -251,8 +251,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("makes the request to get the resource", () => {
|
it("makes the request to get the resource", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo1",
|
"/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo1",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -266,8 +266,8 @@ describe("KubeApi", () => {
|
|||||||
let result: Ingress | null;
|
let result: Ingress | null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo1"],
|
["/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo1"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo1", JSON.stringify({})),
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1/namespaces/default/ingresses/foo1", JSON.stringify({})),
|
||||||
);
|
);
|
||||||
result = await getCall;
|
result = await getCall;
|
||||||
@ -283,8 +283,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when resource request fulfills with no resource", () => {
|
describe("when resource request fulfills with no resource", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1"],
|
["/api-kube/apis/networking.k8s.io/v1"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1", JSON.stringify({
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1", JSON.stringify({
|
||||||
resources: [],
|
resources: [],
|
||||||
})),
|
})),
|
||||||
@ -292,8 +292,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests resources from the second versioned api group from the initial apiBase", () => {
|
it("requests resources from the second versioned api group from the initial apiBase", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1",
|
"/api-kube/apis/networking.k8s.io/v1beta1",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -307,8 +307,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when resource request fulfills with a resource", () => {
|
describe("when resource request fulfills with a resource", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1"],
|
["/api-kube/apis/networking.k8s.io/v1beta1"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1", JSON.stringify({
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1", JSON.stringify({
|
||||||
resources: [{
|
resources: [{
|
||||||
name: "ingresses",
|
name: "ingresses",
|
||||||
@ -318,8 +318,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("makes the request to get the resource", () => {
|
it("makes the request to get the resource", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo",
|
"/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -349,8 +349,8 @@ describe("KubeApi", () => {
|
|||||||
let result: Ingress | null;
|
let result: Ingress | null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo"],
|
["/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo", JSON.stringify({})),
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo", JSON.stringify({})),
|
||||||
);
|
);
|
||||||
result = await getCall;
|
result = await getCall;
|
||||||
@ -374,8 +374,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("makes the request to get the resource", () => {
|
it("makes the request to get the resource", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo1",
|
"/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo1",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -389,8 +389,8 @@ describe("KubeApi", () => {
|
|||||||
let result: Ingress | null;
|
let result: Ingress | null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo1"],
|
["/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo1"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo1", JSON.stringify({})),
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo1", JSON.stringify({})),
|
||||||
);
|
);
|
||||||
result = await getCall;
|
result = await getCall;
|
||||||
@ -407,8 +407,8 @@ describe("KubeApi", () => {
|
|||||||
let result: Ingress | null;
|
let result: Ingress | null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo"],
|
["/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo", JSON.stringify({
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo", JSON.stringify({
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
kind: "Ingress",
|
kind: "Ingress",
|
||||||
@ -441,8 +441,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("makes the request to get the resource", () => {
|
it("makes the request to get the resource", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo1",
|
"/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo1",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -456,8 +456,8 @@ describe("KubeApi", () => {
|
|||||||
let result: Ingress | null;
|
let result: Ingress | null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo1"],
|
["/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo1"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo1", JSON.stringify({})),
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1/namespaces/default/ingresses/foo1", JSON.stringify({})),
|
||||||
);
|
);
|
||||||
result = await getCall;
|
result = await getCall;
|
||||||
@ -475,8 +475,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the version list from the api group resolves with no versions", () => {
|
describe("when the version list from the api group resolves with no versions", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io"],
|
["/api-kube/apis/networking.k8s.io"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io", JSON.stringify({
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/networking.k8s.io", JSON.stringify({
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"status": "Failure",
|
"status": "Failure",
|
||||||
@ -496,8 +496,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests the resources from the base api url from the fallback api", () => {
|
it("requests the resources from the base api url from the fallback api", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/extensions",
|
"/api-kube/apis/extensions",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -509,8 +509,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when resource request fulfills with a resource", () => {
|
describe("when resource request fulfills with a resource", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/extensions"],
|
["/api-kube/apis/extensions"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/extensions", JSON.stringify({
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/extensions", JSON.stringify({
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
kind: "APIGroup",
|
kind: "APIGroup",
|
||||||
@ -530,8 +530,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests resource versions from the versioned api group from the fallback apiBase", () => {
|
it("requests resource versions from the versioned api group from the fallback apiBase", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1",
|
"/api-kube/apis/extensions/v1beta1",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -543,8 +543,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the preferred version request resolves to v1beta1", () => {
|
describe("when the preferred version request resolves to v1beta1", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1"],
|
["/api-kube/apis/extensions/v1beta1"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/extensions", JSON.stringify({
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/extensions", JSON.stringify({
|
||||||
resources: [{
|
resources: [{
|
||||||
name: "ingresses",
|
name: "ingresses",
|
||||||
@ -554,8 +554,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("makes the request to get the resource", () => {
|
it("makes the request to get the resource", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo",
|
"/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -581,8 +581,8 @@ describe("KubeApi", () => {
|
|||||||
let result: Ingress | null;
|
let result: Ingress | null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo"],
|
["/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo", JSON.stringify({})),
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo", JSON.stringify({})),
|
||||||
);
|
);
|
||||||
result = await getCall;
|
result = await getCall;
|
||||||
@ -606,8 +606,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("makes the request to get the resource", () => {
|
it("makes the request to get the resource", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo1",
|
"/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo1",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -621,8 +621,8 @@ describe("KubeApi", () => {
|
|||||||
let result: Ingress | null;
|
let result: Ingress | null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo1"],
|
["/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo1"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo1", JSON.stringify({})),
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo1", JSON.stringify({})),
|
||||||
);
|
);
|
||||||
result = await getCall;
|
result = await getCall;
|
||||||
@ -639,8 +639,8 @@ describe("KubeApi", () => {
|
|||||||
let result: Ingress | null;
|
let result: Ingress | null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo"],
|
["/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo", JSON.stringify({
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo", JSON.stringify({
|
||||||
apiVersion: "v1beta1",
|
apiVersion: "v1beta1",
|
||||||
kind: "Ingress",
|
kind: "Ingress",
|
||||||
@ -673,8 +673,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("makes the request to get the resource", () => {
|
it("makes the request to get the resource", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo1",
|
"/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo1",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -688,8 +688,8 @@ describe("KubeApi", () => {
|
|||||||
let result: Ingress | null;
|
let result: Ingress | null;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo1"],
|
["/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo1"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo1", JSON.stringify({})),
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/extensions/v1beta1/namespaces/default/ingresses/foo1", JSON.stringify({})),
|
||||||
);
|
);
|
||||||
result = await getCall;
|
result = await getCall;
|
||||||
@ -733,8 +733,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests version list from the api group from the initial apiBase", () => {
|
it("requests version list from the api group from the initial apiBase", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/autoscaling",
|
"/api-kube/apis/autoscaling",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -746,8 +746,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the version list from the api group resolves with preferredVersion in allowed version", () => {
|
describe("when the version list from the api group resolves with preferredVersion in allowed version", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/autoscaling"],
|
["/api-kube/apis/autoscaling"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/autoscaling", JSON.stringify({
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/autoscaling", JSON.stringify({
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
kind: "APIGroup",
|
kind: "APIGroup",
|
||||||
@ -771,8 +771,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests resources from the preferred version api group from the initial apiBase", () => {
|
it("requests resources from the preferred version api group from the initial apiBase", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/autoscaling/v1",
|
"/api-kube/apis/autoscaling/v1",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -785,8 +785,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the version list from the api group resolves with preferredVersion not allowed version", () => {
|
describe("when the version list from the api group resolves with preferredVersion not allowed version", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["https://127.0.0.1:12345/api-kube/apis/autoscaling"],
|
["/api-kube/apis/autoscaling"],
|
||||||
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/autoscaling", JSON.stringify({
|
createMockResponseFromString("https://127.0.0.1:12345/api-kube/apis/autoscaling", JSON.stringify({
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
kind: "APIGroup",
|
kind: "APIGroup",
|
||||||
@ -814,8 +814,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests resources from the non preferred version from the initial apiBase", () => {
|
it("requests resources from the non preferred version from the initial apiBase", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"https://127.0.0.1:12345/api-kube/apis/autoscaling/v2",
|
"/api-kube/apis/autoscaling/v2",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
|
|||||||
@ -9,34 +9,19 @@ import { PassThrough } from "stream";
|
|||||||
import type { DeploymentApi, NamespaceApi } from "../endpoints";
|
import type { DeploymentApi, NamespaceApi } from "../endpoints";
|
||||||
import { Deployment, Pod, PodApi } from "../endpoints";
|
import { Deployment, Pod, PodApi } from "../endpoints";
|
||||||
import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
|
import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
|
||||||
import type { Fetch } from "../../fetch/fetch.injectable";
|
import type { CreateKubeApiForRemoteCluster } from "../create-kube-api-for-remote-cluster.injectable";
|
||||||
import fetchInjectable from "../../fetch/fetch.injectable";
|
import createKubeApiForRemoteClusterInjectable from "../create-kube-api-for-remote-cluster.injectable";
|
||||||
import type {
|
|
||||||
CreateKubeApiForRemoteCluster,
|
|
||||||
} from "../create-kube-api-for-remote-cluster.injectable";
|
|
||||||
import createKubeApiForRemoteClusterInjectable
|
|
||||||
from "../create-kube-api-for-remote-cluster.injectable";
|
|
||||||
import type { AsyncFnMock } from "@async-fn/jest";
|
import type { AsyncFnMock } from "@async-fn/jest";
|
||||||
import asyncFn from "@async-fn/jest";
|
import asyncFn from "@async-fn/jest";
|
||||||
import { flushPromises } from "@k8slens/test-utils";
|
import { flushPromises } from "@k8slens/test-utils";
|
||||||
import createKubeJsonApiInjectable from "../create-kube-json-api.injectable";
|
|
||||||
import type { IKubeWatchEvent } from "../kube-watch-event";
|
import type { IKubeWatchEvent } from "../kube-watch-event";
|
||||||
import type { KubeJsonApiDataFor, KubeStatusData } from "../kube-object";
|
import type { KubeJsonApiDataFor, KubeStatusData } from "../kube-object";
|
||||||
import setupAutoRegistrationInjectable
|
import setupAutoRegistrationInjectable from "../../../renderer/before-frame-starts/runnables/setup-auto-registration.injectable";
|
||||||
from "../../../renderer/before-frame-starts/runnables/setup-auto-registration.injectable";
|
import { createMockResponseFromStream, createMockResponseFromString } from "../../../test-utils/mock-responses";
|
||||||
import {
|
import storesAndApisCanBeCreatedInjectable from "../../../renderer/stores-apis-can-be-created.injectable";
|
||||||
createMockResponseFromStream,
|
import directoryForUserDataInjectable from "../../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||||
createMockResponseFromString,
|
import hostedClusterInjectable from "../../../renderer/cluster-frame-context/hosted-cluster.injectable";
|
||||||
} from "../../../test-utils/mock-responses";
|
import directoryForKubeConfigsInjectable from "../../app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable";
|
||||||
import storesAndApisCanBeCreatedInjectable
|
|
||||||
from "../../../renderer/stores-apis-can-be-created.injectable";
|
|
||||||
import directoryForUserDataInjectable
|
|
||||||
from "../../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
|
||||||
import hostedClusterInjectable
|
|
||||||
from "../../../renderer/cluster-frame-context/hosted-cluster.injectable";
|
|
||||||
import directoryForKubeConfigsInjectable
|
|
||||||
from "../../app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable";
|
|
||||||
import apiKubeInjectable from "../../../renderer/k8s/api-kube.injectable";
|
|
||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import deploymentApiInjectable from "../endpoints/deployment.api.injectable";
|
import deploymentApiInjectable from "../endpoints/deployment.api.injectable";
|
||||||
import podApiInjectable from "../endpoints/pod.api.injectable";
|
import podApiInjectable from "../endpoints/pod.api.injectable";
|
||||||
@ -46,6 +31,10 @@ import namespaceApiInjectable from "../endpoints/namespace.api.injectable";
|
|||||||
// eslint-disable-next-line no-restricted-imports
|
// eslint-disable-next-line no-restricted-imports
|
||||||
import { PodsApi } from "../../../extensions/common-api/k8s-api";
|
import { PodsApi } from "../../../extensions/common-api/k8s-api";
|
||||||
import { Cluster } from "../../cluster/cluster";
|
import { Cluster } from "../../cluster/cluster";
|
||||||
|
import type { LensFetch } from "../../../features/lens-fetch/common/lens-fetch.injectable";
|
||||||
|
import lensFetchInjectable from "../../../features/lens-fetch/common/lens-fetch.injectable";
|
||||||
|
import type { Fetch } from "../../fetch/fetch.injectable";
|
||||||
|
import fetchInjectable from "../../fetch/fetch.injectable";
|
||||||
|
|
||||||
describe("createKubeApiForRemoteCluster", () => {
|
describe("createKubeApiForRemoteCluster", () => {
|
||||||
let createKubeApiForRemoteCluster: CreateKubeApiForRemoteCluster;
|
let createKubeApiForRemoteCluster: CreateKubeApiForRemoteCluster;
|
||||||
@ -149,7 +138,7 @@ describe("createKubeApiForRemoteCluster", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("KubeApi", () => {
|
describe("KubeApi", () => {
|
||||||
let fetchMock: AsyncFnMock<Fetch>;
|
let lensFetchMock: AsyncFnMock<LensFetch>;
|
||||||
let di: DiContainer;
|
let di: DiContainer;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@ -159,10 +148,8 @@ describe("KubeApi", () => {
|
|||||||
di.override(directoryForKubeConfigsInjectable, () => "/some-kube-configs");
|
di.override(directoryForKubeConfigsInjectable, () => "/some-kube-configs");
|
||||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||||
|
|
||||||
fetchMock = asyncFn();
|
lensFetchMock = asyncFn();
|
||||||
di.override(fetchInjectable, () => fetchMock);
|
di.override(lensFetchInjectable, () => lensFetchMock);
|
||||||
|
|
||||||
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
|
||||||
|
|
||||||
di.override(hostedClusterInjectable, () => new Cluster({
|
di.override(hostedClusterInjectable, () => new Cluster({
|
||||||
contextName: "some-context-name",
|
contextName: "some-context-name",
|
||||||
@ -172,11 +159,6 @@ describe("KubeApi", () => {
|
|||||||
clusterServerUrl: "https://localhost:8080",
|
clusterServerUrl: "https://localhost:8080",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
di.override(apiKubeInjectable, () => createKubeJsonApi({
|
|
||||||
serverAddress: `http://127.0.0.1:9999`,
|
|
||||||
apiBase: "/api-kube",
|
|
||||||
}));
|
|
||||||
|
|
||||||
const setupAutoRegistration = di.inject(setupAutoRegistrationInjectable);
|
const setupAutoRegistration = di.inject(setupAutoRegistrationInjectable);
|
||||||
|
|
||||||
setupAutoRegistration.run();
|
setupAutoRegistration.run();
|
||||||
@ -202,8 +184,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests a patch using strategic merge", () => {
|
it("requests a patch using strategic merge", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test",
|
"/api-kube/apis/apps/v1/namespaces/default/deployments/test",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/strategic-merge-patch+json",
|
"content-type": "application/strategic-merge-patch+json",
|
||||||
@ -216,8 +198,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the patch request resolves with data", () => {
|
describe("when the patch request resolves with data", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test"],
|
["/api-kube/apis/apps/v1/namespaces/default/deployments/test"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", JSON.stringify({
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", JSON.stringify({
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
kind: "Deployment",
|
kind: "Deployment",
|
||||||
@ -253,8 +235,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests a patch using json merge", () => {
|
it("requests a patch using json merge", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test",
|
"/api-kube/apis/apps/v1/namespaces/default/deployments/test",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json-patch+json",
|
"content-type": "application/json-patch+json",
|
||||||
@ -269,8 +251,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the patch request resolves with data", () => {
|
describe("when the patch request resolves with data", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test"],
|
["/api-kube/apis/apps/v1/namespaces/default/deployments/test"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", JSON.stringify({
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", JSON.stringify({
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
kind: "Deployment",
|
kind: "Deployment",
|
||||||
@ -308,8 +290,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests a patch using json merge", () => {
|
it("requests a patch using json merge", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test",
|
"/api-kube/apis/apps/v1/namespaces/default/deployments/test",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/merge-patch+json",
|
"content-type": "application/merge-patch+json",
|
||||||
@ -322,8 +304,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the patch request resolves with data", () => {
|
describe("when the patch request resolves with data", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test"],
|
["/api-kube/apis/apps/v1/namespaces/default/deployments/test"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", JSON.stringify({
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", JSON.stringify({
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
kind: "Deployment",
|
kind: "Deployment",
|
||||||
@ -365,8 +347,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests deleting pod in default namespace", () => {
|
it("requests deleting pod in default namespace", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background",
|
"/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -378,8 +360,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when request resolves", () => {
|
describe("when request resolves", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
fetchMock.resolveSpecific(
|
lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background"],
|
["/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background", "{}"),
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background", "{}"),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -401,8 +383,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests deleting pod in default namespace", () => {
|
it("requests deleting pod in default namespace", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background",
|
"/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -414,8 +396,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when request resolves", () => {
|
describe("when request resolves", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
fetchMock.resolveSpecific(
|
lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background"],
|
["/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background", "{}"),
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background", "{}"),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -437,8 +419,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests deleting pod in given namespace", () => {
|
it("requests deleting pod in given namespace", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo?propagationPolicy=Background",
|
"/api-kube/api/v1/namespaces/test/pods/foo?propagationPolicy=Background",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -450,8 +432,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when request resolves", () => {
|
describe("when request resolves", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
fetchMock.resolveSpecific(
|
lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo?propagationPolicy=Background"],
|
["/api-kube/api/v1/namespaces/test/pods/foo?propagationPolicy=Background"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo?propagationPolicy=Background", "{}"),
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo?propagationPolicy=Background", "{}"),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -470,8 +452,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests evicting a pod in given namespace", () => {
|
it("requests evicting a pod in given namespace", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo/eviction",
|
"/api-kube/api/v1/namespaces/test/pods/foo/eviction",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -482,8 +464,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should resolve the call with >=200 <300 http code", async () => {
|
it("should resolve the call with >=200 <300 http code", async () => {
|
||||||
fetchMock.resolveSpecific(
|
lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo/eviction"],
|
["/api-kube/api/v1/namespaces/test/pods/foo/eviction"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo/eviction", JSON.stringify({
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo/eviction", JSON.stringify({
|
||||||
apiVersion: "policy/v1",
|
apiVersion: "policy/v1",
|
||||||
kind: "Status",
|
kind: "Status",
|
||||||
@ -496,8 +478,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should throw in case of error", async () => {
|
it("should throw in case of error", async () => {
|
||||||
fetchMock.resolveSpecific(
|
lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo/eviction"],
|
["/api-kube/api/v1/namespaces/test/pods/foo/eviction"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo/eviction", JSON.stringify({
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo/eviction", JSON.stringify({
|
||||||
apiVersion: "policy/v1",
|
apiVersion: "policy/v1",
|
||||||
kind: "Status",
|
kind: "Status",
|
||||||
@ -511,7 +493,7 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("deleting namespaces (cluser scoped resource)", () => {
|
describe("deleting namespaces (cluster scoped resource)", () => {
|
||||||
let api: NamespaceApi;
|
let api: NamespaceApi;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -529,8 +511,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests deleting Namespace without namespace", () => {
|
it("requests deleting Namespace without namespace", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background",
|
"/api-kube/api/v1/namespaces/foo?propagationPolicy=Background",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -542,8 +524,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when request resolves", () => {
|
describe("when request resolves", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
fetchMock.resolveSpecific(
|
lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background"],
|
["/api-kube/api/v1/namespaces/foo?propagationPolicy=Background"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background", "{}"),
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background", "{}"),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -565,8 +547,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests deleting Namespace without namespace", () => {
|
it("requests deleting Namespace without namespace", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background",
|
"/api-kube/api/v1/namespaces/foo?propagationPolicy=Background",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -578,8 +560,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when request resolves", () => {
|
describe("when request resolves", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
fetchMock.resolveSpecific(
|
lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background"],
|
["/api-kube/api/v1/namespaces/foo?propagationPolicy=Background"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background", "{}"),
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background", "{}"),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -626,8 +608,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests the watch", () => {
|
it("requests the watch", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600",
|
"/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -639,9 +621,9 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the request resolves with a stream", () => {
|
describe("when the request resolves with a stream", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
([url, init]) => {
|
([url, init]) => {
|
||||||
const isMatch = url === "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600";
|
const isMatch = url === "/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600";
|
||||||
|
|
||||||
if (isMatch) {
|
if (isMatch) {
|
||||||
init?.signal?.addEventListener("abort", () => {
|
init?.signal?.addEventListener("abort", () => {
|
||||||
@ -722,8 +704,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests the watch", () => {
|
it("requests the watch", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600",
|
"/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -735,9 +717,9 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the request resolves with a stream", () => {
|
describe("when the request resolves with a stream", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
([url, init]) => {
|
([url, init]) => {
|
||||||
const isMatch = url === "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600";
|
const isMatch = url === "/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600";
|
||||||
|
|
||||||
if (isMatch) {
|
if (isMatch) {
|
||||||
init?.signal?.addEventListener("abort", () => {
|
init?.signal?.addEventListener("abort", () => {
|
||||||
@ -817,8 +799,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests the watch", () => {
|
it("requests the watch", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60",
|
"/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -830,9 +812,9 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the request resolves with a stream", () => {
|
describe("when the request resolves with a stream", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
([url, init]) => {
|
([url, init]) => {
|
||||||
const isMatch = url === "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60";
|
const isMatch = url === "/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60";
|
||||||
|
|
||||||
if (isMatch) {
|
if (isMatch) {
|
||||||
init?.signal?.addEventListener("abort", () => {
|
init?.signal?.addEventListener("abort", () => {
|
||||||
@ -899,8 +881,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("requests a new watch", () => {
|
it("requests a new watch", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60",
|
"/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -967,8 +949,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should request to create a pod with full descriptor", () => {
|
it("should request to create a pod with full descriptor", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods",
|
"/api-kube/api/v1/namespaces/default/pods",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -1002,8 +984,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when request resolves with data", () => {
|
describe("when request resolves with data", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods"],
|
["/api-kube/api/v1/namespaces/default/pods"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods", JSON.stringify({
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods", JSON.stringify({
|
||||||
kind: "Pod",
|
kind: "Pod",
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
@ -1077,8 +1059,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should request that the pod is updated", () => {
|
it("should request that the pod is updated", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foobar",
|
"/api-kube/api/v1/namespaces/default/pods/foobar",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -1112,8 +1094,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the request resolves with data", () => {
|
describe("when the request resolves with data", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foobar"],
|
["/api-kube/api/v1/namespaces/default/pods/foobar"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foobar", JSON.stringify({
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foobar", JSON.stringify({
|
||||||
kind: "Pod",
|
kind: "Pod",
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
@ -1165,8 +1147,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should request that the pods from all namespaces", () => {
|
it("should request that the pods from all namespaces", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/pods",
|
"/api-kube/api/v1/pods",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -1178,8 +1160,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the request resolves with empty data", () => {
|
describe("when the request resolves with empty data", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/api/v1/pods"],
|
["/api-kube/api/v1/pods"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/pods", JSON.stringify({
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/pods", JSON.stringify({
|
||||||
kind: "PodList",
|
kind: "PodList",
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
@ -1207,8 +1189,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should request that the pods from all namespaces", () => {
|
it("should request that the pods from all namespaces", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/pods",
|
"/api-kube/api/v1/pods",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -1220,8 +1202,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the request resolves with empty data", () => {
|
describe("when the request resolves with empty data", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/api/v1/pods"],
|
["/api-kube/api/v1/pods"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/pods", JSON.stringify({
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/pods", JSON.stringify({
|
||||||
kind: "PodList",
|
kind: "PodList",
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
@ -1249,8 +1231,8 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should request that the pods from just the default namespace", () => {
|
it("should request that the pods from just the default namespace", () => {
|
||||||
expect(fetchMock.mock.lastCall).toMatchObject([
|
expect(lensFetchMock.mock.lastCall).toMatchObject([
|
||||||
"http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods",
|
"/api-kube/api/v1/namespaces/default/pods",
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
@ -1262,8 +1244,8 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
describe("when the request resolves with empty data", () => {
|
describe("when the request resolves with empty data", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific(
|
await lensFetchMock.resolveSpecific(
|
||||||
["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods"],
|
["/api-kube/api/v1/namespaces/default/pods"],
|
||||||
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods", JSON.stringify({
|
createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods", JSON.stringify({
|
||||||
kind: "PodList",
|
kind: "PodList",
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
|
|||||||
@ -113,7 +113,15 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
|
|||||||
searchParams.append(key, value);
|
searchParams.append(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return format({ ...base, query: searchParams.toString() });
|
return format({
|
||||||
|
protocol: base.protocol || undefined,
|
||||||
|
auth: base.auth || undefined,
|
||||||
|
host: base.host || undefined,
|
||||||
|
hostname: base.hostname || undefined,
|
||||||
|
pathname: base.pathname || undefined,
|
||||||
|
hash: base.hash || undefined,
|
||||||
|
query: Object.fromEntries(searchParams.entries()),
|
||||||
|
});
|
||||||
})();
|
})();
|
||||||
const reqInit = await (async () => {
|
const reqInit = await (async () => {
|
||||||
const baseInit: SetRequired<RequestInit, "method"> = { method: "get" };
|
const baseInit: SetRequired<RequestInit, "method"> = { method: "get" };
|
||||||
|
|||||||
@ -12,8 +12,6 @@ import React from "react";
|
|||||||
import directoryForKubeConfigsInjectable from "../../../common/app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable";
|
import directoryForKubeConfigsInjectable from "../../../common/app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable";
|
||||||
import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||||
import { Cluster } from "../../../common/cluster/cluster";
|
import { Cluster } from "../../../common/cluster/cluster";
|
||||||
import type { Fetch } from "../../../common/fetch/fetch.injectable";
|
|
||||||
import fetchInjectable from "../../../common/fetch/fetch.injectable";
|
|
||||||
import { Namespace } from "../../../common/k8s-api/endpoints";
|
import { Namespace } from "../../../common/k8s-api/endpoints";
|
||||||
import { createMockResponseFromString } from "../../../test-utils/mock-responses";
|
import { createMockResponseFromString } from "../../../test-utils/mock-responses";
|
||||||
import hostedClusterInjectable from "../../cluster-frame-context/hosted-cluster.injectable";
|
import hostedClusterInjectable from "../../cluster-frame-context/hosted-cluster.injectable";
|
||||||
@ -26,6 +24,8 @@ import { renderFor } from "../test-utils/renderFor";
|
|||||||
import { NamespaceSelectFilter } from "./namespace-select-filter";
|
import { NamespaceSelectFilter } from "./namespace-select-filter";
|
||||||
import type { NamespaceStore } from "./store";
|
import type { NamespaceStore } from "./store";
|
||||||
import namespaceStoreInjectable from "./store.injectable";
|
import namespaceStoreInjectable from "./store.injectable";
|
||||||
|
import type { LensFetch } from "../../../features/lens-fetch/common/lens-fetch.injectable";
|
||||||
|
import lensFetchInjectable from "../../../features/lens-fetch/common/lens-fetch.injectable";
|
||||||
|
|
||||||
function createNamespace(name: string): Namespace {
|
function createNamespace(name: string): Namespace {
|
||||||
return new Namespace({
|
return new Namespace({
|
||||||
@ -43,7 +43,7 @@ function createNamespace(name: string): Namespace {
|
|||||||
describe("<NamespaceSelectFilter />", () => {
|
describe("<NamespaceSelectFilter />", () => {
|
||||||
let di: DiContainer;
|
let di: DiContainer;
|
||||||
let namespaceStore: NamespaceStore;
|
let namespaceStore: NamespaceStore;
|
||||||
let fetchMock: AsyncFnMock<Fetch>;
|
let lensFetchMock: AsyncFnMock<LensFetch>;
|
||||||
let result: RenderResult;
|
let result: RenderResult;
|
||||||
let cleanup: Disposer;
|
let cleanup: Disposer;
|
||||||
|
|
||||||
@ -55,8 +55,8 @@ describe("<NamespaceSelectFilter />", () => {
|
|||||||
di.override(directoryForKubeConfigsInjectable, () => "/some-kube-configs");
|
di.override(directoryForKubeConfigsInjectable, () => "/some-kube-configs");
|
||||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||||
|
|
||||||
fetchMock = asyncFn();
|
lensFetchMock = asyncFn();
|
||||||
di.override(fetchInjectable, () => fetchMock);
|
di.override(lensFetchInjectable, () => lensFetchMock);
|
||||||
|
|
||||||
di.override(hostedClusterInjectable, () => new Cluster({
|
di.override(hostedClusterInjectable, () => new Cluster({
|
||||||
contextName: "some-context-name",
|
contextName: "some-context-name",
|
||||||
@ -85,8 +85,8 @@ describe("<NamespaceSelectFilter />", () => {
|
|||||||
|
|
||||||
describe("once the subscribe resolves", () => {
|
describe("once the subscribe resolves", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await fetchMock.resolveSpecific([
|
await lensFetchMock.resolveSpecific([
|
||||||
"https://127.0.0.1:12345/api-kube/api/v1/namespaces",
|
"/api-kube/api/v1/namespaces",
|
||||||
], createMockResponseFromString("https://127.0.0.1:12345/api-kube/api/v1/namespaces", JSON.stringify({
|
], createMockResponseFromString("https://127.0.0.1:12345/api-kube/api/v1/namespaces", JSON.stringify({
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
kind: "NamespaceList",
|
kind: "NamespaceList",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user