<commit_before>/*
 * autostart-test.js: Tests for autostarting drones.
 *
 * (C) 2010, Nodejitsu Inc.
 *
 */

var assert = require('assert'),
    path = require('path'),
    vows = require('vows'),
    data = require('../fixtures/apps'),
    helpers = require('../helpers'),
    haibu = require('../../lib/haibu');

var app = data.apps[0];
var home = data.apps[3];
var dataSystem = data.apps[4];

//
// Add a user property to the app
//
app.user = 'marak';

haibu.config.set('directories:pid', '/etc/cozy/pids');

var startBatch = {
  "When using haibu": {
    "a call to haibu.drone.start()": {
      topic: function () {
        haibu.drone.start({
          host: 'localhost',
          port: 9100
        }, this.callback);
      },
      "should namespace the server and drone": function (err, server) {
        assert.isNull(err);
        assert.isObject(haibu.running);
        assert.isObject(haibu.running.server);
        assert.isObject(haibu.running.drone);
      },
      "and a resulting server": {
        topic: function (server) {
          this.callback(null, server)
        },
        "should be running `test` app": function (err, server) {
          assert.isNotNull(server.drone.apps.test);
          assert.isNotNull(Object.keys(haibu.running.drone.apps).length, 1);
          //assert.equal(Object.keys(server.drone.apps.test.drones).length, 1);
        }
      },
      "Add application home": {
        topic: function (server) {
          server.drone.start(home, this.callback);
        },
        "should be successfull": function (err, drone) {
          assert.isNull(err);
        }
      }
    }
  }
}

// Some tests can't run in Travis. This is a dirty patch to not run them
// during the Travis build.
console.log(process.env.TEST_ENV);
if(process.env.TEST_ENV !== 'travis') {
  baseTest = startBatch["When using haibu"]["a call to haibu.drone.start()"];
  baseTest["Add application data-system"] = {
    topic: function (server) {
      server.drone.start(dataSystem, this.callback);
    },
    "should be successfull": function (err, drone) {
      assert.isNull(err);
    }
  }
};

vows.describe('haibu/drone/autostart').addBatch(helpers.requireInit()).addBatch({
  "When using haibu": {
    "a call to haibu.drone.start()": {
      topic: function () {
        haibu.drone.start({
          host: 'localhost',
          port: 9100
        }, this.callback);
      },
      "should namespace the server and drone": function (err, server) {
        assert.isNull(err);
        assert.isObject(haibu.running);
        assert.isObject(haibu.running.server);
        assert.isObject(haibu.running.drone);
      },
      "and running one drone": {<commit_msg>new attempt<commit_after>/*
 * autostart-test.js: Tests for autostarting drones.
 *
 * (C) 2010, Nodejitsu Inc.
 *
 */

var assert = require('assert'),
    path = require('path'),
    vows = require('vows'),
    data = require('../fixtures/apps'),
    helpers = require('../helpers'),
    haibu = require('../../lib/haibu');

var app = data.apps[0];
var home = data.apps[3];
var dataSystem = data.apps[4];

//
// Add a user property to the app
//
app.user = 'marak';

haibu.config.set('directories:pid', '/etc/cozy/pids');

var startBatch = {
  "When using haibu": {
    "a call to haibu.drone.start()": {
      topic: function () {
        haibu.drone.start({
          host: 'localhost',
          port: 9100
        }, this.callback);
      },
      "should namespace the server and drone": function (err, server) {
        assert.isNull(err);
        assert.isObject(haibu.running);
        assert.isObject(haibu.running.server);
        assert.isObject(haibu.running.drone);
      },
      "and a resulting server": {
        topic: function (server) {
          this.callback(null, server)
        },
        "should be running `test` app": function (err, server) {
          assert.isNotNull(server.drone.apps.test);
          assert.isNotNull(Object.keys(haibu.running.drone.apps).length, 1);
          //assert.equal(Object.keys(server.drone.apps.test.drones).length, 1);
        }
      },
      "Add application home": {
        topic: function (server) {
          server.drone.start(home, this.callback);
        },
        "should be successfull": function (err, drone) {
          assert.isNull(err);
        }
      }
    }
  }
}

// Some tests can't run in Travis. This is a dirty patch to not run them
// during the Travis build.
if(process.env.TEST_ENV !== 'travis') {
  baseTest = startBatch["When using haibu"]["a call to haibu.drone.start()"];
  baseTest["Add application data-system"] = {
    topic: function (server) {
      server.drone.start(dataSystem, this.callback);
      console.log(process.env.TEST_ENV);
    },
    "should be successfull": function (err, drone) {
      assert.isNull(err);
    }
  }
};

vows.describe('haibu/drone/autostart').addBatch(helpers.requireInit()).addBatch({
  "When using haibu": {
    "a call to haibu.drone.start()": {
      topic: function () {
        haibu.drone.start({
          host: 'localhost',
          port: 9100
        }, this.callback);
      },
      "should namespace the server and drone": function (err, server) {
        assert.isNull(err);
        assert.isObject(haibu.running);
        assert.isObject(haibu.running.server);
        assert.isObject(haibu.running.drone);
      },
      "and running one drone": {
{'fraction_non_alphanumeric': 0.15584415584415584, 'fraction_numerical': 0.006307977736549165, 'mean_word_length': 2.420685279187817, 'pattern_counts': {'":': 24, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2618673', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1748, 'n_words': 375}