Skip to content

Commit

Permalink
fix: pass grpc metadata to helpers. #189
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhendumadhukar committed Sep 2, 2022
1 parent 0cdcc8e commit 3ff8421
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/handlebar/RequestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export class RequestHelper {
return null;
}
}
case "metadata":
return context.data.root.metadata.get(context.hash.key);
default:
if (
typeof context.hash.using === "undefined" ||
Expand Down
8 changes: 4 additions & 4 deletions src/parser/GrpcParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export default class GrpcParser {
const mockFilePath = path.join(this.config.protocols.grpc.mocks_dir, mockFile + ".mock");
if (fs.existsSync(mockFilePath)) {
const template = Handlebars.compile(fs.readFileSync(mockFilePath, "utf-8").toString());
logger.debug(`Unary Request: ${JSON.stringify(call.request)}`)
const fileContent = await template({ request: call.request });
logger.debug(`Unary Request: ${JSON.stringify(call.request)}. Metadata: ${JSON.stringify(call.metadata)}`)
const fileContent = await template({ request: call.request, metadata: call.metadata });
logger.debug(`Mock file path: ${mockFilePath}`);
logger.debug(`Response: ${fileContent}`);
const response = JSON.parse(fileContent);
Expand Down Expand Up @@ -72,8 +72,8 @@ export default class GrpcParser {
if (fs.existsSync(mockFilePath)) {
try {
const template = Handlebars.compile(fs.readFileSync(mockFilePath, "utf-8").toString());
logger.debug(`Server Stream Request: ${JSON.stringify(call.request)}`)
const fileContent = await template({ request: call.request });
logger.debug(`Server Stream Request: ${JSON.stringify(call.request)}. Metadata ${JSON.stringify(call.metadata)}`)
const fileContent = await template({ request: call.request, metadata: call.metadata });
logger.debug(`Mock file path: ${mockFilePath}`);
const streamArr = fileContent.split("====");
let delay = 0;
Expand Down

0 comments on commit 3ff8421

Please sign in to comment.