mirror of https://github.com/actions/toolkit
artifact: tests for stream digest util
parent
c5d1911357
commit
e3549a9c58
|
@ -10,6 +10,7 @@ import {
|
||||||
getInitialRetryIntervalInMilliseconds,
|
getInitialRetryIntervalInMilliseconds,
|
||||||
getRetryMultiplier
|
getRetryMultiplier
|
||||||
} from '../src/internal/config-variables'
|
} from '../src/internal/config-variables'
|
||||||
|
import {Readable} from 'stream'
|
||||||
|
|
||||||
jest.mock('../src/internal/config-variables')
|
jest.mock('../src/internal/config-variables')
|
||||||
|
|
||||||
|
@ -74,15 +75,18 @@ describe('Utils', () => {
|
||||||
const size = 24
|
const size = 24
|
||||||
const uncompressedLength = 100
|
const uncompressedLength = 100
|
||||||
const range = 'bytes 0-199/200'
|
const range = 'bytes 0-199/200'
|
||||||
|
const digest =
|
||||||
|
'5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269'
|
||||||
const headers = utils.getUploadHeaders(
|
const headers = utils.getUploadHeaders(
|
||||||
contentType,
|
contentType,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
uncompressedLength,
|
uncompressedLength,
|
||||||
size,
|
size,
|
||||||
range
|
range,
|
||||||
|
digest
|
||||||
)
|
)
|
||||||
expect(Object.keys(headers).length).toEqual(8)
|
expect(Object.keys(headers).length).toEqual(9)
|
||||||
expect(headers['Accept']).toEqual(
|
expect(headers['Accept']).toEqual(
|
||||||
`application/json;api-version=${utils.getApiVersion()}`
|
`application/json;api-version=${utils.getApiVersion()}`
|
||||||
)
|
)
|
||||||
|
@ -93,6 +97,7 @@ describe('Utils', () => {
|
||||||
expect(headers['x-tfs-filelength']).toEqual(uncompressedLength)
|
expect(headers['x-tfs-filelength']).toEqual(uncompressedLength)
|
||||||
expect(headers['Content-Length']).toEqual(size)
|
expect(headers['Content-Length']).toEqual(size)
|
||||||
expect(headers['Content-Range']).toEqual(range)
|
expect(headers['Content-Range']).toEqual(range)
|
||||||
|
expect(headers['X-Digest']).toEqual(`sha-256=${digest}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Test constructing upload headers with only required parameter', () => {
|
it('Test constructing upload headers with only required parameter', () => {
|
||||||
|
@ -219,4 +224,14 @@ describe('Utils', () => {
|
||||||
const size2 = (await fs.promises.stat(emptyFile2)).size
|
const size2 = (await fs.promises.stat(emptyFile2)).size
|
||||||
expect(size2).toEqual(0)
|
expect(size2).toEqual(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Creates a digest from a readable stream', async () => {
|
||||||
|
const data = 'lorem ipsum'
|
||||||
|
const stream = Readable.from(data)
|
||||||
|
const digest = await utils.digestForStream(stream)
|
||||||
|
|
||||||
|
expect(digest).toBe(
|
||||||
|
'5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269'
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue