TcpTransport.test.js
1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"use strict";
let expect = require('expect.js'),
rewire = require('rewire'),
http = require('../mock/http'),
os = require('os');
describe('/libs/TcpTransport', function() {
let TcpTransport = rewire("../../libs/TcpTransport");
TcpTransport.__set__('http', http);
describe('constructor', function() {
let trans = new TcpTransport({
level: 'error',
host: 'xxx',
port: '1234',
measurement: 'xxx'
});
it('expect trans to be tcpInfuxdbLogger', function() {
expect(trans.name).to.be('tcpInfuxdbLogger');
});
it('expect addline send buffer right value', function() {
trans.log('info', 'xxx', {}, function() {});
let line = 'xxx,host=' + os.hostname() + ',pid=' + process.pid + ',level=info message="xxx",meta="{}"';
expect(http.writeRet).to.be(line);
});
it('init database async,log add first,when database done,log add batch!', function(done) {
http.async = true;
let atrans = new TcpTransport({
level: 'error',
host: 'xxx',
measurement: 'xxx'
});
let i = 0;
atrans.log('info', 'xxx','123',function(){
i++;
});
atrans.log('info', 'xxx','123',function(){
i++;
});
if(i>1) {
expect(i).to.be(2);
}
setTimeout(done,50);
});
});
});