Skip to content

Commit 3a29afe

Browse files
author
Barry Waldbaum
authored
test: increase pathBuilder and Kind test coverage (#17)
fix: filters for field and label selectors weren't tested. also added a test for a Kind without a version.
1 parent f46422b commit 3a29afe

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/fluent/utils.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { GenericClass } from "../types";
88
import { ClusterRole, Ingress, Pod } from "../upstream";
99
import { Filters } from "./types";
1010
import { k8sExec, pathBuilder } from "./utils";
11+
import { RegisterKind } from "../kinds";
1112

1213
jest.mock("https");
1314
jest.mock("../fetch");
@@ -20,6 +21,44 @@ describe("pathBuilder Function", () => {
2021
expect(() => pathBuilder("", model, filters)).toThrow("Kind not specified for Unknown");
2122
});
2223

24+
it("should generate a path for core group kinds (with custom filters)", () => {
25+
const filters: Filters = {
26+
namespace: "default",
27+
name: "mypod",
28+
fields: { iamafield: "iamavalue" },
29+
labels: { iamalabel: "iamalabelvalue" },
30+
};
31+
const result = pathBuilder(serverUrl, Pod, filters);
32+
const expected = new URL(
33+
"/api/v1/namespaces/default/pods/mypod?fieldSelector=iamafield%3Diamavalue&labelSelector=iamalabel%3Diamalabelvalue",
34+
serverUrl,
35+
);
36+
expect(result).toEqual(expected);
37+
});
38+
39+
it("Version not specified in a Kind", () => {
40+
const filters: Filters = {
41+
namespace: "default",
42+
name: "mypod",
43+
};
44+
class Fake {
45+
name: string;
46+
constructor() {
47+
this.name = "Fake";
48+
}
49+
}
50+
RegisterKind(Fake, {
51+
kind: "Fake",
52+
version: "",
53+
group: "fake",
54+
});
55+
try {
56+
pathBuilder(serverUrl, Fake, filters);
57+
} catch (e) {
58+
expect(e.message).toEqual(`Version not specified for Fake`);
59+
}
60+
});
61+
2362
it("should generate a path for core group kinds", () => {
2463
const filters: Filters = { namespace: "default", name: "mypod" };
2564
const result = pathBuilder(serverUrl, Pod, filters);

0 commit comments

Comments
 (0)