kubernetes-fluent-client 3.1.1 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/.husky/pre-commit +1 -0
  2. package/.lintstagedrc.json +5 -0
  3. package/dist/fluent/types.d.ts +14 -0
  4. package/dist/fluent/types.d.ts.map +1 -1
  5. package/dist/fluent/watch.d.ts.map +1 -1
  6. package/dist/fluent/watch.js +121 -71
  7. package/package.json +8 -5
  8. package/src/fluent/types.ts +16 -0
  9. package/src/fluent/watch.ts +136 -81
  10. package/dist/fetch.test.d.ts +0 -2
  11. package/dist/fetch.test.d.ts.map +0 -1
  12. package/dist/fetch.test.js +0 -97
  13. package/dist/fileSystem.test.d.ts +0 -2
  14. package/dist/fileSystem.test.d.ts.map +0 -1
  15. package/dist/fileSystem.test.js +0 -75
  16. package/dist/fluent/http2-watch.spec.d.ts +0 -2
  17. package/dist/fluent/http2-watch.spec.d.ts.map +0 -1
  18. package/dist/fluent/http2-watch.spec.js +0 -284
  19. package/dist/fluent/index.test.d.ts +0 -2
  20. package/dist/fluent/index.test.d.ts.map +0 -1
  21. package/dist/fluent/index.test.js +0 -193
  22. package/dist/fluent/utils.test.d.ts +0 -2
  23. package/dist/fluent/utils.test.d.ts.map +0 -1
  24. package/dist/fluent/utils.test.js +0 -215
  25. package/dist/fluent/watch.spec.d.ts +0 -2
  26. package/dist/fluent/watch.spec.d.ts.map +0 -1
  27. package/dist/fluent/watch.spec.js +0 -261
  28. package/dist/generate.test.d.ts +0 -2
  29. package/dist/generate.test.d.ts.map +0 -1
  30. package/dist/generate.test.js +0 -320
  31. package/dist/helpers.test.d.ts +0 -2
  32. package/dist/helpers.test.d.ts.map +0 -1
  33. package/dist/helpers.test.js +0 -37
  34. package/dist/kinds.test.d.ts +0 -2
  35. package/dist/kinds.test.d.ts.map +0 -1
  36. package/dist/kinds.test.js +0 -155
  37. package/dist/postProcessing.test.d.ts +0 -2
  38. package/dist/postProcessing.test.d.ts.map +0 -1
  39. package/dist/postProcessing.test.js +0 -550
  40. package/e2e/cli.e2e.test.ts +0 -127
  41. package/e2e/crds/policyreports.default.expected/policyreport-v1alpha1.ts +0 -332
  42. package/e2e/crds/policyreports.default.expected/policyreport-v1alpha2.ts +0 -360
  43. package/e2e/crds/policyreports.default.expected/policyreport-v1beta1.ts +0 -360
  44. package/e2e/crds/policyreports.no.post.expected/policyreport-v1alpha1.ts +0 -331
  45. package/e2e/crds/policyreports.no.post.expected/policyreport-v1alpha2.ts +0 -360
  46. package/e2e/crds/policyreports.no.post.expected/policyreport-v1beta1.ts +0 -360
  47. package/e2e/crds/test.yaml/policyreports.test.yaml +0 -1008
  48. package/e2e/crds/test.yaml/uds-podmonitors.test.yaml +0 -1245
  49. package/e2e/crds/uds-podmonitors.default.expected/podmonitor-v1.ts +0 -1333
  50. package/e2e/crds/uds-podmonitors.no.post.expected/podmonitor-v1.ts +0 -1360
  51. package/src/fetch.test.ts +0 -115
  52. package/src/fileSystem.test.ts +0 -67
  53. package/src/fluent/http2-watch.spec.ts +0 -335
  54. package/src/fluent/index.test.ts +0 -268
  55. package/src/fluent/utils.test.ts +0 -276
  56. package/src/fluent/watch.spec.ts +0 -299
  57. package/src/generate.test.ts +0 -399
  58. package/src/helpers.test.ts +0 -42
  59. package/src/kinds.test.ts +0 -166
  60. package/src/postProcessing.test.ts +0 -742
@@ -1,320 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const globals_1 = require("@jest/globals");
7
- const generate_1 = require("./generate");
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- const quicktype_core_1 = require("quicktype-core");
11
- const fetch_1 = require("./fetch");
12
- const client_node_1 = require("@kubernetes/client-node");
13
- const fluent_1 = require("./fluent");
14
- const upstream_1 = require("./upstream");
15
- // Mock the file system
16
- globals_1.jest.mock("fs", () => ({
17
- ...globals_1.jest.requireActual("fs"), // Preserve the rest of the fs module
18
- writeFileSync: globals_1.jest.fn(), // Mock only writeFileSync
19
- existsSync: globals_1.jest.fn(),
20
- readFileSync: globals_1.jest.fn(),
21
- }));
22
- globals_1.jest.mock("./fetch");
23
- globals_1.jest.mock("quicktype-core", () => {
24
- const actualQuicktypeCore = globals_1.jest.requireActual("quicktype-core");
25
- return {
26
- quicktype: globals_1.jest.fn(),
27
- JSONSchemaInput: actualQuicktypeCore.JSONSchemaInput,
28
- FetchingJSONSchemaStore: actualQuicktypeCore.FetchingJSONSchemaStore,
29
- InputData: actualQuicktypeCore.InputData,
30
- };
31
- });
32
- globals_1.jest.mock("@kubernetes/client-node", () => {
33
- const actualModule = globals_1.jest.requireActual("@kubernetes/client-node");
34
- return {
35
- ...(typeof actualModule === "object" ? actualModule : {}),
36
- loadAllYaml: globals_1.jest.fn(), // Mock only the specific method
37
- };
38
- });
39
- globals_1.jest.mock("./fluent", () => ({
40
- K8s: globals_1.jest.fn(),
41
- }));
42
- globals_1.jest.mock("./generate", () => {
43
- const actualGenerate = globals_1.jest.requireActual("./generate");
44
- return {
45
- ...(typeof actualGenerate === "object" ? actualGenerate : {}),
46
- resolveFilePath: globals_1.jest.fn(), // Mock resolveFilePath globally
47
- tryParseUrl: globals_1.jest.fn(),
48
- };
49
- });
50
- // Sample CRD content to use in tests
51
- const sampleCrd = {
52
- apiVersion: "apiextensions.k8s.io/v1",
53
- kind: "CustomResourceDefinition",
54
- metadata: { name: "movies.example.com" },
55
- spec: {
56
- group: "example.com",
57
- names: { kind: "Movie", plural: "movies" },
58
- scope: "Namespaced",
59
- versions: [
60
- {
61
- name: "v1",
62
- served: true,
63
- storage: true,
64
- schema: {
65
- openAPIV3Schema: {
66
- type: "object",
67
- description: "Movie nerd",
68
- properties: {
69
- spec: {
70
- properties: {
71
- title: { type: "string" },
72
- author: { type: "string" },
73
- },
74
- },
75
- },
76
- },
77
- },
78
- },
79
- ],
80
- },
81
- };
82
- const expectedMovie = [
83
- "/**",
84
- " * Movie nerd",
85
- " */",
86
- "export interface Movie {",
87
- " spec?: any[] | boolean | number | number | null | SpecObject | string;",
88
- " [property: string]: any;",
89
- "}",
90
- "",
91
- "export interface SpecObject {",
92
- " author?: string;",
93
- " title?: string;",
94
- " [property: string]: any;",
95
- "}",
96
- "",
97
- ];
98
- (0, globals_1.describe)("CRD Generate", () => {
99
- let logFn; // Mock log function
100
- (0, globals_1.beforeEach)(() => {
101
- globals_1.jest.clearAllMocks(); // Reset all mocks before each test
102
- logFn = globals_1.jest.fn(); // Mock the log function with correct typing
103
- });
104
- (0, globals_1.test)("convertCRDtoTS should generate the expected TypeScript file", async () => {
105
- // Mock convertCRDtoTS to return a valid result structure
106
- quicktype_core_1.quicktype.mockResolvedValueOnce({
107
- lines: expectedMovie,
108
- annotations: [],
109
- });
110
- const options = {
111
- source: "test-crd.yaml",
112
- language: "ts",
113
- logFn,
114
- directory: "test-dir",
115
- plain: false,
116
- npmPackage: "kubernetes-fluent-client",
117
- };
118
- // Call convertCRDtoTS with sample CRD
119
- const result = await (0, generate_1.convertCRDtoTS)(sampleCrd, options);
120
- // Extract the generated types from the result
121
- const generatedTypes = result[0].results["movie-v1"];
122
- // Assert that the generated types match the expected TypeScript code
123
- (0, globals_1.expect)(generatedTypes).toEqual(expectedMovie);
124
- // Assert the file writing happens with the expected TypeScript content
125
- (0, globals_1.expect)(fs_1.default.writeFileSync).toHaveBeenCalledWith(path_1.default.join("test-dir", "movie-v1.ts"), expectedMovie.join("\n"));
126
- // Assert the logs contain expected log messages
127
- (0, globals_1.expect)(logFn).toHaveBeenCalledWith("- Generating example.com/v1 types for Movie");
128
- });
129
- });
130
- (0, globals_1.describe)("readOrFetchCrd", () => {
131
- let mockOpts;
132
- (0, globals_1.beforeEach)(() => {
133
- globals_1.jest.clearAllMocks();
134
- mockOpts = {
135
- source: "mock-file-path",
136
- logFn: globals_1.jest.fn(),
137
- };
138
- // Reapply mock for resolveFilePath inside beforeEach
139
- const { resolveFilePath } = globals_1.jest.requireMock("./generate");
140
- resolveFilePath.mockReturnValue("mock-file-path");
141
- });
142
- (0, globals_1.test)("should load CRD from a local file", async () => {
143
- // Inside the test:
144
- const absoluteFilePath = path_1.default.join(process.cwd(), "mock-file-path");
145
- // Mock file system functions
146
- fs_1.default.existsSync.mockReturnValue(true);
147
- fs_1.default.readFileSync.mockReturnValue("mock file content");
148
- // Mock loadAllYaml to return parsed CRD
149
- const mockCrd = [{ kind: "CustomResourceDefinition" }];
150
- client_node_1.loadAllYaml.mockReturnValue(mockCrd);
151
- // Call the function
152
- const result = await (0, generate_1.readOrFetchCrd)(mockOpts);
153
- // Assert fs and loadAllYaml were called with correct args
154
- (0, globals_1.expect)(fs_1.default.existsSync).toHaveBeenCalledWith(absoluteFilePath);
155
- (0, globals_1.expect)(fs_1.default.readFileSync).toHaveBeenCalledWith(absoluteFilePath, "utf8");
156
- (0, globals_1.expect)(client_node_1.loadAllYaml).toHaveBeenCalledWith("mock file content");
157
- // Assert the result matches the mocked CRD
158
- (0, globals_1.expect)(result).toEqual(mockCrd);
159
- // Assert log function was called with correct message
160
- (0, globals_1.expect)(mockOpts.logFn).toHaveBeenCalledWith("Attempting to load mock-file-path as a local file");
161
- });
162
- });
163
- (0, globals_1.describe)("readOrFetchCrd with URL", () => {
164
- let mockOpts;
165
- (0, globals_1.beforeEach)(() => {
166
- globals_1.jest.clearAllMocks();
167
- mockOpts = {
168
- source: "http://example.com/mock-crd",
169
- logFn: globals_1.jest.fn(),
170
- };
171
- // Mock resolveFilePath to simulate URL logic
172
- const { resolveFilePath } = globals_1.jest.requireMock("./generate");
173
- resolveFilePath.mockReturnValue("mock-file-path");
174
- // Ensure fs.existsSync returns false for URL tests to skip file logic
175
- fs_1.default.existsSync.mockReturnValue(false);
176
- });
177
- (0, globals_1.test)("should fetch CRD from a URL and parse YAML", async () => {
178
- const { tryParseUrl } = globals_1.jest.requireMock("./generate");
179
- tryParseUrl.mockReturnValue(new URL("http://example.com/mock-crd"));
180
- // Mock fetch to return a valid response
181
- fetch_1.fetch.mockResolvedValue({
182
- ok: true,
183
- data: "mock fetched data",
184
- status: 0,
185
- statusText: "",
186
- });
187
- // Mock loadAllYaml to return parsed CRD
188
- const mockCrd = [{ kind: "CustomResourceDefinition" }];
189
- client_node_1.loadAllYaml.mockReturnValue(mockCrd);
190
- // Call the function
191
- const result = await (0, generate_1.readOrFetchCrd)(mockOpts);
192
- // Assert fetch was called with correct URL
193
- (0, globals_1.expect)(fetch_1.fetch).toHaveBeenCalledWith("http://example.com/mock-crd");
194
- // Assert loadAllYaml was called with fetched data
195
- (0, globals_1.expect)(client_node_1.loadAllYaml).toHaveBeenCalledWith("mock fetched data");
196
- // Assert the result matches the mocked CRD
197
- (0, globals_1.expect)(result).toEqual(mockCrd);
198
- // Assert log function was called with correct message
199
- (0, globals_1.expect)(mockOpts.logFn).toHaveBeenCalledWith("Attempting to load http://example.com/mock-crd as a URL");
200
- });
201
- });
202
- (0, globals_1.describe)("readOrFetchCrd from Kubernetes cluster", () => {
203
- let mockOpts;
204
- (0, globals_1.beforeEach)(() => {
205
- globals_1.jest.clearAllMocks();
206
- mockOpts = {
207
- source: "my-crd",
208
- logFn: globals_1.jest.fn(),
209
- };
210
- // Mock resolveFilePath and tryParseUrl to return null or invalid results
211
- const { resolveFilePath, tryParseUrl } = globals_1.jest.requireMock("./generate");
212
- resolveFilePath.mockReturnValue("mock-file-path");
213
- tryParseUrl.mockReturnValue(null);
214
- // Ensure fs.existsSync returns false to force fallback to Kubernetes
215
- fs_1.default.existsSync.mockReturnValue(false);
216
- });
217
- (0, globals_1.test)("should load CRD from Kubernetes cluster", async () => {
218
- // Mock K8s to return a mocked CRD from the Kubernetes cluster
219
- const mockCrd = { kind: "CustomResourceDefinition" };
220
- const mockK8sGet = globals_1.jest
221
- .fn()
222
- .mockResolvedValue(mockCrd);
223
- fluent_1.K8s.mockReturnValue({ Get: mockK8sGet });
224
- // Call the function
225
- const result = await (0, generate_1.readOrFetchCrd)(mockOpts);
226
- // Assert K8s.Get was called with the correct source
227
- (0, globals_1.expect)(fluent_1.K8s).toHaveBeenCalledWith(upstream_1.CustomResourceDefinition);
228
- (0, globals_1.expect)(mockK8sGet).toHaveBeenCalledWith("my-crd");
229
- // Assert the result matches the mocked CRD
230
- (0, globals_1.expect)(result).toEqual([mockCrd]);
231
- // Assert log function was called with correct message
232
- (0, globals_1.expect)(mockOpts.logFn).toHaveBeenCalledWith("Attempting to read my-crd from the Kubernetes cluster");
233
- });
234
- (0, globals_1.test)("should log an error if Kubernetes cluster read fails", async () => {
235
- // Mock K8s to throw an error
236
- const mockError = new Error("Kubernetes API error");
237
- const mockK8sGet = globals_1.jest.fn().mockRejectedValue(mockError);
238
- fluent_1.K8s.mockReturnValue({ Get: mockK8sGet });
239
- // Call the function and assert that it throws an error
240
- await (0, globals_1.expect)((0, generate_1.readOrFetchCrd)(mockOpts)).rejects.toThrowError(`Failed to read my-crd as a file, URL, or Kubernetes CRD`);
241
- // Assert log function was called with error message
242
- (0, globals_1.expect)(mockOpts.logFn).toHaveBeenCalledWith("Error loading CRD: Kubernetes API error");
243
- // Assert K8s.Get was called with the correct source
244
- (0, globals_1.expect)(fluent_1.K8s).toHaveBeenCalledWith(upstream_1.CustomResourceDefinition);
245
- (0, globals_1.expect)(mockK8sGet).toHaveBeenCalledWith("my-crd");
246
- });
247
- });
248
- (0, globals_1.describe)("readOrFetchCrd error handling", () => {
249
- let mockOpts;
250
- (0, globals_1.beforeEach)(() => {
251
- globals_1.jest.clearAllMocks();
252
- mockOpts = {
253
- source: "mock-source",
254
- logFn: globals_1.jest.fn(),
255
- };
256
- });
257
- (0, globals_1.test)("should throw an error if file reading fails", async () => {
258
- fs_1.default.existsSync.mockReturnValue(true);
259
- fs_1.default.readFileSync.mockImplementation(() => {
260
- throw new Error("File read error");
261
- });
262
- await (0, globals_1.expect)((0, generate_1.readOrFetchCrd)(mockOpts)).rejects.toThrowError("Failed to read mock-source as a file, URL, or Kubernetes CRD");
263
- (0, globals_1.expect)(mockOpts.logFn).toHaveBeenCalledWith("Error loading CRD: File read error");
264
- });
265
- });
266
- (0, globals_1.describe)("convertCRDtoTS with invalid CRD", () => {
267
- (0, globals_1.test)("should skip CRD with no versions", async () => {
268
- const invalidCrd = {
269
- ...sampleCrd,
270
- spec: {
271
- ...sampleCrd.spec,
272
- versions: [], // CRD with no versions
273
- },
274
- };
275
- const options = {
276
- source: "mock-source",
277
- language: "ts",
278
- logFn: globals_1.jest.fn(), // Ensure the mock log function is set
279
- directory: "test-dir",
280
- plain: false,
281
- npmPackage: "kubernetes-fluent-client",
282
- };
283
- const result = await (0, generate_1.convertCRDtoTS)(invalidCrd, options);
284
- // Assert that result is empty due to invalid CRD
285
- (0, globals_1.expect)(result).toEqual([]);
286
- // Assert the log function is called with the correct message
287
- (0, globals_1.expect)(options.logFn).toHaveBeenCalledWith("Skipping movies.example.com, it does not appear to be a CRD");
288
- });
289
- (0, globals_1.test)("should handle schema with no OpenAPI schema", async () => {
290
- // Modify the sampleCrd to simulate the invalid CRD
291
- const invalidCrd = {
292
- ...sampleCrd,
293
- spec: {
294
- ...sampleCrd.spec,
295
- versions: [
296
- {
297
- name: "v1",
298
- served: true,
299
- storage: true,
300
- schema: undefined, // No OpenAPI schema
301
- },
302
- ],
303
- },
304
- };
305
- const options = {
306
- source: "mock-source",
307
- language: "ts",
308
- logFn: globals_1.jest.fn(), // Mock log function
309
- directory: "test-dir",
310
- plain: false,
311
- npmPackage: "kubernetes-fluent-client",
312
- };
313
- // Call the convertCRDtoTS function with the invalid CRD
314
- const result = await (0, generate_1.convertCRDtoTS)(invalidCrd, options);
315
- // Assert that result is empty due to invalid schema
316
- (0, globals_1.expect)(result).toEqual([]);
317
- // Assert that the log function was called with the appropriate message
318
- (0, globals_1.expect)(options.logFn).toHaveBeenCalledWith("Skipping movies.example.com, it does not appear to have a valid schema");
319
- });
320
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=helpers.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.test.d.ts","sourceRoot":"","sources":["../src/helpers.test.ts"],"names":[],"mappings":""}
@@ -1,37 +0,0 @@
1
- "use strict";
2
- // SPDX-License-Identifier: Apache-2.0
3
- // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- const globals_1 = require("@jest/globals");
6
- const helpers_1 = require("./helpers");
7
- (0, globals_1.describe)("helpers", () => {
8
- (0, globals_1.test)("fromEnv for NodeJS", () => {
9
- (0, globals_1.expect)(() => {
10
- (0, helpers_1.fromEnv)("MY_MISSING_ENV_VAR");
11
- }).toThrowError("Environment variable MY_MISSING_ENV_VAR is not set");
12
- process.env.MY_ENV_VAR = "my-value";
13
- (0, globals_1.expect)((0, helpers_1.fromEnv)("MY_ENV_VAR")).toEqual("my-value");
14
- delete process.env.MY_ENV_VAR;
15
- });
16
- });
17
- (0, globals_1.describe)("Cluster Wait Function", () => {
18
- (0, globals_1.it)("should resolve if the cluster is already ready", async () => {
19
- const cluster = await (0, helpers_1.waitForCluster)(5);
20
- (0, globals_1.expect)(cluster).toEqual({ server: "http://jest-test:8080" });
21
- });
22
- });
23
- (0, globals_1.describe)("hasLogs function", () => {
24
- (0, globals_1.it)("should return true for known kinds", () => {
25
- (0, globals_1.expect)((0, helpers_1.hasLogs)("Pod")).toBe(true);
26
- (0, globals_1.expect)((0, helpers_1.hasLogs)("DaemonSet")).toBe(true);
27
- (0, globals_1.expect)((0, helpers_1.hasLogs)("ReplicaSet")).toBe(true);
28
- (0, globals_1.expect)((0, helpers_1.hasLogs)("Service")).toBe(true);
29
- (0, globals_1.expect)((0, helpers_1.hasLogs)("StatefulSet")).toBe(true);
30
- (0, globals_1.expect)((0, helpers_1.hasLogs)("Deployment")).toBe(true);
31
- });
32
- (0, globals_1.it)("should return false for unknown kinds", () => {
33
- (0, globals_1.expect)((0, helpers_1.hasLogs)("Unknown")).toBe(false);
34
- (0, globals_1.expect)((0, helpers_1.hasLogs)("")).toBe(false);
35
- (0, globals_1.expect)((0, helpers_1.hasLogs)("RandomKind")).toBe(false);
36
- });
37
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=kinds.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"kinds.test.d.ts","sourceRoot":"","sources":["../src/kinds.test.ts"],"names":[],"mappings":""}
@@ -1,155 +0,0 @@
1
- "use strict";
2
- // SPDX-License-Identifier: Apache-2.0
3
- // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- const globals_1 = require("@jest/globals");
6
- const index_1 = require("./index");
7
- const kinds_1 = require("./kinds");
8
- const testCases = [
9
- {
10
- name: index_1.kind.Event,
11
- expected: { group: "events.k8s.io", version: "v1", kind: "Event" },
12
- },
13
- {
14
- name: index_1.kind.CoreEvent,
15
- expected: { group: "", version: "v1", kind: "Event" },
16
- },
17
- {
18
- name: index_1.kind.ClusterRole,
19
- expected: { group: "rbac.authorization.k8s.io", version: "v1", kind: "ClusterRole" },
20
- },
21
- {
22
- name: index_1.kind.ClusterRoleBinding,
23
- expected: { group: "rbac.authorization.k8s.io", version: "v1", kind: "ClusterRoleBinding" },
24
- },
25
- {
26
- name: index_1.kind.Role,
27
- expected: { group: "rbac.authorization.k8s.io", version: "v1", kind: "Role" },
28
- },
29
- {
30
- name: index_1.kind.RoleBinding,
31
- expected: { group: "rbac.authorization.k8s.io", version: "v1", kind: "RoleBinding" },
32
- },
33
- { name: index_1.kind.Pod, expected: { group: "", version: "v1", kind: "Pod" } },
34
- { name: index_1.kind.Deployment, expected: { group: "apps", version: "v1", kind: "Deployment" } },
35
- { name: index_1.kind.StatefulSet, expected: { group: "apps", version: "v1", kind: "StatefulSet" } },
36
- { name: index_1.kind.DaemonSet, expected: { group: "apps", version: "v1", kind: "DaemonSet" } },
37
- { name: index_1.kind.Job, expected: { group: "batch", version: "v1", kind: "Job" } },
38
- { name: index_1.kind.CronJob, expected: { group: "batch", version: "v1", kind: "CronJob" } },
39
- { name: index_1.kind.ConfigMap, expected: { group: "", version: "v1", kind: "ConfigMap" } },
40
- { name: index_1.kind.Secret, expected: { group: "", version: "v1", kind: "Secret" } },
41
- { name: index_1.kind.Service, expected: { group: "", version: "v1", kind: "Service" } },
42
- { name: index_1.kind.ServiceAccount, expected: { group: "", version: "v1", kind: "ServiceAccount" } },
43
- { name: index_1.kind.Namespace, expected: { group: "", version: "v1", kind: "Namespace" } },
44
- {
45
- name: index_1.kind.HorizontalPodAutoscaler,
46
- expected: { group: "autoscaling", version: "v2", kind: "HorizontalPodAutoscaler" },
47
- },
48
- {
49
- name: index_1.kind.CustomResourceDefinition,
50
- expected: { group: "apiextensions.k8s.io", version: "v1", kind: "CustomResourceDefinition" },
51
- },
52
- { name: index_1.kind.Ingress, expected: { group: "networking.k8s.io", version: "v1", kind: "Ingress" } },
53
- {
54
- name: index_1.kind.NetworkPolicy,
55
- expected: {
56
- group: "networking.k8s.io",
57
- version: "v1",
58
- kind: "NetworkPolicy",
59
- plural: "networkpolicies",
60
- },
61
- },
62
- { name: index_1.kind.Node, expected: { group: "", version: "v1", kind: "Node" } },
63
- { name: index_1.kind.PersistentVolume, expected: { group: "", version: "v1", kind: "PersistentVolume" } },
64
- {
65
- name: index_1.kind.PersistentVolumeClaim,
66
- expected: { group: "", version: "v1", kind: "PersistentVolumeClaim" },
67
- },
68
- { name: index_1.kind.Pod, expected: { group: "", version: "v1", kind: "Pod" } },
69
- {
70
- name: index_1.kind.PodDisruptionBudget,
71
- expected: { group: "policy", version: "v1", kind: "PodDisruptionBudget" },
72
- },
73
- { name: index_1.kind.PodTemplate, expected: { group: "", version: "v1", kind: "PodTemplate" } },
74
- { name: index_1.kind.ReplicaSet, expected: { group: "apps", version: "v1", kind: "ReplicaSet" } },
75
- {
76
- name: index_1.kind.ReplicationController,
77
- expected: { group: "", version: "v1", kind: "ReplicationController" },
78
- },
79
- { name: index_1.kind.ResourceQuota, expected: { group: "", version: "v1", kind: "ResourceQuota" } },
80
- {
81
- name: index_1.kind.RuntimeClass,
82
- expected: { group: "node.k8s.io", version: "v1", kind: "RuntimeClass" },
83
- },
84
- { name: index_1.kind.Secret, expected: { group: "", version: "v1", kind: "Secret" } },
85
- {
86
- name: index_1.kind.SelfSubjectAccessReview,
87
- expected: { group: "authorization.k8s.io", version: "v1", kind: "SelfSubjectAccessReview" },
88
- },
89
- {
90
- name: index_1.kind.SelfSubjectRulesReview,
91
- expected: { group: "authorization.k8s.io", version: "v1", kind: "SelfSubjectRulesReview" },
92
- },
93
- { name: index_1.kind.Service, expected: { group: "", version: "v1", kind: "Service" } },
94
- { name: index_1.kind.ServiceAccount, expected: { group: "", version: "v1", kind: "ServiceAccount" } },
95
- { name: index_1.kind.StatefulSet, expected: { group: "apps", version: "v1", kind: "StatefulSet" } },
96
- {
97
- name: index_1.kind.StorageClass,
98
- expected: { group: "storage.k8s.io", version: "v1", kind: "StorageClass" },
99
- },
100
- {
101
- name: index_1.kind.SubjectAccessReview,
102
- expected: { group: "authorization.k8s.io", version: "v1", kind: "SubjectAccessReview" },
103
- },
104
- {
105
- name: index_1.kind.TokenReview,
106
- expected: { group: "authentication.k8s.io", version: "v1", kind: "TokenReview" },
107
- },
108
- {
109
- name: index_1.kind.ValidatingWebhookConfiguration,
110
- expected: {
111
- group: "admissionregistration.k8s.io",
112
- version: "v1",
113
- kind: "ValidatingWebhookConfiguration",
114
- },
115
- },
116
- {
117
- name: index_1.kind.VolumeAttachment,
118
- expected: { group: "storage.k8s.io", version: "v1", kind: "VolumeAttachment" },
119
- },
120
- ];
121
- globals_1.test.each(testCases)("should return the correct GroupVersionKind for '%s'", ({ name, expected }) => {
122
- const { name: modelName } = name;
123
- const gvk = (0, index_1.modelToGroupVersionKind)(modelName);
124
- try {
125
- (0, globals_1.expect)(gvk.group).toBe(expected.group);
126
- (0, globals_1.expect)(gvk.version).toBe(expected.version);
127
- (0, globals_1.expect)(gvk.kind).toBe(expected.kind);
128
- }
129
- catch (error) {
130
- console.error(`Failed for model ${modelName}: Expected GroupVersionKind to be ${JSON.stringify(expected)}, but got ${JSON.stringify(gvk)}`);
131
- throw error;
132
- }
133
- });
134
- (0, globals_1.test)("new registered type", () => {
135
- class foo {
136
- kind;
137
- group;
138
- constructor() {
139
- this.kind = "foo";
140
- this.group = "bar";
141
- }
142
- }
143
- (0, kinds_1.RegisterKind)(foo, new foo());
144
- });
145
- (0, globals_1.test)("throws an error for already registered", () => {
146
- const { name } = index_1.kind.VolumeAttachment;
147
- const gvk = (0, index_1.modelToGroupVersionKind)(name);
148
- (0, globals_1.expect)(() => {
149
- (0, kinds_1.RegisterKind)(index_1.kind.VolumeAttachment, {
150
- kind: gvk.kind,
151
- version: gvk.version,
152
- group: gvk.group,
153
- });
154
- }).toThrow(`GVK ${name} already registered`);
155
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=postProcessing.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"postProcessing.test.d.ts","sourceRoot":"","sources":["../src/postProcessing.test.ts"],"names":[],"mappings":""}