Home Reference Source Test

test/InfluxWriter.js

const {InfluxWriter} = require('../src');
const {describe, it} = require('mocha');
const {expect} = require('chai');

const INFLUX_HOST = process.env.INFLUX_HOST || 'localhost';
describe('InfluxWriter', function () {

    it('writes requests to influx', function () {
        let writer = new InfluxWriter({
            host: INFLUX_HOST,
            batchSize: 1,
            tags: {
                service: 'test'
            }
        });
        writer._influx = {
            writePoints(batch) {
                expect(batch.length).to.equal(1);
                batch.forEach(point => {
                    expect(point.timestamp).to.not.be.null;
                    expect(point.tags).to.deep.equal({service: 'test', a: 'b'});
                    expect(point.fields).to.deep.equal({time: 5});
                });
                return Promise.resolve();
            }
        };

        writer.writePoint('test', {a: 'b'}, {time: 5});
    });
});