Skip to content

Commit

Permalink
test: fix zlib-brotli output assumptions
Browse files Browse the repository at this point in the history
On different architectures, it's possible for the compression algorithm
to produce slightly different outputs. So, don't assume we will
always get the same compressed output on all architectures. Instead,
verify that the decompressing pre-compressed string functions
correctly.

Fixes: #25568

Backport-PR-URL: #27681
PR-URL: #25697
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
AdamMajer authored and MylesBorins committed May 16, 2019
1 parent 93edf90 commit 3ca5f23
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions test/parallel/test-zlib-brotli-from-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@ const inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing eli'
' diam ipsum. Suspendisse nec ullamcorper odio. Vestibulu' +
'm arcu mi, sodales non suscipit id, ultrices ut massa. S' +
'ed ac sem sit amet arcu malesuada fermentum. Nunc sed. ';
const expectedBase64Compress = 'G/gBQBwHdky2aHV5KK9Snf05//1pPdmNw/7232fnIm1IB' +
'K1AA8RsN8OB8Nb7Lpgk3UWWUlzQXZyHQeBBbXMTQXC1j7' +
'wg3LJs9LqOGHRH2bj/a2iCTLLx8hBOyTqgoVuD1e+Qqdn' +
'f1rkUNyrWq6LtOhWgxP3QUwdhKGdZm3rJWaDDBV7+pDk1' +
'MIkrmjp4ma2xVi5MsgJScA3tP1I7mXeby6MELozrwoBQD' +
'mVTnEAicZNj4lkGqntJe2qSnGyeMmcFgraK94vCg/4iLu' +
'Tw5RhKhnVY++dZ6niUBmRqIutsjf5TzwF5iAg8a9UkjF5' +
'2eZ0tB2vo6v8SqVfNMkBmmhxr0NT9LkYF69aEjlYzj7IE' +
'KmEUQf1HBogRYhFIt4ymRNEgHAIzOyNEsQM=';
const compressedString = 'G/gBQBwHdky2aHV5KK9Snf05//1pPdmNw/7232fnIm1IB' +
'K1AA8RsN8OB8Nb7Lpgk3UWWUlzQXZyHQeBBbXMTQXC1j7' +
'wg3LJs9LqOGHRH2bj/a2iCTLLx8hBOyTqgoVuD1e+Qqdn' +
'f1rkUNyrWq6LtOhWgxP3QUwdhKGdZm3rJWaDDBV7+pDk1' +
'MIkrmjp4ma2xVi5MsgJScA3tP1I7mXeby6MELozrwoBQD' +
'mVTnEAicZNj4lkGqntJe2qSnGyeMmcFgraK94vCg/4iLu' +
'Tw5RhKhnVY++dZ6niUBmRqIutsjf5TzwF5iAg8a9UkjF5' +
'2eZ0tB2vo6v8SqVfNMkBmmhxr0NT9LkYF69aEjlYzj7IE' +
'KmEUQf1HBogRYhFIt4ymRNEgHAIzOyNEsQM=';

zlib.brotliCompress(inputString, common.mustCall((err, buffer) => {
assert.strictEqual(buffer.toString('base64'), expectedBase64Compress);
assert(inputString.length > buffer.length);

zlib.brotliDecompress(buffer, common.mustCall((err, buffer) => {
assert.strictEqual(buffer.toString(), inputString);
}));
}));

const buffer = Buffer.from(expectedBase64Compress, 'base64');
const buffer = Buffer.from(compressedString, 'base64');
zlib.brotliDecompress(buffer, common.mustCall((err, buffer) => {
assert.strictEqual(buffer.toString(), inputString);
}));

0 comments on commit 3ca5f23

Please sign in to comment.