|
1 | 1 | import { describe, it } from 'node:test';
|
2 | 2 | import { deepEqual, deepStrictEqual, strictEqual } from 'node:assert';
|
3 |
| -import { V1CustomResourceDefinition, V1Namespace } from './api.js'; |
| 3 | +import { V1CustomResourceDefinition, V1Namespace, V1Pod } from './api.js'; |
4 | 4 | import { dumpYaml, loadAllYaml, loadYaml } from './yaml.js';
|
5 | 5 |
|
6 | 6 | describe('yaml', () => {
|
@@ -84,22 +84,27 @@ spec:
|
84 | 84 | const objects = loadAllYaml(yaml);
|
85 | 85 |
|
86 | 86 | strictEqual(objects.length, 3);
|
87 |
| - strictEqual(objects[0].kind, 'Namespace'); |
88 |
| - strictEqual(objects[1].kind, 'Pod'); |
89 |
| - strictEqual(objects[0].metadata.name, 'some-namespace'); |
90 |
| - strictEqual(objects[1].metadata.name, 'some-pod'); |
91 |
| - strictEqual(objects[1].metadata.namespace, 'some-ns'); |
92 |
| - strictEqual(objects[2].apiVersion, 'apiextensions.k8s.io/v1'); |
93 |
| - strictEqual(objects[2].kind, 'CustomResourceDefinition'); |
94 |
| - strictEqual(objects[2].metadata!.name, 'my-crd.example.com'); |
| 87 | + // Assert specific types for each object |
| 88 | + const ns = objects[0] as V1Namespace; |
| 89 | + const pod = objects[1] as V1Pod; |
| 90 | + const crd = objects[2] as V1CustomResourceDefinition; |
| 91 | + |
| 92 | + strictEqual(ns.kind, 'Namespace'); |
| 93 | + strictEqual(pod.kind, 'Pod'); |
| 94 | + strictEqual(ns.metadata!.name, 'some-namespace'); |
| 95 | + strictEqual(pod.metadata!.name, 'some-pod'); |
| 96 | + strictEqual(pod.metadata!.namespace, 'some-ns'); |
| 97 | + |
| 98 | + strictEqual(crd.apiVersion, 'apiextensions.k8s.io/v1'); |
| 99 | + strictEqual(crd.kind, 'CustomResourceDefinition'); |
| 100 | + strictEqual(crd.metadata!.name, 'my-crd.example.com'); |
95 | 101 | strictEqual(
|
96 |
| - objects[2].spec.versions[0]!.schema!.openAPIV3Schema!.properties!['foobar'] |
97 |
| - .x_kubernetes_int_or_string, |
| 102 | + crd.spec.versions[0]!.schema!.openAPIV3Schema!.properties!['foobar'].x_kubernetes_int_or_string, |
98 | 103 | true,
|
99 | 104 | );
|
100 | 105 | strictEqual(
|
101 |
| - objects[2].spec.versions[0]!.schema!.openAPIV3Schema!.properties!['foobar'][ |
102 |
| - 'x-kubernetes-int-or-string' |
| 106 | + crd.spec.versions[0]!.schema!.openAPIV3Schema!.properties!['foobar'][ |
| 107 | + 'x-kubernetes-int-or-string' // This access is still on the parsed object before type mapping, hence `undefined` is correct |
103 | 108 | ],
|
104 | 109 | undefined,
|
105 | 110 | );
|
|
0 commit comments