mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Change parseKubeApi into a no-throw version
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
8dce32153f
commit
2f21ba51d1
10 files changed
+113
-80
No files matched your search
+9
-6
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
import { getInjectable, createInstantiationTargetDecorator, instantiationDecoratorToken } from "@ogre-tools/injectable";
|
||||
import { pick } from "lodash";
|
||||
import { inspect } from "util";
|
||||
import { parseKubeApi } from "../../../common/k8s-api/kube-api-parse";
|
||||
import showDetailsInjectable from "../../../renderer/components/kube-detail-params/show-details.injectable";
|
||||
import emitTelemetryInjectable from "./emit-telemetry.injectable";
|
||||
@@ -21,13 +22,15 @@ const telemetryDecoratorForShowDetailsInjectable = getInjectable({
|
||||
? {
|
||||
action: "open",
|
||||
...(() => {
|
||||
try {
|
||||
return {
|
||||
resource: pick(parseKubeApi(args[0]), "apiPrefix", "apiVersion", "apiGroup", "namespace", "resource", "name"),
|
||||
};
|
||||
} catch (error) {
|
||||
return { error: `${error}` };
|
||||
const parsedApi = parseKubeApi(args[0]);
|
||||
|
||||
if (!parsedApi) {
|
||||
return { error: `invalid apiPath: ${inspect(args[0])}` };
|
||||
}
|
||||
|
||||
return {
|
||||
resource: pick(parsedApi, "apiPrefix", "apiVersion", "apiGroup", "namespace", "resource", "name"),
|
||||
};
|
||||
})(),
|
||||
}
|
||||
: {
|
||||
|
||||
@@ -21,7 +21,7 @@ describe("emit telemetry with params for calls to showDetails", () => {
|
||||
showDetails = di.inject(showDetailsInjectable);
|
||||
});
|
||||
|
||||
it("when showDetails is called with no selflink (ie closing) should emit telemetry with param indicating closing the drawer", () => {
|
||||
it("when showDetails is called with no selfLink (ie closing) should emit telemetry with param indicating closing the drawer", () => {
|
||||
showDetails(undefined);
|
||||
|
||||
expect(emitAppEventMock).toBeCalledWith({
|
||||
@@ -34,7 +34,7 @@ describe("emit telemetry with params for calls to showDetails", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("when showDetails is called with empty selflink (ie closing) should emit telemetry with param indicating closing the drawer", () => {
|
||||
it("when showDetails is called with empty selfLink (ie closing) should emit telemetry with param indicating closing the drawer", () => {
|
||||
showDetails("");
|
||||
|
||||
expect(emitAppEventMock).toBeCalledWith({
|
||||
@@ -47,7 +47,7 @@ describe("emit telemetry with params for calls to showDetails", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("when showDetails is called with valid selflink should emit telemetry with param indicating opening the drawer with that resource", () => {
|
||||
it("when showDetails is called with valid selfLink should emit telemetry with param indicating opening the drawer with that resource", () => {
|
||||
showDetails("/api/v1/namespaces/default/pods/some-name");
|
||||
|
||||
expect(emitAppEventMock).toBeCalledWith({
|
||||
@@ -68,7 +68,7 @@ describe("emit telemetry with params for calls to showDetails", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("when showDetails is called with invalid selflink should emit telemetry with param indicating opening the drawer but also show error", () => {
|
||||
it("when showDetails is called with invalid selfLink should emit telemetry with param indicating opening the drawer but also show error", () => {
|
||||
showDetails("some-non-self-link-value");
|
||||
|
||||
expect(emitAppEventMock).toBeCalledWith({
|
||||
@@ -77,7 +77,7 @@ describe("emit telemetry with params for calls to showDetails", () => {
|
||||
name: "show-details",
|
||||
params: {
|
||||
action: "open",
|
||||
error: "Error: invalid apiPath: /some-non-self-link-value",
|
||||
error: "invalid apiPath: 'some-non-self-link-value'",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user