Skip to content

Commit

Permalink
Add Test for failing case for both pwsh and powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
luketomlinson committed May 14, 2021
1 parent 008211e commit 495c529
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions packages/tool-cache/__tests__/tool-cache.test.ts
Expand Up @@ -347,6 +347,22 @@ describe('@actions/tool-cache', function() {
await io.rmRF(tempDir)
}
})
it.each(['pwsh', 'powershell'])(
'unzip properly fails with bad path (%s)',
async powershellTool => {
const originalPath = process.env['PATH']
try {
if (powershellTool === 'powershell' && IS_WINDOWS) {
//remove pwsh from PATH temporarily to test fallback case
process.env['PATH'] = removePWSHFromPath(process.env['PATH'])
}

await expect(tc.extractZip('badPath')).rejects.toThrow()
} finally {
process.env['PATH'] = originalPath
}
}
)
} else if (IS_MAC) {
it('extract .xar', async () => {
const tempDir = path.join(tempPath, 'test-install.xar')
Expand Down Expand Up @@ -579,13 +595,7 @@ describe('@actions/tool-cache', function() {

if (powershellTool === 'powershell' && IS_WINDOWS) {
//remove pwsh from PATH temporarily to test fallback case
const newPath = originalPath
?.split(';')
.filter(segment => {
return !segment.startsWith(`C:\\Program Files\\PowerShell`)
})
.join(';')
process.env['PATH'] = newPath
process.env['PATH'] = removePWSHFromPath(process.env['PATH'])
}

const extPath: string = await tc.extractZip(zipFile)
Expand Down Expand Up @@ -865,3 +875,12 @@ function setGlobal<T>(key: string, value: T | undefined): void {
g[key] = value
}
}

function removePWSHFromPath(path: string | undefined): string {
return (path || '')
.split(';')
.filter(segment => {
return !segment.startsWith(`C:\\Program Files\\PowerShell`)
})
.join(';')
}
Binary file added source.zip
Binary file not shown.

0 comments on commit 495c529

Please sign in to comment.