datasources: querier: add user to query (#109917)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user