Skip to content

Instantly share code, notes, and snippets.

@soundstep
Created March 3, 2023 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soundstep/7abe7c08e61b7beb42fc36e80c3317a0 to your computer and use it in GitHub Desktop.
Save soundstep/7abe7c08e61b7beb42fc36e80c3317a0 to your computer and use it in GitHub Desktop.
Goreplay
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