options for @grpc/proto-loader to load .proto file. In detail, please check here out. Default is null
rules
Array<Rule>
Required
Array of Rules
Rule
prop name
type
required/optional
description
method
String
Required
path to .proto file
streamType
Enum<"client"|"server"|"mutual">
Optional
Type of stream. Set client if only using client side stream, set server if only using server side stream, and set mutual if using both of client and server side stream. Set null/undefined if not using stream. Default is null
input
Object|String
Required when streamType is null or server
Specifying an expected input. Raw object or pattern string(RegExp) is available
output
String
Required when streamType is null or client
Specifying an output to an expected input
stream
Array<Chunk>
Required when streamType is client, server and mutual
Array of Chunks
error
Object
Optional
If provided, server will respond with this error object
Chunk
prop name
type
required/optional
description
input
Object|String
Required when streamType is client. Optional when streamType is mutual
Specifying an expected input. Raw object or pattern string(RegExp) is available.
output
Object
Required when streamType is server. Optional when streamType is mutual
I have been using this for some time and was able to work around every problem found, but there is something i can't seem to discover which is metadata matching.
In the above sample, i wan't to match 2 requests:
1- Metadata with Culture: 'pt-PT'
2- Empty Metadata
The problem with this is that grpc-mock will always return the first stream instead of throwing the error provided in the second array element. I saw that metadata is implemented for error output responses but not for input.
This is something important for Sad Path tests, i could try to submit a PR, but first i would like to know if this is already possible somehow.
If no rule was found, then callback not being called at all. And no exception was raised.
As result current test running process just get stuck (mocha, jest test runner, for example). And you have no idea what's going wrong. Cause your grpc client code expects a ccallback from GRPC at any case. But grpc-mock will not call it in that case.
As a developer, i have only one way out: set a breakpoint at grpc-mock's for loop and find wrong request, that was not able to find proper rule. It'a a headache.
Propose to change the behaviour: if no rules was matched current request, rais an exception.
Similar logic implemented at nock library: https://github.com/nock/nock#expectations
npm WARN deprecated [email protected]: This library will not receive further updates other than security fixes. We recommend using @grpc/grpc-js instead.
I am attempting to return an ENUM value as part of an output. I have tried both specifying the value as its string representation as well as its integer representation, but neither seems to be working. Should this work?
Hi,
The README.md could contains details on how to start this mock-grpc locally. I am new to node.js and all I want is this mock server to be up and running. How do I do that?
TIA
I tried:
{
input: {
param: "^[a-zA-Z]+"
}
}
and I set param to "uuid" in the request , but it doesn't work and throws "io.grpc.StatusRuntimeException: INVALID_ARGUMENT: unexpected input pattern"
Hi,
I have a proto file which uses google.protobuf.FieldOptions and it fails compailing that protobufjs cannot resolve this.
Pasted the error below: /node_modules/protobufjs/src/root.js:243 throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
Any idea how to make protobufjs support this?
Thanks
Sometimes you just care about a part of the input of the request. For example,
Input object: user: String, friends: List<User>, random: Number
pseudo-rules:
if user: "john" then return blah
if user: "laura"then return an error
In these cases I don't care about the friends and I can't predict the random number. I know that with strings you can use .* but it doesn't work with other types.
Would it be possible for the server to match like this?
{
input: {
stream: Boolean;//stream or not
body: Object|string;//raw object or pattern string},
output: {
stream: Boolean;//stream or not
body: Object}}
Sometimes in the same tests suite you have different tests that need different set of rules, and today the only way to change the rules is starting a new server with those new rules. An example would be expecting the same request to return successfully on one test, and fail on another (the input can't be changed).
Would it be possible to update those rules on the fly so we can make the tests use only 1 server? also making them faster?
seems to make the server crash as well as return unexpected input pattern
/usr/local/lib/node_modules/grpc-mock/node_modules/grpc/src/server.js:69
call.startBatch(error_batch, function(){});
^
Error: startBatch failed
at handleError (/usr/local/lib/node_modules/grpc-mock/node_modules/grpc/src/server.js:69:8)
at sendUnaryData (/usr/local/lib/node_modules/grpc-mock/node_modules/grpc/src/server.js:595:9)
at HandlerFactory.<anonymous> (/usr/local/lib/node_modules/grpc-mock/index.js:143:15)
at Object.DeleteDevice (/usr/local/lib/node_modules/grpc-mock/node_modules/grpc-kit/index.js:53:28)
at /usr/local/lib/node_modules/grpc-mock/node_modules/grpc/src/server.js:590:13