'use strict';

var assert = require('assert'),
    os = require('os'),
    utils = require('../src/utils');


describe('utils', function () {

    process.env.silent = true;

    describe('encodeBase64', function () {

        it('BASE64 for not empty JSON object', function () {
            assert.equal(
                'eyJmb3JjZSI6dHJ1ZX0=',
                utils.encodeBase64({
                    'force': true
                })
            );
        });

        it('BASE64 for empty JSON object', function () {
            assert.equal(
                'e30=',
                utils.encodeBase64({})
            );
        });

        it('BASE64 for null-object', function () {
            assert.equal(
                'bnVsbA==',
                utils.encodeBase64(null)
            );
        });

        it('BASE64 for non-JSON object', function () {
            assert.equal(
                'IlN0cmluZyI=',
                utils.encodeBase64('String')
            );
        });

    });

    describe('filePath', function () {

        it('not null', function () {
            var file = utils.filePath('.');
            assert.notEqual(null, file);
            assert.notEqual('', file);
        });

    });

    describe('runFsWatchdog', function () {

        it('should not start fs watch dog', function () {
            assert.equal(null, utils.runFsWatchdog(null, 0, null));
            assert.equal(null, utils.runFsWatchdog(null, 60, null));
            assert.equal(null, utils.runFsWatchdog('/tmp', 0, null));
        });

        it('should start fs watch dog correctly', function () {
            var watchdog = utils.runFsWatchdog(os.tmpdir(), 1, function () {});
            assert.notEqual(null, watchdog);
            clearInterval(watchdog);
        });

    });


    describe('execProcess', function () {

        it('should not execute empty command', function (done) {
            assert.throws(function () {
                utils.execProcess(null, null);
            });
            assert.throws(function () {
                utils.execProcess(null, []);
            });
            assert.throws(function () {
                utils.execProcess('', null);
            });
            assert.throws(function () {
                utils.execProcess('', []);
            });
            done();
        });

        it('execute "ls"', function (done) {
            utils.execProcess('ls', null, function (code) {
                assert.equal(0, code);
            });
            utils.execProcess('ls', [], function (code) {
                assert.equal(0, code);
            });
            done();
        });

        it('execute "ls -la"', function (done) {
            utils.execProcess('ls', ['-la'], function (code) {
                assert.equal(0, code);
            });
            done();
        });

        it('execute "ls -l -a"', function (done) {
            utils.execProcess('ls', ['-l', '-a'], function (code) {
                assert.equal(0, code);
            });
            done();
        });

    });

});

@@ -2484,36 +2484,24 @@
  code);%0A    
-        %7D);%0A
             
@@ -2554,32 +2554,36 @@
                 
+    
 assert.equal(0, 
@@ -2581,32 +2581,64 @@
 equal(0, code);%0A
+                    done();%0A    
             %7D);%0A
@@ -2641,37 +2641,33 @@
 %7D);%0A            
-done(
+%7D
 );%0A        %7D);%0A%0A
@@ -2692,17 +2692,16 @@
 e %22ls -l
-a
 %22', func
@@ -2754,17 +2754,16 @@
 s', %5B'-l
-a
 '%5D, func
@@ -2819,33 +2819,41 @@
 e);%0A            
-%7D
+    done(
 );%0A            d
@@ -2843,37 +2843,33 @@
 ();%0A            
-done(
+%7D
 );%0A        %7D);%0A%0A
@@ -3030,33 +3030,41 @@
 e);%0A            
-%7D
+    done(
 );%0A            d
@@ -3054,37 +3054,33 @@
 ();%0A            
-done(
+%7D
 );%0A        %7D);%0A%0A

Fix unit-tests for utils: use done() correctly