Replies: 1 comment 1 reply
-
@bhollis, you can provide your own implementation of type testRequest[T any] struct {
*connect.Request[T]
method string
}
func (r testRequest[_]) Spec() connect.Spec {
return connect.Spec{
Procedure: r.method,
}
}
func newRequest[T any](msg *T, method string) connect.AnyRequest {
return testRequest[T]{Request: connect.NewRequest(msg), method: method}
} Note that such a test request will cause problems if passed to the actual Connect framework, so if your interceptor implementation actually needs to override any of these request properties (and pass the modified request to the next interceptor or handler in the chain), that is not currently possible. But if you are just testing your interceptor in isolation, this technique should be fine. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there, we're switching from the Google gRPC libraries to Connect, and so far it's going well. However, we've hit a bit of a snag while trying to migrate over all of our custom interceptors. As far as I can tell, there's no way for us to construct a
request.AnyRequest
ourselves with a populatedspec
field, which makes it difficult for us to test an interceptor in isolation. Our interceptor is only readingreq.Spec().Procedure
and with the Google libraries, it was easy for us to construct agrpc.UnaryServerInfo
struct to pass in with all kinds of different method names. With Connect, we can't quite figure out any way to do this. As the docs onAnyRequest
say:As an example, our original tests looked something like this, where
authz.NewInterceptor
returned agrpc.UnaryServerInterceptor
:Beta Was this translation helpful? Give feedback.
All reactions