/** @overview nodeunit test case. */

var testResource = require('../../../test_resource'),
    fs = require('fs'),
    mockInjector = require('../../../mock_injector'),
    _writeFileUnlessExists = require('../../../../task/worker/_write_file_unless_exists.js');

exports.setUp = function (done) {
    done();
};

exports.tearDown = function (done) {
    mockInjector.restoreAll();
    done();
};


exports['Write file unless exists.'] = function (test) {
    var dest = testResource.resolveWorkFile('work_file_to_write_unless_exists');
    if (fs.existsSync(dest)) fs.unlinkSync(dest);
    _writeFileUnlessExists(dest, 'foo', function (err) {
        test.ifError(err);
        _writeFileUnlessExists(dest, 'bar', function (err) {
            test.ifError(err);
            fs.readFile(dest, function (err, content) {
                test.equal(content.toString(), 'foo');
                test.done();
            });
        });
    });
};