Skip to content

Commit

Permalink
closeFd tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Feb 4, 2016
1 parent 3804e5b commit 8591013
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/fileOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

var expect = require('expect');

var fs = require('graceful-fs');
var path = require('path');

var closeFd = require('../lib/dest/fileOperations/closeFd');
var isOwner = require('../lib/dest/fileOperations/isOwner');
var getModeDiff = require('../lib/dest/fileOperations/getModeDiff');
var getTimesDiff = require('../lib/dest/fileOperations/getTimesDiff');
Expand Down Expand Up @@ -279,3 +283,67 @@ describe('getTimesDiff', function() {
done();
});
});

describe('closeFd', function() {

it('calls the callback with propagated error if fd is not a number', function(done) {
var propagatedError = new Error();

closeFd(propagatedError, null, function(err) {
expect(err).toEqual(propagatedError);

done();
});
});

it('calls the callback with close error if no error to propagate', function(done) {
closeFd(null, 9001, function(err) {
expect(err).toExist();
expect(err.message).toEqual('EBADF, close');

done();
});
});

it('calls the callback with propagated error if close errors', function(done) {
var propagatedError = new Error();

closeFd(propagatedError, 9001, function(err) {
expect(err).toEqual(propagatedError);

done();
});
});

it('calls the callback with propagated error if close succeeds', function(done) {
var propagatedError = new Error();

var fd = fs.openSync(path.join(__dirname, './fixtures/test.coffee'), 'r');

var spy = expect.spyOn(fs, 'close').andCallThrough();

closeFd(propagatedError, fd, function(err) {
spy.restore();

expect(spy.calls.length).toEqual(1);
expect(err).toEqual(propagatedError);

done();
});
});

it('calls the callback with no error if close succeeds & no propagated error', function(done) {
var fd = fs.openSync(path.join(__dirname, './fixtures/test.coffee'), 'r');

var spy = expect.spyOn(fs, 'close').andCallThrough();

closeFd(null, fd, function(err) {
spy.restore();

expect(spy.calls.length).toEqual(1);
expect(err).toEqual(undefined);

done();
});
});
});

0 comments on commit 8591013

Please sign in to comment.