datasources: querier: add user to query (#109917)

This commit is contained in:
Gábor Farkas
2025-09-03 09:29:26 +02:00
committed by GitHub
parent cb77e97996
commit 0bfec936b3
2 changed files with 19 additions and 2 deletions
+12 -1
View File
@@ -16,6 +16,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
dataapi "github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1"
"github.com/grafana/grafana/pkg/apimachinery/identity"
queryapi "github.com/grafana/grafana/pkg/apis/query/v0alpha1"
"github.com/grafana/grafana/pkg/expr"
"github.com/grafana/grafana/pkg/infra/log"
@@ -45,6 +46,14 @@ func loadTestdataFrames(t *testing.T, filename string) *backend.QueryDataRespons
return result
}
type mockUser struct {
identity.Requester
}
func (mu mockUser) GetOrgID() int64 {
return -1
}
func TestQueryAPI(t *testing.T) {
testCases := []struct {
name string
@@ -167,7 +176,9 @@ func TestQueryAPI(t *testing.T) {
legacyDatasourceLookup: &mockLegacyDataSourceLookup{},
}
req := httptest.NewRequest(http.MethodPost, "/some-path", bytes.NewReader([]byte(tc.queryJSON)))
reqCtx := identity.WithRequester(context.Background(), mockUser{})
req := httptest.NewRequestWithContext(reqCtx, http.MethodPost, "/some-path", bytes.NewReader([]byte(tc.queryJSON)))
req.Header.Set("Content-Type", "application/json")
// Set optional headers