Skip to content

Commit

Permalink
Add tests for decoding gzipped files
Browse files Browse the repository at this point in the history
  • Loading branch information
Utsav2 committed Dec 13, 2015
1 parent cdf4523 commit 4255d7d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Binary file added test/assets/test-gz.txt
Binary file not shown.
Binary file added test/assets/test-gz.txt.gz
Binary file not shown.
34 changes: 33 additions & 1 deletion test/util/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('download', function () {
nock('http://bower.io', opts.nockOpts)
);

download('http://bower.io/package.tar.gz', destination, opts.downloadOpts)
download(opts.sourceUrl || 'http://bower.io/package.tar.gz', opts.destinationPath || destination, opts.downloadOpts)
.then(function (result) {
if (opts.expect) {
opts.expect(result);
Expand Down Expand Up @@ -174,4 +174,36 @@ describe('download', function () {
}
});
});

describe('gzipped files', function () {

function testGzip(sourceFilename) {
var sourceFile = path.resolve(__dirname, '../assets/' + sourceFilename);
var destinationPath = tempDir.getPath(sourceFilename);

return downloadTest({
response: function(nock) {
nock
.get('/' + sourceFilename)
.replyWithFile(200, sourceFile, {
'Content-Encoding' : 'gzip'
});
},
expect: function() {
expect(fs.readFileSync(destinationPath, 'ascii'))
.to.be('Hello World!\n');
},
sourceUrl: 'http://bower.io/' + sourceFilename,
destinationPath: destinationPath
});
}

it('correctly decodes gzipped files without gz extension', function () {
return testGzip('test-gz.txt');
});

it('correctly decodes gzipped files with gz extension', function () {
return testGzip('test-gz.txt.gz');
});
});
});

0 comments on commit 4255d7d

Please sign in to comment.