From 2446b6cf9bb8b5e6aa250ddf5ea967c14b44388e Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Wed, 17 Nov 2021 16:34:05 +0200 Subject: [PATCH] Add tests for KubeApi.watch timeout (#4367) --- src/common/k8s-api/__tests__/kube-api.test.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/common/k8s-api/__tests__/kube-api.test.ts b/src/common/k8s-api/__tests__/kube-api.test.ts index dd79b9c386..08cc9f2642 100644 --- a/src/common/k8s-api/__tests__/kube-api.test.ts +++ b/src/common/k8s-api/__tests__/kube-api.test.ts @@ -293,4 +293,37 @@ describe("KubeApi", () => { await api.delete({ name: "foo", namespace: "default", propagationPolicy: "Orphan" }); }); }); + + describe("watch", () => { + let api: TestKubeApi; + + beforeEach(() => { + api = new TestKubeApi({ + request, + objectConstructor: TestKubeObject, + }); + }); + + it("sends a valid watch request", () => { + const spy = jest.spyOn(request, "getResponse"); + + (fetch as any).mockResponse(async () => { + return {}; + }); + + api.watch({ namespace: "kube-system" }); + expect(spy).toHaveBeenCalledWith("/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=", expect.anything(), expect.anything()); + }); + + it("sends timeout as a query parameter", async () => { + const spy = jest.spyOn(request, "getResponse"); + + (fetch as any).mockResponse(async () => { + return {}; + }); + + api.watch({ namespace: "kube-system", timeout: 60 }); + expect(spy).toHaveBeenCalledWith("/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=", { query: { timeoutSeconds: 60 }}, expect.anything()); + }); + }); });