Skip to content

Commit

Permalink
Modify test to confirm overwrite behavior for xar
Browse files Browse the repository at this point in the history
  • Loading branch information
luketomlinson committed May 14, 2021
1 parent 495c529 commit b31bbe5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions packages/tool-cache/__tests__/tool-cache.test.ts
Expand Up @@ -243,6 +243,10 @@ describe('@actions/tool-cache', function() {
const _7zFile: string = path.join(tempDir, 'test.7z')
await io.cp(path.join(__dirname, 'data', 'test.7z'), _7zFile)

const destDir = path.join(tempDir, 'destination')
await io.mkdirP(destDir)
fs.writeFileSync(path.join(destDir, 'file.txt'), 'overwriteMe')

// extract/cache
const extPath: string = await tc.extract7z(_7zFile)
await tc.cacheDir(extPath, 'my-7z-contents', '1.1.0')
Expand All @@ -251,6 +255,9 @@ describe('@actions/tool-cache', function() {
expect(fs.existsSync(toolPath)).toBeTruthy()
expect(fs.existsSync(`${toolPath}.complete`)).toBeTruthy()
expect(fs.existsSync(path.join(toolPath, 'file.txt'))).toBeTruthy()
expect(fs.readFileSync(path.join(toolPath, 'file.txt'), 'utf8')).toBe(
'file.txt contents'
)
expect(
fs.existsSync(path.join(toolPath, 'file-with-ç-character.txt'))
).toBeTruthy()
Expand Down Expand Up @@ -376,14 +383,21 @@ describe('@actions/tool-cache', function() {
cwd: sourcePath
})

const destDir = path.join(tempDir, 'destination')
await io.mkdirP(destDir)
fs.writeFileSync(path.join(destDir, 'file.txt'), 'overwriteMe')

// extract/cache
const extPath: string = await tc.extractXar(targetPath, undefined, '-x')
const extPath: string = await tc.extractXar(targetPath, destDir, ['-x'])
await tc.cacheDir(extPath, 'my-xar-contents', '1.1.0')
const toolPath: string = tc.find('my-xar-contents', '1.1.0')

expect(fs.existsSync(toolPath)).toBeTruthy()
expect(fs.existsSync(`${toolPath}.complete`)).toBeTruthy()
expect(fs.existsSync(path.join(toolPath, 'file.txt'))).toBeTruthy()
expect(fs.readFileSync(path.join(toolPath, 'file.txt'), 'utf8')).toBe(
'file.txt contents'
)
expect(
fs.existsSync(path.join(toolPath, 'file-with-ç-character.txt'))
).toBeTruthy()
Expand Down Expand Up @@ -876,8 +890,8 @@ function setGlobal<T>(key: string, value: T | undefined): void {
}
}

function removePWSHFromPath(path: string | undefined): string {
return (path || '')
function removePWSHFromPath(pathEnv: string | undefined): string {
return (pathEnv || '')
.split(';')
.filter(segment => {
return !segment.startsWith(`C:\\Program Files\\PowerShell`)
Expand Down
2 changes: 1 addition & 1 deletion packages/tool-cache/src/tool-cache.ts
Expand Up @@ -354,7 +354,7 @@ async function extractZipWin(file: string, dest: string): Promise<void> {
`$ErrorActionPreference = 'Stop' ;`,
`try { Add-Type -AssemblyName System.IO.Compression.ZipFile } catch { } ;`,
`try { [System.IO.Compression.ZipFile]::ExtractToDirectory('${escapedFile}', '${escapedDest}', $true) }`,
`catch { if ($_.Exception.GetType().FullName -eq 'System.Management.Automation.MethodException'){ Expand-Archive -LiteralPath '${escapedFile}' -DestinationPath '${escapedDest}' -Force } else { $_ } } ;`
`catch { if ($_.Exception.GetType().FullName -eq 'System.Management.Automation.MethodException'){ Expand-Archive -LiteralPath '${escapedFile}' -DestinationPath '${escapedDest}' -Force } else { throw $_ } } ;`
].join(' ')

const args = [
Expand Down
Binary file removed source.zip
Binary file not shown.

0 comments on commit b31bbe5

Please sign in to comment.