@@ -25,7 +25,7 @@ import { URI } from 'vscode-uri';
2525import * as openshift from './openshift.js' ;
2626import * as sandbox from './sandbox.js' ;
2727import * as kubeconfig from './kubeconfig.js' ;
28- import { CoreV1Api , KubeConfig } from '@kubernetes/client-node' ;
28+ import { CoreV1Api , KubeConfig , type V1Secret } from '@kubernetes/client-node' ;
2929import got from 'got' ;
3030
3131const context : podmanDesktopApi . ExtensionContext = {
@@ -91,7 +91,7 @@ suite('kubernetes provider connection factory', () => {
9191 config : KubeConfig = new KubeConfig ( ) ,
9292 mockSandboxCalls ?: ( ) => void ,
9393 mockGetPipelineServiceAccountToken ?: ( ) => void ,
94- ) : Promise < { error : Error ; provider : podmanDesktopApi . Provider } | undefined > {
94+ ) : Promise < { error : Error | undefined ; provider : podmanDesktopApi . Provider } > {
9595 const providerMock : podmanDesktopApi . Provider = {
9696 setKubernetesProviderConnectionFactory : vi . fn ( ) ,
9797 registerKubernetesProviderConnection : ( ) => ( {
@@ -106,7 +106,7 @@ suite('kubernetes provider connection factory', () => {
106106 } as unknown as podmanDesktopApi . AuthenticationSession ) ;
107107 await extension . activate ( context ) ;
108108 const connectionFactory = vi . mocked ( providerMock . setKubernetesProviderConnectionFactory ) . mock . calls [ 0 ] [ 0 ] ;
109- let verificationError : Error ;
109+ let verificationError : Error | undefined = undefined ;
110110 try {
111111 mockSandboxCalls ?.( ) ;
112112 if ( ! mockSandboxCalls ) {
@@ -125,9 +125,12 @@ suite('kubernetes provider connection factory', () => {
125125 vi . spyOn ( openshift , 'whoami' ) . mockResolvedValue ( 'system:serviceaccount:username-dev:pipeline' ) ;
126126 vi . spyOn ( kubeconfig , 'createOrLoadFromFile' ) . mockReturnValue ( config ) ;
127127 vi . spyOn ( kubeconfig , 'exportToFile' ) . mockImplementation ( vi . fn ( ) ) ;
128- await connectionFactory . create ( params ) ;
128+
129+ expect ( connectionFactory ) . toBeDefined ( ) ;
130+ expect ( typeof connectionFactory ?. create ) . toBe ( 'function' ) ;
131+ await connectionFactory ?. create ?.( params ) ;
129132 } catch ( e ) {
130- verificationError = e ;
133+ verificationError = e as Error ;
131134 }
132135 return {
133136 error : verificationError ,
@@ -139,7 +142,7 @@ suite('kubernetes provider connection factory', () => {
139142 const { error : verificationError } = await callCreate ( ) ;
140143
141144 expect ( verificationError ) . toBeDefined ( ) ;
142- expect ( verificationError . message ) . is . equal ( 'Context name is required.' ) ;
145+ expect ( verificationError ? .message ) . is . equal ( 'Context name is required.' ) ;
143146 } ) ;
144147
145148 test ( 'creates new context for sandbox with specified url/token and sets it as default context' , async ( ) => {
@@ -344,8 +347,8 @@ suite('kubernetes provider connection factory', () => {
344347 } ,
345348 ] ,
346349 } ) ;
347- vi . spyOn ( CoreV1Api . prototype , 'createNamespacedSecret' ) . mockResolvedValue ( undefined ) ;
348- const responseError = new Error ( ) ;
350+ vi . spyOn ( CoreV1Api . prototype , 'createNamespacedSecret' ) . mockResolvedValue ( { } as V1Secret ) ;
351+ const responseError : any = new Error ( ) ;
349352 responseError [ 'response' ] = {
350353 statusCode : 404 ,
351354 } ;
@@ -444,7 +447,7 @@ test('push image to sandbox does not change title after it is finished', async (
444447 return config ;
445448 } ) ;
446449 const registerCommandMock = vi . mocked ( podmanDesktopApi . commands . registerCommand ) ;
447- let commandCallback : ( ...args : any [ ] ) => any ;
450+ let commandCallback : ( ( ...args : any [ ] ) => any ) | undefined ;
448451 registerCommandMock . mockImplementation ( ( commandId : string , callback : ( ...args : any [ ] ) => any ) => {
449452 if ( commandId === 'sandbox.image.push.to.cluster' ) {
450453 commandCallback = callback ;
@@ -456,7 +459,7 @@ test('push image to sandbox does not change title after it is finished', async (
456459 let registeredConnection : { status : ( ) => any } ;
457460 const providerMock : podmanDesktopApi . Provider = {
458461 setKubernetesProviderConnectionFactory : vi . fn ( ) ,
459- registerKubernetesProviderConnection : connection => {
462+ registerKubernetesProviderConnection : ( connection : podmanDesktopApi . KubernetesProviderConnection ) => {
460463 registeredConnection = connection ;
461464 return {
462465 dispose : vi . fn ( ) ,
@@ -479,20 +482,20 @@ test('push image to sandbox does not change title after it is finished', async (
479482 const progress : podmanDesktopApi . Progress < { message ?: string ; increment ?: number } > = {
480483 report,
481484 } ;
482- task ( progress , undefined ) ;
483- return ;
485+ task ( progress , { } as podmanDesktopApi . CancellationToken ) ;
486+ return Promise . resolve ( ) ;
484487 } ,
485488 ) ;
486- let pushImageCallback : ( name : string , data ?: string ) => void ;
489+ let pushImageCallback : ( ( name : string , data ?: string ) => void ) | undefined ;
487490 vi . mocked ( podmanDesktopApi . containerEngine . pushImage ) . mockImplementation (
488- async (
491+ ( async (
489492 _engineId : string ,
490493 _imageId : string ,
491- callback : ( name : string , data : string ) => Promise < void > ,
494+ callback : ( name : string , data ? : string ) => void ,
492495 _authInfo ?: podmanDesktopApi . ContainerAuthInfo ,
493496 ) => {
494497 pushImageCallback = callback ;
495- } ,
498+ } ) as any ,
496499 ) ;
497500 await extension . activate ( context ) ;
498501
@@ -504,14 +507,14 @@ test('push image to sandbox does not change title after it is finished', async (
504507
505508 const imageInfo = { engineId : 'podman' , name : 'imageName' , tag : 'registry-host/repository/image' } ;
506509
507- await Promise . resolve ( commandCallback ( ...[ imageInfo ] ) ) ;
510+ await Promise . resolve ( commandCallback ?. ( ...[ imageInfo ] ) ) ;
508511
509512 await vi . waitFor ( async ( ) => {
510513 expect ( pushImageCallback ) . toBeDefined ( ) ;
511514 } , 3000 ) ;
512515
513- pushImageCallback ( 'data' , 'data-chunk-1' ) ;
514- pushImageCallback ( 'end' ) ;
516+ pushImageCallback ?. ( 'data' , 'data-chunk-1' ) ;
517+ pushImageCallback ?. ( 'end' ) ;
515518
516519 expect ( report ) . not . toHaveBeenCalledWith ( expect . objectContaining ( { message : 'data-chunk-1' } ) ) ;
517520} ) ;
0 commit comments