mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
special case */namespace/* in parseApi, add test (#509)
This commit is contained in:
parent
dd5e66ba67
commit
73fd09c57d
@ -2,7 +2,7 @@ import { KubeApi, IKubeApiLinkBase } from "../kube-api";
|
||||
|
||||
interface ParseAPITest {
|
||||
url: string;
|
||||
expected: IKubeApiLinkBase;
|
||||
expected: Required<IKubeApiLinkBase>;
|
||||
}
|
||||
|
||||
const tests: ParseAPITest[] = [
|
||||
@ -97,6 +97,19 @@ const tests: ParseAPITest[] = [
|
||||
namespace: undefined,
|
||||
},
|
||||
},
|
||||
{
|
||||
url: "/api/v1/namespaces/kube-public",
|
||||
expected: {
|
||||
apiBase: "/api/v1/namespaces",
|
||||
apiPrefix: "/api",
|
||||
apiGroup: "",
|
||||
apiVersion: "v1",
|
||||
apiVersionWithGroup: "v1",
|
||||
resource: "namespaces",
|
||||
name: "kube-public",
|
||||
namespace: undefined,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
jest.mock('../kube-watch-api.ts', () => 'KubeWatchApi');
|
||||
|
||||
@ -8,7 +8,6 @@ import { apiKube } from "./index";
|
||||
import { kubeWatchApi } from "./kube-watch-api";
|
||||
import { apiManager } from "./api-manager";
|
||||
import { split } from "../utils/arrays";
|
||||
import isEqual from "lodash/isEqual";
|
||||
|
||||
export interface IKubeApiOptions<T extends KubeObject> {
|
||||
kind: string; // resource type within api-group, e.g. "Namespace"
|
||||
@ -43,7 +42,6 @@ export interface IKubeApiLinkBase extends IKubeApiLinkRef {
|
||||
export class KubeApi<T extends KubeObject = any> {
|
||||
static parseApi(apiPath = ""): IKubeApiLinkBase {
|
||||
apiPath = new URL(apiPath, location.origin).pathname;
|
||||
|
||||
const [, prefix, ...parts] = apiPath.split("/");
|
||||
const apiPrefix = `/${prefix}`;
|
||||
|
||||
@ -52,12 +50,12 @@ export class KubeApi<T extends KubeObject = any> {
|
||||
|
||||
if (namespaced) {
|
||||
switch (right.length) {
|
||||
case 1:
|
||||
name = right[0];
|
||||
// fallthrough
|
||||
case 0:
|
||||
resource = "namespaces"; // special case this due to `split` removing namespaces
|
||||
break;
|
||||
case 1:
|
||||
resource = right[0];
|
||||
break;
|
||||
default:
|
||||
[namespace, resource, name] = right;
|
||||
break;
|
||||
@ -69,6 +67,7 @@ export class KubeApi<T extends KubeObject = any> {
|
||||
switch (left.length) {
|
||||
case 2:
|
||||
resource = left.pop();
|
||||
// fallthrough
|
||||
case 1:
|
||||
apiVersion = left.pop();
|
||||
apiGroup = "";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user