overload downloadTool to accept destination path (#257)

This commit is contained in:
eric sciple
2019-12-16 11:59:48 -05:00
committed by GitHub
parent 17acd9c66f
commit 61d502068b
2 changed files with 53 additions and 9 deletions

View File

@@ -47,6 +47,47 @@ describe('@actions/tool-cache', function() {
expect(fs.statSync(downPath).size).toBe(35)
})
it('downloads a 35 byte file (dest)', async () => {
const dest = 'test-download-file'
try {
const downPath: string = await tc.downloadTool(
'http://example.com/bytes/35',
dest
)
expect(downPath).toEqual(dest)
expect(fs.existsSync(downPath)).toBeTruthy()
expect(fs.statSync(downPath).size).toBe(35)
} finally {
try {
await fs.promises.unlink(dest)
} catch {
// intentionally empty
}
}
})
it('downloads a 35 byte file (dest requires mkdirp)', async () => {
const dest = 'test-download-dir/test-download-file'
try {
const downPath: string = await tc.downloadTool(
'http://example.com/bytes/35',
dest
)
expect(downPath).toEqual(dest)
expect(fs.existsSync(downPath)).toBeTruthy()
expect(fs.statSync(downPath).size).toBe(35)
} finally {
try {
await fs.promises.unlink(dest)
await fs.promises.rmdir(path.dirname(dest))
} catch {
// intentionally empty
}
}
})
it('downloads a 35 byte file after a redirect', async () => {
nock('http://example.com')
.get('/redirect-to')