Caching: Consolidate resource cache checking and updating in plugin middleware (#67002)

* Update the HandleResourceRequest function to mimic the HandleQueryRequest function

* Remove CacheResourceResponse function from interface

* revert additional thing I missed
This commit is contained in:
Michael Mandrus
2023-04-21 13:03:49 -04:00
committed by GitHub
parent d02aee2479
commit a29cfe5d46
9 changed files with 92 additions and 64 deletions
@@ -179,6 +179,9 @@ type ClientDecoratorTest struct {
SubscribeStreamCtx context.Context
PublishStreamReq *backend.PublishStreamRequest
PublishStreamCtx context.Context
// When CallResource is called, the sender will be called with these values
callResourceResponses []*backend.CallResourceResponse
}
type ClientDecoratorTestOption func(*ClientDecoratorTest)
@@ -197,6 +200,13 @@ func NewClientDecoratorTest(t *testing.T, opts ...ClientDecoratorTestOption) *Cl
CallResourceFunc: func(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
cdt.CallResourceReq = req
cdt.CallResourceCtx = ctx
if cdt.callResourceResponses != nil {
for _, r := range cdt.callResourceResponses {
if err := sender.Send(r); err != nil {
return err
}
}
}
return nil
},
CheckHealthFunc: func(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
@@ -262,3 +272,10 @@ func WithMiddlewares(middlewares ...plugins.ClientMiddleware) ClientDecoratorTes
cdt.Middlewares = append(cdt.Middlewares, middlewares...)
})
}
// WithResourceResponses can be used to make the test client send simulated resource responses back over the sender stream
func WithResourceResponses(responses []*backend.CallResourceResponse) ClientDecoratorTestOption {
return ClientDecoratorTestOption(func(cdt *ClientDecoratorTest) {
cdt.callResourceResponses = responses
})
}