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);