Skip to content

Commit

Permalink
add test for single-hash response header
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Mar 22, 2021
1 parent 8d0a0de commit 1d79a1b
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1381,8 +1381,9 @@ describe('File', () => {
it('should validate with crc32c', done => {
file.requestStream = getFakeSuccessfulRequest(data);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(fakeValidationStream as any).test = (algo: string) => {
(fakeValidationStream as any).test = (algo: string, value: string) => {
assert.strictEqual(algo, 'crc32c');
assert.strictEqual(value, CRC32C_HASH.substr(4));
return true;
};
file
Expand All @@ -1408,7 +1409,11 @@ describe('File', () => {
it('should validate with md5', done => {
file.requestStream = getFakeSuccessfulRequest(data);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(fakeValidationStream as any).test = () => true;
(fakeValidationStream as any).test = (algo: string, value: string) => {
assert.strictEqual(algo, 'md5');
assert.strictEqual(value, MD5_HASH);
return true;
};
file
.createReadStream({validation: 'md5'})
.on('error', done)
Expand Down Expand Up @@ -1459,6 +1464,40 @@ describe('File', () => {
.on('end', done);
});

it('should handle x-goog-hash with only crc32c', done => {
handleRespOverride = (
err: Error,
res: {},
body: {},
callback: Function
) => {
const rawResponseStream = new PassThrough();
Object.assign(rawResponseStream, {
toJSON() {
return {
headers: {
'x-goog-hash': `crc32c=${CRC32C_HASH}`,
},
};
},
});
callback(null, null, rawResponseStream);
setImmediate(() => {
rawResponseStream.end(data);
});
};

file.requestStream = getFakeSuccessfulRequest(data);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(fakeValidationStream as any).test = (algo: string, value: string) => {
assert.strictEqual(algo, 'crc32c');
assert.strictEqual(value, CRC32C_HASH.substr(4));
return true;
};

file.createReadStream().on('error', done).on('end', done).resume();
});

describe('destroying the through stream', () => {
beforeEach(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit 1d79a1b

Please sign in to comment.