mirror of
https://github.com/grafana/grafana.git
synced 2024-11-21 16:38:03 -06:00
Chore: Add linter rule to avoid imports from Grafana core in test datasource (#71779)
This commit is contained in:
parent
5faf5e48ea
commit
5b2721b4f1
@ -23,6 +23,15 @@ deny = [
|
||||
{pkg = "github.com/gofrs/uuid", desc = "Use github.com/google/uuid instead, which we already depend on."},
|
||||
]
|
||||
|
||||
[linters-settings.depguard.rules.coreplugins]
|
||||
deny = [
|
||||
{pkg = "github.com/grafana/grafana/pkg/", desc = "Core plugins are not allowed to depend on Grafana core packages"},
|
||||
]
|
||||
files = [
|
||||
"**/pkg/tsdb/testdatasource/*",
|
||||
"**/pkg/tsdb/testdatasource/**/*",
|
||||
]
|
||||
|
||||
[linters-settings.gocritic]
|
||||
enabled-checks = ["ruleguard"]
|
||||
[linters-settings.gocritic.settings.ruleguard]
|
||||
|
@ -15,31 +15,30 @@ import (
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
)
|
||||
|
||||
func (s *Service) handleCsvContentScenario(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := simplejson.NewJson(q.JSON)
|
||||
model, err := getModel(q.JSON)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse query json: %v", err)
|
||||
}
|
||||
|
||||
csvContent := model.Get("csvContent").MustString()
|
||||
csvContent := model.CSVContent
|
||||
if len(csvContent) == 0 {
|
||||
return backend.NewQueryDataResponse(), nil
|
||||
}
|
||||
|
||||
alias := model.Get("alias").MustString("")
|
||||
alias := model.Alias
|
||||
|
||||
frame, err := LoadCsvContent(strings.NewReader(csvContent), alias)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dropPercent := model.Get("dropPercent").MustFloat64(0)
|
||||
dropPercent := model.DropPercent
|
||||
if dropPercent > 0 {
|
||||
frame, err = dropValues(frame, dropPercent)
|
||||
if err != nil {
|
||||
@ -59,12 +58,12 @@ func (s *Service) handleCsvFileScenario(ctx context.Context, req *backend.QueryD
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, q := range req.Queries {
|
||||
model, err := simplejson.NewJson(q.JSON)
|
||||
model, err := getModel(q.JSON)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse query json %v", err)
|
||||
}
|
||||
|
||||
fileName := model.Get("csvFileName").MustString()
|
||||
fileName := model.CSVFileName
|
||||
|
||||
if len(fileName) == 0 {
|
||||
continue
|
||||
@ -76,7 +75,7 @@ func (s *Service) handleCsvFileScenario(ctx context.Context, req *backend.QueryD
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dropPercent := model.Get("dropPercent").MustFloat64(0)
|
||||
dropPercent := model.DropPercent
|
||||
if dropPercent > 0 {
|
||||
frame, err = dropValues(frame, dropPercent)
|
||||
if err != nil {
|
||||
|
@ -8,15 +8,10 @@ import (
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/experimental"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCSVFileScenario(t *testing.T) {
|
||||
cfg := setting.NewCfg()
|
||||
cfg.DataPath = t.TempDir()
|
||||
cfg.StaticRootPath = "../../../public"
|
||||
|
||||
s := &Service{}
|
||||
|
||||
t.Run("loadCsvFile", func(t *testing.T) {
|
||||
|
@ -250,6 +250,9 @@ type JSONModel struct {
|
||||
// Cannot specify a type for csvWave since legacy queries
|
||||
// does not follow the same format as the new ones (and there is no migration).
|
||||
CSVWave interface{} `json:"csvWave"`
|
||||
CSVContent string `json:"csvContent"`
|
||||
CSVFileName string `json:"csvFileName"`
|
||||
DropPercent float64 `json:"dropPercent"`
|
||||
}
|
||||
|
||||
type pulseWave struct {
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
// nolint:depguard // Lint exception can be removed once we move testdata to a separate module
|
||||
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
||||
)
|
||||
|
||||
|
@ -9,6 +9,8 @@ import (
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/resource/httpadapter"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
|
||||
// nolint:depguard // Lint exception can be removed once we move testdata to a separate module
|
||||
"github.com/grafana/grafana/pkg/tsdb/testdatasource/sims"
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user