File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const test = require ( 'ava' )
4
+ const sget = require ( 'simple-get' )
5
+ const validator = require ( 'is-my-json-valid' )
6
+ const express = require ( 'express' )
7
+ const morgan = require ( 'morgan' )
8
+ const stoppable = require ( 'stoppable' )
9
+ const split = require ( 'split2' )
10
+ const ecsFormat = require ( './' )
11
+
12
+ const validate = validator ( require ( '../../utils/schema.json' ) )
13
+
14
+ test . cb ( 'Should produce valid ecs logs' , t => {
15
+ t . plan ( 2 )
16
+
17
+ const stream = split ( JSON . parse ) . on ( 'data' , line => {
18
+ t . true ( validate ( line ) )
19
+ } )
20
+
21
+ const app = express ( )
22
+ app . use ( morgan ( ecsFormat ( ) , { stream } ) )
23
+ app . use ( '/' , ( req , res ) => {
24
+ res . end ( 'ok' )
25
+ } )
26
+
27
+ const server = stoppable ( app . listen ( 0 , ( ) => {
28
+ const body = JSON . stringify ( { hello : 'world' } )
29
+ sget ( {
30
+ method : 'POST' ,
31
+ url : `http://localhost:${ server . address ( ) . port } ?foo=bar` ,
32
+ body,
33
+ headers : {
34
+ 'user-agent' : 'cool-agent' ,
35
+ 'content-type' : 'application/json' ,
36
+ 'content-length' : Buffer . byteLength ( body )
37
+ }
38
+ } , ( err , res ) => {
39
+ t . falsy ( err )
40
+ server . stop ( )
41
+ t . end ( )
42
+ } )
43
+ } ) )
44
+ } )
You can’t perform that action at this time.
0 commit comments