From 2e5a5174604f49b48c910fb50602fdea8e32a2d4 Mon Sep 17 00:00:00 2001 From: Sampark Sharma Date: Tue, 29 Nov 2022 12:16:17 +0000 Subject: [PATCH] Fix test --- packages/cache/__tests__/tar.test.ts | 50 +++++++++++++++++----------- packages/cache/src/internal/tar.ts | 7 ++-- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/packages/cache/__tests__/tar.test.ts b/packages/cache/__tests__/tar.test.ts index e868363f..2143ad89 100644 --- a/packages/cache/__tests__/tar.test.ts +++ b/packages/cache/__tests__/tar.test.ts @@ -73,8 +73,7 @@ test('zstd extract tar', async () => { '--use-compress-program', IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30' ]) - .join(' '), - {cwd: undefined} + .join(' ') ) }) @@ -106,8 +105,7 @@ test('zstd extract tar with windows BSDtar', async () => { '-P', '-C', workspace?.replace(/\\/g, '/') - ].join(' '), - {cwd: undefined} + ].join(' ') ) } }) @@ -137,8 +135,7 @@ test('gzip extract tar', async () => { .concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(['-z']) - .join(' '), - {cwd: undefined} + .join(' ') ) }) @@ -165,8 +162,7 @@ test('gzip extract GNU tar on windows with GNUtar in path', async () => { workspace?.replace(/\\/g, '/'), '--force-local', '-z' - ].join(' '), - {cwd: undefined} + ].join(' ') ) } }) @@ -206,6 +202,7 @@ test('zstd create tar', async () => { IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30' ]) .join(' '), + undefined, // args { cwd: archiveFolder } @@ -252,6 +249,7 @@ test('zstd create tar with windows BSDtar', async () => { CacheFilename.Zstd.replace(/\\/g, '/'), TarFilename.replace(/\\/g, '/') ].join(' '), + undefined, // args { cwd: archiveFolder } @@ -274,8 +272,8 @@ test('gzip create tar', async () => { expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledWith( - `"${tarPath}"`, [ + `"${tarPath}"`, '--posix', '-cf', IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip, @@ -291,6 +289,7 @@ test('gzip create tar', async () => { .concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(['-z']) .join(' '), + undefined, // args { cwd: archiveFolder } @@ -309,15 +308,19 @@ test('zstd list tar', async () => { const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledWith( - [`"${tarPath}"`, '-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P'] + [ + `"${tarPath}"`, + '-tf', + IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, + '-P' + ] .concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat([ '--use-compress-program', IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30' ]) - .join(' '), - {cwd: undefined} + .join(' ') ) }) @@ -343,8 +346,7 @@ test('zstd list tar with windows BSDtar', async () => { '-tf', TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), '-P' - ].join(' '), - {cwd: undefined} + ].join(' ') ) } }) @@ -361,12 +363,16 @@ test('zstdWithoutLong list tar', async () => { const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledWith( - [`"${tarPath}"`, '-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P'] + [ + `"${tarPath}"`, + '-tf', + IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, + '-P' + ] .concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd']) - .join(' '), - {cwd: undefined} + .join(' ') ) }) @@ -381,11 +387,15 @@ test('gzip list tar', async () => { const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledWith( - [`"${tarPath}"`, '-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P'] + [ + `"${tarPath}"`, + '-tf', + IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, + '-P' + ] .concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(['-z']) - .join(' '), - {cwd: undefined} + .join(' ') ) }) diff --git a/packages/cache/src/internal/tar.ts b/packages/cache/src/internal/tar.ts index 7549fb14..f9f91d15 100644 --- a/packages/cache/src/internal/tar.ts +++ b/packages/cache/src/internal/tar.ts @@ -56,7 +56,7 @@ async function getTarArgs( type: string, archivePath = '' ): Promise { - const args = [tarPath.path] + const args = [`"${tarPath.path}"`] const cacheFileName = utils.getCacheFileName(compressionMethod) const tarFile = 'cache.tar' const workingDirectory = getWorkingDirectory() @@ -260,11 +260,10 @@ export async function createTar( compressionMethod: CompressionMethod ): Promise { // Write source directories to manifest.txt to avoid command length limits - const manifestFilename = 'manifest.txt' writeFileSync( - path.join(archiveFolder, manifestFilename), + path.join(archiveFolder, ManifestFilename), sourceDirectories.join('\n') ) const args = await getArgs(compressionMethod, 'create') - await exec(args) + await exec(args, undefined, {cwd: archiveFolder}) }