11// workloadUtils.test.ts
22import axios from 'axios'
3+ import * as fs from 'fs'
34import * as fsExtra from 'fs-extra'
45import * as fsPromises from 'fs/promises'
56import path from 'path'
@@ -24,13 +25,15 @@ jest.mock('fs/promises', () => ({
2425 writeFile : jest . fn ( ) ,
2526 readdir : jest . fn ( ) ,
2627} ) )
27- jest . mock ( 'fs-extra' , ( ) => ( {
28- readFile : jest . fn ( ) ,
28+ jest . mock ( 'fs' , ( ) => ( {
2929 existsSync : jest . fn ( ) ,
3030 mkdirSync : jest . fn ( ) ,
3131 renameSync : jest . fn ( ) ,
3232 rmSync : jest . fn ( ) ,
3333} ) )
34+ jest . mock ( 'fs-extra' , ( ) => ( {
35+ readFile : jest . fn ( ) ,
36+ } ) )
3437jest . mock ( 'simple-git' , ( ) => ( {
3538 __esModule : true ,
3639 default : jest . fn ( ( ) => ( {
@@ -354,7 +357,7 @@ describe('sparseCloneChart', () => {
354357 // Set up environment variables for tests
355358 process . env = { ...originalEnv , GIT_USER : 'git-user' , GIT_PASSWORD : 'git-password' }
356359 // Mock necessary function responses
357- ; ( fsExtra . existsSync as jest . Mock ) . mockReturnValue ( false )
360+ ; ( fs . existsSync as jest . Mock ) . mockReturnValue ( false )
358361 } )
359362
360363 afterEach ( ( ) => {
@@ -390,16 +393,16 @@ describe('sparseCloneChart', () => {
390393 )
391394
392395 expect ( result ) . toBe ( true )
393- expect ( fsExtra . mkdirSync ) . toHaveBeenCalledWith ( localHelmChartsDir , { recursive : true } )
394- expect ( fsExtra . mkdirSync ) . toHaveBeenCalledWith ( `${ localHelmChartsDir } -newChart` , { recursive : true } )
396+ expect ( fs . mkdirSync ) . toHaveBeenCalledWith ( localHelmChartsDir , { recursive : true } )
397+ expect ( fs . mkdirSync ) . toHaveBeenCalledWith ( `${ localHelmChartsDir } -newChart` , { recursive : true } )
395398 expect ( mockGit . clone ) . toHaveBeenCalledTimes ( 2 ) // Once for catalog repo, once for chart repo
396399 expect ( mockGit . listRemote ) . toHaveBeenCalled ( )
397400 expect ( mockGit . raw ) . toHaveBeenCalledWith ( [ 'sparse-checkout' , 'init' , '--cone' ] )
398401 expect ( mockGit . raw ) . toHaveBeenCalledWith ( [ 'sparse-checkout' , 'set' , 'main/bitnami/cassandra/' ] )
399402 expect ( mockGit . checkout ) . toHaveBeenCalled ( )
400- expect ( fsExtra . renameSync ) . toHaveBeenCalled ( )
401- expect ( fsExtra . rmSync ) . toHaveBeenCalledWith ( `${ localHelmChartsDir } -newChart` , { recursive : true , force : true } )
402- expect ( fsExtra . rmSync ) . toHaveBeenCalledWith ( `${ localHelmChartsDir } /${ chartTargetDirName } /.git` , {
403+ expect ( fs . renameSync ) . toHaveBeenCalled ( )
404+ expect ( fs . rmSync ) . toHaveBeenCalledWith ( `${ localHelmChartsDir } -newChart` , { recursive : true , force : true } )
405+ expect ( fs . rmSync ) . toHaveBeenCalledWith ( `${ localHelmChartsDir } /${ chartTargetDirName } /.git` , {
403406 recursive : true ,
404407 force : true ,
405408 } )
@@ -491,7 +494,7 @@ describe('sparseCloneChart', () => {
491494 listRemote : jest . fn ( ) . mockResolvedValue ( '' ) ,
492495 }
493496 ; ( simpleGit as jest . Mock ) . mockReturnValue ( mockGit )
494- ; ( fsExtra . existsSync as jest . Mock ) . mockReturnValueOnce ( false )
497+ ; ( fs . existsSync as jest . Mock ) . mockReturnValueOnce ( false )
495498
496499 await sparseCloneChart (
497500 gitRepositoryUrl ,
@@ -504,7 +507,7 @@ describe('sparseCloneChart', () => {
504507 allowTeams ,
505508 )
506509
507- expect ( fsExtra . mkdirSync ) . toHaveBeenCalledWith ( localHelmChartsDir , { recursive : true } )
510+ expect ( fs . mkdirSync ) . toHaveBeenCalledWith ( localHelmChartsDir , { recursive : true } )
508511 } )
509512
510513 test ( 'returns false if git provider detection fails' , async ( ) => {
@@ -535,7 +538,7 @@ describe('fetchWorkloadCatalog', () => {
535538 beforeEach ( ( ) => {
536539 jest . clearAllMocks ( )
537540 process . env = { ...originalEnv , GIT_USER : 'git-user' , GIT_PASSWORD : 'git-password' }
538- ; ( fsExtra . existsSync as jest . Mock ) . mockReturnValue ( false )
541+ ; ( fs . existsSync as jest . Mock ) . mockReturnValue ( false )
539542
540543 // Mock directory structure
541544 const files = [ '.git' , 'chart1' , 'chart2' , 'README.md' , 'rbac.yaml' ]
@@ -597,7 +600,7 @@ describe('fetchWorkloadCatalog', () => {
597600
598601 const result = await fetchWorkloadCatalog ( url , helmChartsDir , 'admin' )
599602
600- expect ( fsExtra . mkdirSync ) . toHaveBeenCalledWith ( helmChartsDir , { recursive : true } )
603+ expect ( fs . mkdirSync ) . toHaveBeenCalledWith ( helmChartsDir , { recursive : true } )
601604 expect ( mockGit . clone ) . toHaveBeenCalledWith (
602605 'https://git-user:[email protected] /otomi/charts.git' , 603606 helmChartsDir ,
@@ -780,7 +783,7 @@ describe('chartRepo', () => {
780783 expect ( mockGit . raw ) . toHaveBeenCalledWith ( [ 'sparse-checkout' , 'init' , '--cone' ] )
781784 expect ( mockGit . raw ) . toHaveBeenCalledWith ( [ 'sparse-checkout' , 'set' , 'charts/my-chart' ] )
782785 expect ( mockGit . checkout ) . toHaveBeenCalledWith ( 'main' )
783- expect ( fsExtra . renameSync ) . toHaveBeenCalledWith ( path . join ( localPath , 'charts/my-chart' ) , finalDestinationPath )
786+ expect ( fs . renameSync ) . toHaveBeenCalledWith ( path . join ( localPath , 'charts/my-chart' ) , finalDestinationPath )
784787 } )
785788
786789 test ( 'addConfig method sets git config' , async ( ) => {
0 commit comments