mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix tests
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
2e6dc57c82
commit
4c632dcd25
@ -20,12 +20,22 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { KubeApi } from "../kube-api";
|
import { KubeApi } from "../kube-api";
|
||||||
|
import { KubeJsonApi } from "../kube-json-api";
|
||||||
import { KubeObject } from "../kube-object";
|
import { KubeObject } from "../kube-object";
|
||||||
|
|
||||||
describe("KubeApi", () => {
|
describe("KubeApi", () => {
|
||||||
|
let request: KubeJsonApi;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
request = new KubeJsonApi({
|
||||||
|
serverAddress: `http://127.0.0.1:9999`,
|
||||||
|
apiBase: "/api-kube"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("uses url from apiBase if apiBase contains the resource", async () => {
|
it("uses url from apiBase if apiBase contains the resource", async () => {
|
||||||
(fetch as any).mockResponse(async (request: any) => {
|
(fetch as any).mockResponse(async (request: any) => {
|
||||||
if (request.url === "/api-kube/apis/networking.k8s.io/v1") {
|
if (request.url === "http://127.0.0.1:9999/api-kube/apis/networking.k8s.io/v1") {
|
||||||
return {
|
return {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
resources: [{
|
resources: [{
|
||||||
@ -33,7 +43,7 @@ describe("KubeApi", () => {
|
|||||||
}] as any[]
|
}] as any[]
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
} else if (request.url === "/api-kube/apis/extensions/v1beta1") {
|
} else if (request.url === "http://127.0.0.1:9999/api-kube/apis/extensions/v1beta1") {
|
||||||
// Even if the old API contains ingresses, KubeApi should prefer the apiBase url
|
// Even if the old API contains ingresses, KubeApi should prefer the apiBase url
|
||||||
return {
|
return {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@ -54,6 +64,7 @@ describe("KubeApi", () => {
|
|||||||
const apiBase = "/apis/networking.k8s.io/v1/ingresses";
|
const apiBase = "/apis/networking.k8s.io/v1/ingresses";
|
||||||
const fallbackApiBase = "/apis/extensions/v1beta1/ingresses";
|
const fallbackApiBase = "/apis/extensions/v1beta1/ingresses";
|
||||||
const kubeApi = new KubeApi({
|
const kubeApi = new KubeApi({
|
||||||
|
request,
|
||||||
objectConstructor: KubeObject,
|
objectConstructor: KubeObject,
|
||||||
apiBase,
|
apiBase,
|
||||||
fallbackApiBases: [fallbackApiBase],
|
fallbackApiBases: [fallbackApiBase],
|
||||||
@ -67,13 +78,13 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
it("uses url from fallbackApiBases if apiBase lacks the resource", async () => {
|
it("uses url from fallbackApiBases if apiBase lacks the resource", async () => {
|
||||||
(fetch as any).mockResponse(async (request: any) => {
|
(fetch as any).mockResponse(async (request: any) => {
|
||||||
if (request.url === "/api-kube/apis/networking.k8s.io/v1") {
|
if (request.url === "http://127.0.0.1:9999/api-kube/apis/networking.k8s.io/v1") {
|
||||||
return {
|
return {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
resources: [] as any[]
|
resources: [] as any[]
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
} else if (request.url === "/api-kube/apis/extensions/v1beta1") {
|
} else if (request.url === "http://127.0.0.1:9999/api-kube/apis/extensions/v1beta1") {
|
||||||
return {
|
return {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
resources: [{
|
resources: [{
|
||||||
@ -93,6 +104,7 @@ describe("KubeApi", () => {
|
|||||||
const apiBase = "apis/networking.k8s.io/v1/ingresses";
|
const apiBase = "apis/networking.k8s.io/v1/ingresses";
|
||||||
const fallbackApiBase = "/apis/extensions/v1beta1/ingresses";
|
const fallbackApiBase = "/apis/extensions/v1beta1/ingresses";
|
||||||
const kubeApi = new KubeApi({
|
const kubeApi = new KubeApi({
|
||||||
|
request,
|
||||||
objectConstructor: KubeObject,
|
objectConstructor: KubeObject,
|
||||||
apiBase,
|
apiBase,
|
||||||
fallbackApiBases: [fallbackApiBase],
|
fallbackApiBases: [fallbackApiBase],
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
import merge from "lodash/merge";
|
import merge from "lodash/merge";
|
||||||
import { stringify } from "querystring";
|
import { stringify } from "querystring";
|
||||||
import { apiKubePrefix, isDevelopment, isTestEnv } from "../../common/vars";
|
import { apiKubePrefix, isDevelopment } from "../../common/vars";
|
||||||
import logger from "../../main/logger";
|
import logger from "../../main/logger";
|
||||||
import { apiManager } from "./api-manager";
|
import { apiManager } from "./api-manager";
|
||||||
import { apiKube } from "./index";
|
import { apiKube } from "./index";
|
||||||
@ -202,18 +202,9 @@ export class KubeApi<T extends KubeObject> {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Exception is ignored as we can try the next url
|
// Exception is ignored as we can try the next url
|
||||||
console.error(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid throwing in tests
|
|
||||||
if (isTestEnv) {
|
|
||||||
return {
|
|
||||||
apiPrefix: this.apiPrefix,
|
|
||||||
apiGroup: this.apiGroup
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error(`Can't find working API for the Kubernetes resource ${this.apiResource}`);
|
throw new Error(`Can't find working API for the Kubernetes resource ${this.apiResource}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user