Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tests for coverage #17

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/fluent/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand Down
Loading