var fs = require('fs'),
    testResource = require('../../../test_resource'),
    copyDir = require('../../../../lib/file/copy_dir');

exports['Copy a directory'] = function (test) {
    var dest = testResource.resolveWorkFile('work_copy_dir');
    copyDir(
        testResource.resolveMockFile('.'),
        dest,
        function (err) {
            test.ifError(err);
            fs.exists(dest, function (exists) {
                test.ok(exists);
                test.done();
            });
        }
    )
};
exports['Handle err.'] = function (test) {
    var _readdirRecursive = copyDir._readdirRecursive;
    copyDir._readdirRecursive = function (dirname, callback) {
        callback(new Error('mock error'));
    };
    copyDir('foo', 'bar', function (err) {
        test.ok(err);
        copyDir._readdirRecursive = _readdirRecursive;

        var mkdirP = copyDir.mkdirP;
        copyDir.mkdirP = function (dirname, callback) {
            callback(new Error('mock error'));
        };
        copyDir(testResource.resolveMockFile('.'), 'bar', function (err) {
            test.ok(err);
            copyDir.mkdirP = mkdirP;
            test.done();
        });
    });
};