@@ -2,7 +2,6 @@ import * as path from 'path';
22import { CodeMaker } from 'codemaker' ;
33import * as fs from 'fs-extra' ;
44import { ImportSpec } from '../../src/config' ;
5- import { K8sSpecialType } from '../../src/import/codegen' ;
65import { ImportK8sManifest , safeParseManifest } from '../../src/import/manifest' ;
76
87describe ( 'ImportK8sManifest' , ( ) => {
@@ -322,16 +321,6 @@ metadata:
322321 expect ( getTypeFromSchema ( 'v1' , 'NonExistentType' , 'spec.field' ) )
323322 . toBeUndefined ( ) ;
324323
325- // Now test the detectSpecialType method which uses getTypeFromSchema
326- const detectSpecialType = ( importer as any ) . detectSpecialType . bind ( importer ) ;
327-
328- // Test with a field that should be a Quantity
329- const quantityType = detectSpecialType ( 'apps/v1' , 'Deployment' , 'spec.template.spec.containers[0].resources.limits.cpu' , '100m' ) ;
330- expect ( quantityType ) . toBe ( K8sSpecialType . QUANTITY ) ;
331-
332- // Test with a field that should be an IntOrString
333- const intOrStringType = detectSpecialType ( 'v1' , 'Service' , 'spec.ports[0].targetPort' , 8080 ) ;
334- expect ( intOrStringType ) . toBe ( K8sSpecialType . INT_OR_STRING ) ;
335324 } ) ;
336325
337326 it ( 'tests IntOrString types from schema for ServicePort.targetPort and HTTPGetAction.port' , ( ) => {
@@ -340,31 +329,15 @@ metadata:
340329
341330 // Access the private methods using type assertion
342331 const getTypeFromSchema = ( importer as any ) . getTypeFromSchema . bind ( importer ) ;
343- const detectSpecialType = ( importer as any ) . detectSpecialType . bind ( importer ) ;
344332
345333 // Test ServicePort.targetPort with different values
346334 expect ( getTypeFromSchema ( 'v1' , 'Service' , 'spec.ports[0].targetPort' ) )
347335 . toBe ( 'io.k8s.apimachinery.pkg.util.intstr.IntOrString' ) ;
348336
349- // Test with numeric value
350- const targetPortNumericType = detectSpecialType ( 'v1' , 'Service' , 'spec.ports[0].targetPort' , 8080 ) ;
351- expect ( targetPortNumericType ) . toBe ( K8sSpecialType . INT_OR_STRING ) ;
352-
353- // Test with string value (named port)
354- const targetPortStringType = detectSpecialType ( 'v1' , 'Service' , 'spec.ports[0].targetPort' , 'http' ) ;
355- expect ( targetPortStringType ) . toBe ( K8sSpecialType . INT_OR_STRING ) ;
356-
357337 // Test HTTPGetAction.port with different values
358338 expect ( getTypeFromSchema ( 'v1' , 'Pod' , 'spec.containers[0].livenessProbe.httpGet.port' ) )
359339 . toBe ( 'io.k8s.apimachinery.pkg.util.intstr.IntOrString' ) ;
360340
361- // Test with numeric value
362- const httpGetPortNumericType = detectSpecialType ( 'v1' , 'Pod' , 'spec.containers[0].livenessProbe.httpGet.port' , 8080 ) ;
363- expect ( httpGetPortNumericType ) . toBe ( K8sSpecialType . INT_OR_STRING ) ;
364-
365- // Test with string value (named port)
366- const httpGetPortStringType = detectSpecialType ( 'v1' , 'Pod' , 'spec.containers[0].livenessProbe.httpGet.port' , 'http' ) ;
367- expect ( httpGetPortStringType ) . toBe ( K8sSpecialType . INT_OR_STRING ) ;
368341 } ) ;
369342
370343 it ( 'tests formatValue handles IntOrString types correctly' , ( ) => {
@@ -395,10 +368,6 @@ metadata:
395368 // Create a test instance
396369 const importer = new ImportK8sManifest ( manifestContent ) ;
397370
398- // Mock the detectSpecialType method to verify field paths
399- const detectSpecialTypeMock = jest . fn ( ) . mockReturnValue ( K8sSpecialType . NONE ) ;
400- ( importer as any ) . detectSpecialType = detectSpecialTypeMock ;
401-
402371 // Access the private formatValue method using type assertion
403372 const formatValue = ( importer as any ) . formatValue . bind ( importer ) ;
404373
@@ -410,15 +379,6 @@ metadata:
410379
411380 formatValue ( arrayValue , 'v1' , 'Pod' , 'spec.containers' ) ;
412381
413- // Verify that detectSpecialType was called with the correct field paths including array indices
414- expect ( detectSpecialTypeMock ) . toHaveBeenCalledWith ( 'v1' , 'Pod' , 'spec.containers[0]' , expect . any ( Object ) ) ;
415- expect ( detectSpecialTypeMock ) . toHaveBeenCalledWith ( 'v1' , 'Pod' , 'spec.containers[1]' , expect . any ( Object ) ) ;
416-
417- // Verify that detectSpecialType was called with the correct field paths for nested properties
418- expect ( detectSpecialTypeMock ) . toHaveBeenCalledWith ( 'v1' , 'Pod' , 'spec.containers[0].name' , 'container1' ) ;
419- expect ( detectSpecialTypeMock ) . toHaveBeenCalledWith ( 'v1' , 'Pod' , 'spec.containers[0].image' , 'nginx' ) ;
420- expect ( detectSpecialTypeMock ) . toHaveBeenCalledWith ( 'v1' , 'Pod' , 'spec.containers[1].name' , 'container2' ) ;
421- expect ( detectSpecialTypeMock ) . toHaveBeenCalledWith ( 'v1' , 'Pod' , 'spec.containers[1].image' , 'redis' ) ;
422382 } ) ;
423383
424384 it ( 'tests formatValue correctly handles multiline strings' , ( ) => {
@@ -654,23 +614,6 @@ app.max_connections=100`;
654614 return ( importer as any ) . generateTypeScript . call ( importer , code , 'k8s-manifest' , { } ) ;
655615 } ;
656616
657- // Mock the detectSpecialType method to return hardcoded values for testing
658-
659- // Replace the detectSpecialType method with a mock implementation
660- ( importer as any ) . detectSpecialType = jest . fn ( ) . mockImplementation (
661- ( _apiVersion : string , _kind : string , fieldPath : string , _value : any ) => {
662- // For testing purposes only - hardcoded special cases
663- if ( fieldPath . includes ( 'cpu' ) || fieldPath . includes ( 'memory' ) ) {
664- return K8sSpecialType . QUANTITY ;
665- }
666-
667- if ( fieldPath . includes ( 'targetPort' ) ) {
668- return K8sSpecialType . INT_OR_STRING ;
669- }
670-
671- return K8sSpecialType . NONE ;
672- } ,
673- ) ;
674617 const code = new CodeMaker ( ) ;
675618
676619 // Set up the mock implementation before generating code
0 commit comments