11// A mock APM server to use in tests.
22//
33// Usage:
4- // const server = new MockAPMServer()
4+ // const server = new MockAPMServer(opts )
55// server.start(function (serverUrl) {
66// // Test code using `serverUrl`...
77// // - Events received on the intake API will be on `server.events`.
@@ -16,9 +16,14 @@ const { URL } = require('url')
1616const zlib = require ( 'zlib' )
1717
1818class MockAPMServer {
19- constructor ( ) {
19+ // - @param {Object} opts
20+ // - {String} opts.apmServerVersion - The version to report in the
21+ // "GET /" response body. Defaults to "8.0.0".
22+ constructor ( opts ) {
23+ opts = opts || { }
2024 this . clear ( )
2125 this . serverUrl = null // set in .start()
26+ this . apmServerVersion = opts . apmServerVersion || '8.0.0'
2227 this . _http = http . createServer ( this . _onRequest . bind ( this ) )
2328 }
2429
@@ -43,7 +48,15 @@ class MockAPMServer {
4348
4449 instream . on ( 'end' , ( ) => {
4550 let resBody = ''
46- if ( parsedUrl . pathname === '/config/v1/agents' ) {
51+ if ( req . method === 'GET' && parsedUrl . pathname === '/' ) {
52+ // https://www.elastic.co/guide/en/apm/server/current/server-info.html#server-info-endpoint
53+ res . writeHead ( 200 )
54+ resBody = JSON . stringify ( {
55+ build_date : '2021-09-16T02:05:39Z' ,
56+ build_sha : 'a183f675ecd03fca4a897cbe85fda3511bc3ca43' ,
57+ version : this . apmServerVersion
58+ } )
59+ } else if ( parsedUrl . pathname === '/config/v1/agents' ) {
4760 // Central config mocking.
4861 res . writeHead ( 200 )
4962 resBody = '{}'
0 commit comments