-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CEL rules for stubs #9
Comments
This would be a very welcome feature! I'm coming from trying out gripmock which does have CEL rules but I would much rather work with fauxrpc's approach to using proto descriptors and its compatibility with the buf ecosystem and test containers. On the note of adding stubs: I would like to use this framework for service/integration testing in the backend. Usually I expect to make a call to my tested service and it will in turn call out one or more stubbed gRPC dependencies. CEL rules would be very useful here to:
In the current state of fauxrpc, if say I was using test containers and added a stub, would it just return that one? Would it return later randomised ones? Having CEL control over this and nice examples would be extremely useful. |
Yeah, if you added a stub it will just return that one. If you add multiple for the same type it will randomly pick amongst them.
I've worked on this a bit yesterday and today: https://github.com/sudorandom/fauxrpc/tree/cel-rules There's still more work to do, but there's several improvements already:
ds, err := protocel.NewDynamicMessage(md, map[string]protocel.Node{
"double_value": protocel.CEL(`1000.0+10.12`),
"float_value": protocel.CEL(`2000.0+10.12`),
"int32_value": protocel.CEL(`1+2`),
"int64_value": protocel.CEL(`2+2`),
"uint32_value": protocel.CEL(`uint(1+2)`),
"uint64_value": protocel.CEL(`uint(2+2)`),
"sint32_value": protocel.CEL(`1+2`),
"sint64_value": protocel.CEL(`2+2`),
"fixed32_value": protocel.CEL(`uint(1+2)`),
"fixed64_value": protocel.CEL(`uint(2+2)`),
"sfixed32_value": protocel.CEL(`1+2`),
"sfixed64_value": protocel.CEL(`2+2`),
"bool_value": protocel.CEL(`true`),
"string_value": protocel.CEL(`"hello"`),
"bytes_value": protocel.CEL(`b"ÿ"`),
}) This works for scalar fields, message fields, and repeated fields. There are also ds, err := protocel.NewDynamicMessage(md, map[string]protocel.Node{
"double_value": protocel.CEL(`gen_float64()`),
"float_value": protocel.CEL(`gen_float32()`),
"int32_value": protocel.CEL(`gen_int32()`),
"int64_value": protocel.CEL(`gen_int64()`),
"uint32_value": protocel.CEL(`gen_uint32()`),
"uint64_value": protocel.CEL(`gen_uint64()`),
"sint32_value": protocel.CEL(`gen_sint32()`),
"sint64_value": protocel.CEL(`gen_sint64()`),
"fixed32_value": protocel.CEL(`gen_fixed32()`),
"fixed64_value": protocel.CEL(`gen_fixed64()`),
"sfixed32_value": protocel.CEL(`gen_sfixed32()`),
"sfixed64_value": protocel.CEL(`gen_sfixed64()`),
"bool_value": protocel.CEL(`gen_bool()`),
"string_value": protocel.CEL(`gen_string()`),
"bytes_value": protocel.CEL(`gen_bytes()`), What's left to do:
|
It would be neat if you could specify CEL rules that would decide if a stub is used. Like if you're stubbing a GET call, you could have a stub that looks like this:
Then when you call
my.v1.app.UserService/getUser
looking for the user with id1234
you would receive the given mocked response. This would allow fairly complex testing scenarios.Also, for debugging purposes the selected stub ID should be returned as a return header value.
The text was updated successfully, but these errors were encountered: