@@ -2,6 +2,7 @@ import { describe, it } from 'node:test';
22import { deepEqual , deepStrictEqual , strictEqual } from 'node:assert' ;
33import { V1CustomResourceDefinition , V1Namespace } from './api.js' ;
44import { dumpYaml , loadAllYaml , loadYaml } from './yaml.js' ;
5+ import { KubernetesObject } from './types.js' ;
56
67describe ( 'yaml' , ( ) => {
78 it ( 'should load safely' , ( ) => {
@@ -154,4 +155,54 @@ spec:
154155 // not using strict equality as types are not matching
155156 deepEqual ( actual , expected ) ;
156157 } ) ;
158+
159+ it ( 'should load Knative Service correctly preserving spec' , ( ) => {
160+ const yaml = `apiVersion: serving.knative.dev/v1
161+ kind: Service
162+ metadata:
163+ name: hello-world
164+ spec:
165+ template:
166+ spec:
167+ containers:
168+ - image: ghcr.io/knative/helloworld-go:latest
169+ ports:
170+ - containerPort: 8080
171+ env:
172+ - name: TARGET
173+ value: "World"` ;
174+ const knativeService = loadYaml ( yaml ) as KubernetesObject ;
175+
176+ strictEqual ( knativeService . apiVersion , 'serving.knative.dev/v1' ) ;
177+ strictEqual ( knativeService . kind , 'Service' ) ;
178+ strictEqual ( ( knativeService as any ) . metadata . name , 'hello-world' ) ;
179+ // Verify that the spec is preserved
180+ strictEqual (
181+ ( knativeService as any ) . spec . template . spec . containers [ 0 ] . image ,
182+ 'ghcr.io/knative/helloworld-go:latest' ,
183+ ) ;
184+ strictEqual ( ( knativeService as any ) . spec . template . spec . containers [ 0 ] . ports [ 0 ] . containerPort , 8080 ) ;
185+ strictEqual ( ( knativeService as any ) . spec . template . spec . containers [ 0 ] . env [ 0 ] . name , 'TARGET' ) ;
186+ strictEqual ( ( knativeService as any ) . spec . template . spec . containers [ 0 ] . env [ 0 ] . value , 'World' ) ;
187+ } ) ;
188+
189+ it ( 'should load custom resources correctly' , ( ) => {
190+ const yaml = `apiVersion: example.com/v1
191+ kind: MyCustomResource
192+ metadata:
193+ name: my-resource
194+ spec:
195+ customField: customValue
196+ nestedObject:
197+ key1: value1
198+ key2: value2` ;
199+ const customResource = loadYaml ( yaml ) as KubernetesObject ;
200+
201+ strictEqual ( ( customResource as any ) . apiVersion , 'example.com/v1' ) ;
202+ strictEqual ( ( customResource as any ) . kind , 'MyCustomResource' ) ;
203+ strictEqual ( ( customResource as any ) . metadata . name , 'my-resource' ) ;
204+ strictEqual ( ( customResource as any ) . spec . customField , 'customValue' ) ;
205+ strictEqual ( ( customResource as any ) . spec . nestedObject . key1 , 'value1' ) ;
206+ strictEqual ( ( customResource as any ) . spec . nestedObject . key2 , 'value2' ) ;
207+ } ) ;
157208} ) ;
0 commit comments