1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add test. Fix typing.

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti 2021-12-02 14:14:41 +02:00
parent 9e9baba659
commit cc2f8fe756
4 changed files with 24 additions and 5 deletions

View File

@ -241,6 +241,24 @@ describe("KubeApi", () => {
{ op: "replace", path: "/spec/replicas", value: 2 },
], "json");
});
it("allows deep partial patch", async () => {
expect.hasAssertions();
(fetch as any).mockResponse(async (request: Request) => {
expect(request.method).toEqual("PATCH");
expect(request.headers.get("content-type")).toMatch("merge-patch");
expect(request.body.toString()).toEqual(JSON.stringify({ metadata: { annotations: { provisioned: "true" } }}));
return {};
});
await api.patch(
{ name: "test", namespace: "default" },
{ metadata: { annotations: { provisioned: "true" } } },
"merge"
);
});
});
describe("delete", () => {

View File

@ -37,7 +37,6 @@ import type { RequestInit } from "node-fetch";
import AbortController from "abort-controller";
import { Agent, AgentOptions } from "https";
import type { Patch } from "rfc6902";
import type { PartialDeep } from "type-fest";
export interface IKubeApiOptions<T extends KubeObject> {
/**
@ -527,7 +526,7 @@ export class KubeApi<T extends KubeObject> {
return parsed;
}
async patch(desc: ResourceDescriptor, data?: PartialDeep<T> | Patch, strategy: KubeApiPatchType = "strategic"): Promise<T | null> {
async patch(desc: ResourceDescriptor, data?: PartialKubeObject<T> | Patch, strategy: KubeApiPatchType = "strategic") {
await this.checkPreferredVersion();
const apiUrl = this.getUrl(desc);
@ -542,7 +541,7 @@ export class KubeApi<T extends KubeObject> {
throw new Error(`PATCH request to ${apiUrl} returned an array: ${JSON.stringify(parsed)}`);
}
return parsed;
return parsed as T | null;
}
async delete({ propagationPolicy = "Background", ...desc }: DeleteResourceDescriptor) {

View File

@ -49,7 +49,8 @@ export class Namespaces extends React.Component<Props> {
<KubeObjectListLayout
isConfigurable
tableId="namespaces"
className="Namespaces" store={namespaceStore}
className="Namespaces"
store={namespaceStore}
sortingCallbacks={{
[columnId.name]: ns => ns.getName(),
[columnId.labels]: ns => ns.getLabels(),

View File

@ -92,7 +92,8 @@ export class Pods extends React.Component<Props> {
render() {
return (
<KubeObjectListLayout
className="Pods" store={podsStore}
className="Pods"
store={podsStore}
dependentStores={[eventStore]} // status icon component uses event store
tableId = "workloads_pods"
isConfigurable