From 56c4680880079cecbce6eda51b3913a8dd393a71 Mon Sep 17 00:00:00 2001 From: bdw617 Date: Mon, 2 Oct 2023 16:56:26 -0400 Subject: [PATCH] added tests for coverage --- src/fluent/utils.test.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/fluent/utils.test.ts b/src/fluent/utils.test.ts index 7944945..9f8108a 100644 --- a/src/fluent/utils.test.ts +++ b/src/fluent/utils.test.ts @@ -8,6 +8,7 @@ import { GenericClass } from "../types"; import { ClusterRole, Ingress, Pod } from "../upstream"; import { Filters } from "./types"; import { k8sExec, pathBuilder } from "./utils"; +import { RegisterKind } from "../kinds"; jest.mock("https"); jest.mock("../fetch"); @@ -20,6 +21,44 @@ describe("pathBuilder Function", () => { expect(() => pathBuilder("", model, filters)).toThrow("Kind not specified for Unknown"); }); + it("should generate a path for core group kinds (with custom filters)", () => { + const filters: Filters = { + namespace: "default", + name: "mypod", + fields: { iamafield: "iamavalue" }, + labels: { iamalabel: "iamalabelvalue" }, + }; + const result = pathBuilder(serverUrl, Pod, filters); + const expected = new URL( + "/api/v1/namespaces/default/pods/mypod?fieldSelector=iamafield%3Diamavalue&labelSelector=iamalabel%3Diamalabelvalue", + serverUrl, + ); + expect(result).toEqual(expected); + }); + + it("Version not specified in a Kind", () => { + const filters: Filters = { + namespace: "default", + name: "mypod", + }; + class Fake { + name: string; + constructor() { + this.name = "Fake"; + } + } + RegisterKind(Fake, { + kind: "Fake", + version: "", + group: "fake", + }); + try { + pathBuilder(serverUrl, Fake, filters); + } catch (e) { + expect(e.message).toEqual(`Version not specified for Fake`); + } + }); + it("should generate a path for core group kinds", () => { const filters: Filters = { namespace: "default", name: "mypod" }; const result = pathBuilder(serverUrl, Pod, filters);