<commit_before><commit_msg>add test for elasticsearch channel recipe<commit_after>var path = require('path');
require('chai').should();
var uut = require('../lib/streamFromRecipe');

var recipes = [
  {
    input: {
      channel: 'elasticsearch',
      glob: {
        index: 'logstash-*',
        size: 0,
        body: {
          // Begin query.
          query: {
            // Boolean query for matching and excluding items.
            bool: {
              must: [{match: {'actionStatus': 'CompletedActionStatus'}}]
            }
          },
          // Aggregate on the results
          aggs: {
            actions: {
              terms: {
                field: 'additionalType',
                order: {'_term' : 'asc'},
                size: 10,
              }
            }
          }
        }
      }
    },
    output: {
      channel: 'gulp',
      glob: path.join(__dirname, 'fixtures', 'output')
    }
  }
];
var connections = {
  'elasticsearch': {
    host: process.env.ELASTICSEARCH_HOST,
    amazonES: {
      region: process.env.ELASTICSEARCH_AWS_DEFAULT_REGION,
      accessKey: process.env.ELASTICSEARCH_AWS_ACCESS_KEY_ID,
      secretKey: process.env.ELASTICSEARCH_AWS_SECRET_ACCESS_KEY
    }
  }
};

var channels = require('../lib/channels')(connections, recipes);

describe('elasticsearch channel', function() {
  it('should query', function(done) {
    this.timeout(10000);

    uut(recipes[0], connections, channels)
    .toArray(function(fileList) {
      fileList.forEach(function(file) {
        var data = JSON.parse(String(file.contents));

        data
        .should.have.deep.property('aggregations.actions.buckets')
        .that.is.an('array');
        data
        .should.have.deep.property('hits.hits')
        .that.is.an('array');
      });
      done();
    })
    ;
  });
});
{'fraction_non_alphanumeric': 0.14145275805570726, 'fraction_numerical': 0.004915346805024577, 'mean_word_length': 1.9453376205787782, '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': '3716010', 'n_tokens_mistral': 570, 'n_tokens_neox': 553, 'n_words': 97}