<commit_before>/* jshint mocha: true */
'use strict';

const assert = require('assert');
const redis = require('../lib/redis');

let nodes;

beforeEach(function(done) {
  redis.flushdb(done);
  nodes = JSON.parse(JSON.stringify(require('./assets/computers')));
});

describe('redis', function() {
  describe('module.exports', function() {
    it('returns a connection', function() {
      assert.equal(typeof redis.server_info, 'object');
    });
  });

  describe('jenkinsChanged()', function() {
    it('returns offline nodes', function(done) {
      redis.jenkinsChanged(nodes.computer, function(err, n) {
        assert.ifError(err);
        assert.equal(n.length, 3);
        assert.equal(n[0].displayName, 'iojs-linaro-armv8-ubuntu1404');
        assert.equal(n[1].displayName, 'iojs-nodesource-raspbian-wheezy-pi1p-3');
        assert.equal(n[2].displayName, 'iojs-voxer-osx1010-release-pkg-2');
        done();
      });
    });

    it('returns empty array for no changed nodes', function(done) {
      redis.jenkinsChanged(nodes.computer, function(err, n) {
        assert.ifError(err);
        nodes = JSON.parse(JSON.stringify(require('./assets/computers')));
        redis.jenkinsChanged(nodes.computer, function(err, n) {
          assert.ifError(err);
          assert.deepEqual(n, []);
          done();
        });
      });
    });

    it('returns only changed nodes', function(done) {
      redis.jenkinsChanged(nodes.computer, function(err, n) {
        assert.ifError(err);

        nodes = JSON.parse(JSON.stringify(require('./assets/computers')));
        nodes.computer[5].temporarilyOffline = true;
        nodes.computer[6].temporarilyOffline = true;

        redis.jenkinsChanged(nodes.computer, function(err, n) {
          assert.ifError(err);
          assert.equal(n.length, 2);
          assert.equal(n[0].displayName, 'iojs-digitalocean-centos5-release-32-1');
          assert.equal(n[1].displayName, 'iojs-digitalocean-centos5-release-64-1');
          done();
        });<commit_msg>Use lib/jenkins formatted nodes when testing redis<commit_after>/* jshint mocha: true */
'use strict';

const assert = require('assert');
const redis = require('../lib/redis');

const jsonist = require('jsonist');
const jenkins = require('../lib/jenkins');

let nodes;

before(function() {
  jsonist.get = function(url, cb) {
    return cb(null, JSON.parse(JSON.stringify(require('./assets/computers.json'))));
  }
});

beforeEach(function(done) {
  redis.flushdb(done);
});

beforeEach(function(done) {
  jenkins.getComputers(function(err, computers) {
    nodes = computers;
    done(err);
  });
});

describe('redis', function() {
  describe('module.exports', function() {
    it('returns a connection', function() {
      assert.equal(typeof redis.server_info, 'object');
    });
  });

  describe('jenkinsChanged()', function() {
    it('returns offline nodes', function(done) {
      redis.jenkinsChanged(nodes, function(err, n) {
        assert.ifError(err);
        assert.equal(n.length, 3);
        assert.equal(n[0].name, 'iojs-linaro-armv8-ubuntu1404');
        assert.equal(n[1].name, 'iojs-nodesource-raspbian-wheezy-pi1p-3');
        assert.equal(n[2].name, 'iojs-voxer-osx1010-release-pkg-2');
        done();
      });
    });

    it('returns empty array for no changed nodes', function(done) {
      redis.jenkinsChanged(nodes, function(err, n) {
        assert.ifError(err);
        nodes = JSON.parse(JSON.stringify(require('./assets/computers')));
        redis.jenkinsChanged(nodes, function(err, n) {
          assert.ifError(err);
          assert.deepEqual(n, []);
          done();
        });
      });
    });

    it('returns only changed nodes', function(done) {
      redis.jenkinsChanged(nodes, function(err, n) {
        assert.ifError(err);

        nodes[5].offline = 1;
        nodes[6].offline = 1;

        redis.jenkinsChanged(nodes, function(err, n) {
          assert.ifError(err);
          assert.equal(n.length, 2);
          assert.equal(n[0].name, 'iojs-digitalocean-centos5-release-32-1');
          assert.equal(n[1].name, 'iojs-digitalocean-centos5-release-64-1');
          done();
        });
{'fraction_non_alphanumeric': 0.17170989433237271, 'fraction_numerical': 0.01440922190201729, 'mean_word_length': 3.024154589371981, 'pattern_counts': {'":': 0, '<': 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': '6291837', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1344, 'n_words': 209}