mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
remove the explicit throw is new parseApi
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
This commit is contained in:
parent
d55803d0c7
commit
1107ff3e43
@ -45,10 +45,23 @@ const tests: ParseAPITest[] = [
|
|||||||
namespace: undefined,
|
namespace: undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
url: "/apis/namespaces/default/es/gke-svc-vodka-1-app-1-w-l-1-9eea2bfe-4jnl",
|
||||||
|
expected: {
|
||||||
|
apiBase: "/apis",
|
||||||
|
apiPrefix: "/apis",
|
||||||
|
apiGroup: undefined,
|
||||||
|
apiVersion: undefined,
|
||||||
|
apiVersionWithGroup: "",
|
||||||
|
resource: undefined,
|
||||||
|
name: undefined,
|
||||||
|
namespace: undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
jest.mock('../kube-watch-api.ts', () => 'KubeWatchApi');
|
jest.mock('../kube-watch-api.ts', () => 'KubeWatchApi');
|
||||||
describe("parseAPI unit tests", () => {
|
describe("parseApi unit tests", () => {
|
||||||
for (const i in tests) {
|
for (const i in tests) {
|
||||||
const { url: tUrl, expected:tExpect} = tests[i];
|
const { url: tUrl, expected:tExpect} = tests[i];
|
||||||
test(`test #${parseInt(i)+1}`, () => {
|
test(`test #${parseInt(i)+1}`, () => {
|
||||||
|
|||||||
@ -18,23 +18,17 @@ export class ApiManager {
|
|||||||
private views = observable.map<KubeApi, ApiComponents>();
|
private views = observable.map<KubeApi, ApiComponents>();
|
||||||
|
|
||||||
getApi(pathOrCallback: string | ((api: KubeApi) => boolean)) {
|
getApi(pathOrCallback: string | ((api: KubeApi) => boolean)) {
|
||||||
const apis = this.apis;
|
|
||||||
if (typeof pathOrCallback === "string") {
|
if (typeof pathOrCallback === "string") {
|
||||||
let api = apis.get(pathOrCallback);
|
return this.apis.get(pathOrCallback) || this.apis.get(KubeApi.parseApi(pathOrCallback).apiBase);
|
||||||
if (!api) {
|
|
||||||
const { apiBase } = KubeApi.parseApi(pathOrCallback);
|
|
||||||
api = apis.get(apiBase);
|
|
||||||
}
|
|
||||||
return api;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return Array.from(apis.values()).find(pathOrCallback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Array.from(this.apis.values()).find(pathOrCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
registerApi(apiBase: string, api: KubeApi) {
|
registerApi(apiBase: string, api: KubeApi) {
|
||||||
if (this.apis.has(apiBase)) return;
|
if (!this.apis.has(apiBase)) {
|
||||||
this.apis.set(apiBase, api);
|
this.apis.set(apiBase, api);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected resolveApi(api: string | KubeApi): KubeApi {
|
protected resolveApi(api: string | KubeApi): KubeApi {
|
||||||
|
|||||||
@ -48,11 +48,7 @@ export class KubeApi<T extends KubeObject = any> {
|
|||||||
const [left, right, found] = split(parts, "namespaces");
|
const [left, right, found] = split(parts, "namespaces");
|
||||||
let apiGroup, apiVersion, namespace, resource, name;
|
let apiGroup, apiVersion, namespace, resource, name;
|
||||||
|
|
||||||
if (found) {
|
if (found && left.length > 0) {
|
||||||
if (left.length == 0) {
|
|
||||||
throw new Error(`invalid apiPath: ${apiPath}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
apiVersion = left.pop();
|
apiVersion = left.pop();
|
||||||
apiGroup = left.join("/");
|
apiGroup = left.join("/");
|
||||||
[namespace, resource, name] = right;
|
[namespace, resource, name] = right;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user