<commit_before>
const assert   = require('assert')
const path     = require('path')

const fixtures = require('haraka-test-fixtures');

function set_up (done) {
    try {
        this.plugin = new fixtures.plugin('../index');
    }
    catch (e) {
        console.error(`unable to load elasticsearch plugin: ${e}`);
        return done('failed to load elasticsearch');
    }

    this.connection = fixtures.connection.createConnection();
    this.plugin.config.root_path = path.resolve(__dirname, '..', '..', 'config');

    done();
}

describe('load_es_ini', function () {
    beforeEach(set_up)

    it('can load elasticsearch.ini', function (done) {
        this.plugin.load_es_ini();
        // console.log(this.plugin.cfg);
        assert.deepEqual(this.plugin.cfg.hosts, { '127.0.0.1': undefined });
        assert.ok(this.plugin.cfg);
        assert.ok(this.plugin.cfg.index);
        done();
    })
})

describe('get_es_hosts', function () {
    beforeEach(set_up)

    it('converts bare host to hosts format', function (done) {
        this.plugin.cfg = { hosts: { 'localhost': undefined } };
        this.plugin.get_es_hosts();
        assert.deepEqual(["http://localhost:9200"], this.plugin.cfg.es_hosts);
        done();
    })

    it('converts host:$options to hosts format', function (done) {
        this.plugin.cfg = { hosts: {
            'localhost': 'port:9200,protocol:https',
            '172.16.15.27': 'protocol:https'
        }};
        const expected = [
            { host: 'localhost', port: '9200', protocol: 'https' },
            { host: '172.16.15.27', protocol: 'https' }
        ];
        this.plugin.get_es_hosts();
        assert.deepEqual(expected, this.plugin.cfg.es_hosts);
        done();
    })
})<commit_msg>strip old host processing options, incompatible with new es client<commit_after>
const assert   = require('assert')
const path     = require('path')

const fixtures = require('haraka-test-fixtures');

function set_up (done) {
    try {
        this.plugin = new fixtures.plugin('../index');
    }
    catch (e) {
        console.error(`unable to load elasticsearch plugin: ${e}`);
        return done('failed to load elasticsearch');
    }

    this.connection = fixtures.connection.createConnection();
    this.plugin.config.root_path = path.resolve(__dirname, '..', '..', 'config');

    done();
}

describe('load_es_ini', function () {
    beforeEach(set_up)

    it('can load elasticsearch.ini', function (done) {
        this.plugin.load_es_ini();
        // console.log(this.plugin.cfg);
        assert.deepEqual(this.plugin.cfg.hosts, { '127.0.0.1': undefined });
        assert.ok(this.plugin.cfg);
        assert.ok(this.plugin.cfg.index);
        done();
    })
})

describe('get_es_hosts', function () {
    beforeEach(set_up)

    it('converts bare host to hosts format', function (done) {
        this.plugin.cfg = { hosts: { 'localhost': undefined } };
        this.plugin.get_es_hosts();
        assert.deepEqual(["http://localhost:9200"], this.plugin.cfg.es_hosts);
        done();
    })
})
{'fraction_non_alphanumeric': 0.16508662961752207, 'fraction_numerical': 0.015037593984962405, 'mean_word_length': 2.709090909090909, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '5236821', 'n_tokens_mistral': 986, 'n_tokens_neox': 934, 'n_words': 180}