Plugins: Use handler middleware from the SDK (#93445)
updates sdk to v0.251.0
This commit is contained in:
+8
-9
@@ -5,34 +5,33 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/handlertest"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/client/clienttest"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginrequestmeta"
|
||||
)
|
||||
|
||||
func TestPluginRequestMetaMiddleware(t *testing.T) {
|
||||
t.Run("default", func(t *testing.T) {
|
||||
cdt := clienttest.NewClientDecoratorTest(t,
|
||||
clienttest.WithMiddlewares(NewPluginRequestMetaMiddleware()),
|
||||
cdt := handlertest.NewHandlerMiddlewareTest(t,
|
||||
handlertest.WithMiddlewares(NewPluginRequestMetaMiddleware()),
|
||||
)
|
||||
_, err := cdt.Decorator.QueryData(context.Background(), &backend.QueryDataRequest{})
|
||||
_, err := cdt.MiddlewareHandler.QueryData(context.Background(), &backend.QueryDataRequest{})
|
||||
require.NoError(t, err)
|
||||
ss := pluginrequestmeta.StatusSourceFromContext(cdt.QueryDataCtx)
|
||||
require.Equal(t, pluginrequestmeta.StatusSourcePlugin, ss)
|
||||
})
|
||||
|
||||
t.Run("other value", func(t *testing.T) {
|
||||
cdt := clienttest.NewClientDecoratorTest(t,
|
||||
clienttest.WithMiddlewares(plugins.ClientMiddlewareFunc(func(next plugins.Client) plugins.Client {
|
||||
cdt := handlertest.NewHandlerMiddlewareTest(t,
|
||||
handlertest.WithMiddlewares(backend.HandlerMiddlewareFunc(func(next backend.Handler) backend.Handler {
|
||||
return &PluginRequestMetaMiddleware{
|
||||
next: next,
|
||||
BaseHandler: backend.NewBaseHandler(next),
|
||||
defaultStatusSource: "test",
|
||||
}
|
||||
})),
|
||||
)
|
||||
_, err := cdt.Decorator.QueryData(context.Background(), &backend.QueryDataRequest{})
|
||||
_, err := cdt.MiddlewareHandler.QueryData(context.Background(), &backend.QueryDataRequest{})
|
||||
require.NoError(t, err)
|
||||
ss := pluginrequestmeta.StatusSourceFromContext(cdt.QueryDataCtx)
|
||||
require.Equal(t, pluginrequestmeta.StatusSource("test"), ss)
|
||||
|
||||
Reference in New Issue
Block a user