Skip to content

Commit

Permalink
Add test for downloadDump module.
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Sep 2, 2015
1 parent 4cbbaf8 commit e5a2c10
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/test-connectToInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('connectToInstance module', function() {

server = https.createServer(options, responseToRequests).listen(8889);
cti(config, function(e) {
server.close();
config.should.not.equal(undefined);
done(e);
});
Expand Down
47 changes: 47 additions & 0 deletions test/test-downloadDump.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

var https = require('https');
var fs = require('fs');
var os = require('os');
var path = require('path');
var options = {
key: fs.readFileSync(path.join(__dirname, 'certs', 'key.key')),
cert: fs.readFileSync(path.join(__dirname, 'certs', 'cert.cert'))
};
var should = require('should');

var dd = require('../src/downloadDump');

var config = {
ip: 'localhost'
};
var server;

function responseToRequests(req, res) {
res.end(responseString);
}
var responseString = 'this is the tar file for ' + Math.random().toString(36).slice(2);

describe('downloadDump module', function() {
it('Should export the expected type', function() {
dd.should.be.instanceOf(Function);
});
it('Should fail when trying to write the wrong place', function(done) {
server = https.createServer(options, responseToRequests).listen(8889, function() {
config.downloadDir = '/root';
dd(config, function(err) {
err.should.not.equal(null);
done();
});
});
});
it('Should download the expected thing', function(done) {
config.downloadDir = os.tmpDir();

dd(config, function(err) {
server.close();
fs.readFileSync(path.join(config.downloadDir, 'dump.tar.gz'), 'utf8').should.equal(responseString);
done(err);
});
});
});

0 comments on commit e5a2c10

Please sign in to comment.