Created
March 3, 2023 11:50
-
-
Save soundstep/7abe7c08e61b7beb42fc36e80c3317a0 to your computer and use it in GitHub Desktop.
Goreplay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gor = require('goreplay_middleware'); | |
const fs = require('fs'); | |
// `init` will initialize STDIN listener | |
gor.init(); | |
// Example of very basic way to compare if replayed traffic have no errors | |
gor.on('request', function (req) { | |
gor.on('response', req.ID, function (resp) { | |
gor.on('replay', req.ID, function (repl) { | |
if (gor.httpStatus(resp.http) != gor.httpStatus(repl.http)) { | |
// Note that STDERR is used for logging, and it actually will be send to `Gor` STDOUT. | |
// This trick is used because SDTIN and STDOUT already used for process communication. | |
// You can write logger that writes to files insead. | |
fs.appendFileSync( | |
'./log.txt', | |
`${gor.httpPath( | |
req.http | |
)} STATUS NOT MATCH: 'Expected ${gor.httpStatus( | |
resp.http | |
)}' got '${gor.httpStatus(repl.http)}' \n` | |
); | |
console.error( | |
`${gor.httpPath( | |
req.http | |
)} STATUS NOT MATCH: 'Expected ${gor.httpStatus( | |
resp.http | |
)}' got '${gor.httpStatus(repl.http)}'` | |
); | |
} | |
return repl; | |
}); | |
return resp; | |
}); | |
return req; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment