var path = require('path'),
    fs = require('fs'),
    readdirRecursive = require('../../../../lib/file/readdir_recursive');

exports['Read a directory recursive'] = function (test) {
    var dirname = path.resolve(__dirname, '../');
    readdirRecursive(dirname, function (err, filenames) {
        test.ifError(err);
        test.done();
    });
};
exports['Handle err.'] = function (test) {
    var readdir = fs.readdir;
    fs.readdir = function (dirname, callback) {
        callback(new Error('readdir mock error'));
    };
    readdirRecursive('foo bar', function (err) {
        test.ok(err);
        fs.readdir = readdir;
        var lstat = fs.lstat;
        fs.lstat = function (filename, callback) {
            callback(new Error('stat mock error'));
        };
        readdirRecursive(__dirname, function (err) {
            fs.lstat = lstat;
            test.ok(err);
            test.done();
        });
    });
};