var fs = require('fs'),
    testResource = require('../../../test_resource'),
    appendFile = require('../../../../lib/file/append_file');

exports['Append a file.'] = function (test) {
    var workDir = testResource.resolveWorkFile('work_append_file');
    testResource.prepareCleanWorkDir(workDir, function () {
        var src = testResource.resolveWorkFile(workDir, 'work-foo-src.txt'),
            dest = testResource.resolveWorkFile(workDir, 'work-bar-dest.txt');

        fs.writeFile(src, 'baz-baz\n', function () {
            appendFile(src, dest, function (err) {
                test.ifError(err);
                appendFile(src, dest, function (err) {
                    fs.readFile(dest, function (err, buffer) {
                        test.equal(buffer.toString(), 'baz-baz\nbaz-baz\n');
                        test.done();
                    });
                });
            });
        });

    });
};