Chore: Remove lint exceptions from testdata backend (#75148)

pull/75214/head
Andres Martinez Gotor 2 years ago committed by GitHub
parent f229758af0
commit dd8f88b194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 43
      .golangci.toml
  2. 24
      pkg/tsdb/testdatasource/scenarios_test.go
  3. 2
      pkg/tsdb/testdatasource/testdata.go

@ -16,21 +16,44 @@ confidence = 3
[linters-settings.depguard.rules.main] [linters-settings.depguard.rules.main]
allow = [] # allow all allow = [] # allow all
deny = [ deny = [
{pkg = "io/ioutil", desc = "Deprecated: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details."}, { pkg = "io/ioutil", desc = "Deprecated: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details." },
{pkg = "gopkg.in/yaml.v2", desc = "Grafana packages are not allowed to depend on gopkg.in/yaml.v2 as gopkg.in/yaml.v3 is now available"}, { pkg = "gopkg.in/yaml.v2", desc = "Grafana packages are not allowed to depend on gopkg.in/yaml.v2 as gopkg.in/yaml.v3 is now available" },
{pkg = "github.com/pkg/errors", desc = "Deprecated: Go 1.13 supports the functionality provided by pkg/errors in the standard library."}, { pkg = "github.com/pkg/errors", desc = "Deprecated: Go 1.13 supports the functionality provided by pkg/errors in the standard library." },
{pkg = "github.com/xorcare/pointer", desc = "Use pkg/util.Pointer instead, which is a generic one-liner alternative"}, { pkg = "github.com/xorcare/pointer", desc = "Use pkg/util.Pointer instead, which is a generic one-liner alternative" },
{pkg = "github.com/gofrs/uuid", desc = "Use github.com/google/uuid instead, which we already depend on."}, { pkg = "github.com/gofrs/uuid", desc = "Use github.com/google/uuid instead, which we already depend on." },
] ]
[linters-settings.depguard.rules.coreplugins] [linters-settings.depguard.rules.coreplugins]
deny = [ deny = [
{pkg = "github.com/grafana/grafana/pkg/", desc = "Core plugins are not allowed to depend on Grafana core packages"}, { pkg = "github.com/grafana/grafana/pkg/api", desc = "Core plugins are not allowed to depend on Grafana core packages" },
] { pkg = "github.com/grafana/grafana/pkg/cmd", desc = "Core plugins are not allowed to depend on Grafana core packages" },
files = [ { pkg = "github.com/grafana/grafana/pkg/cuectx", desc = "Core plugins are not allowed to depend on Grafana core packages" },
"**/pkg/tsdb/testdatasource/*", { pkg = "github.com/grafana/grafana/pkg/extensions", desc = "Core plugins are not allowed to depend on Grafana core packages" },
"**/pkg/tsdb/testdatasource/**/*", { pkg = "github.com/grafana/grafana/pkg/kinds", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/middleware", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/modules", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/registry", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/services", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/build", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/codegen", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/events", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/ifaces", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/kindsysreport", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/mocks", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/plugins", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/setting", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/util", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/bus", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/components", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/expr", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/infra", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/login", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/models", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/server", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/tests", desc = "Core plugins are not allowed to depend on Grafana core packages" },
{ pkg = "github.com/grafana/grafana/pkg/web", desc = "Core plugins are not allowed to depend on Grafana core packages" },
] ]
files = ["**/pkg/tsdb/testdatasource/*", "**/pkg/tsdb/testdatasource/**/*"]
[linters-settings.gocritic] [linters-settings.gocritic]
enabled-checks = ["ruleguard"] enabled-checks = ["ruleguard"]

@ -11,9 +11,6 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/data" "github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "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"
) )
func TestTestdataScenarios(t *testing.T) { func TestTestdataScenarios(t *testing.T) {
@ -21,13 +18,14 @@ func TestTestdataScenarios(t *testing.T) {
t.Run("random walk ", func(t *testing.T) { t.Run("random walk ", func(t *testing.T) {
t.Run("Should start at the requested value", func(t *testing.T) { t.Run("Should start at the requested value", func(t *testing.T) {
timeRange := legacydata.DataTimeRange{From: "5m", To: "now", Now: time.Now()} from := time.Now()
to := from.Add(5 * time.Minute)
query := backend.DataQuery{ query := backend.DataQuery{
RefID: "A", RefID: "A",
TimeRange: backend.TimeRange{ TimeRange: backend.TimeRange{
From: timeRange.MustGetFrom(), From: from,
To: timeRange.MustGetTo(), To: to,
}, },
Interval: 100 * time.Millisecond, Interval: 100 * time.Millisecond,
MaxDataPoints: 100, MaxDataPoints: 100,
@ -60,13 +58,14 @@ func TestTestdataScenarios(t *testing.T) {
t.Run("random walk table", func(t *testing.T) { t.Run("random walk table", func(t *testing.T) {
t.Run("Should return a table that looks like value/min/max", func(t *testing.T) { t.Run("Should return a table that looks like value/min/max", func(t *testing.T) {
timeRange := legacydata.DataTimeRange{From: "5m", To: "now", Now: time.Now()} from := time.Now()
to := from.Add(5 * time.Minute)
query := backend.DataQuery{ query := backend.DataQuery{
RefID: "A", RefID: "A",
TimeRange: backend.TimeRange{ TimeRange: backend.TimeRange{
From: timeRange.MustGetFrom(), From: from,
To: timeRange.MustGetTo(), To: to,
}, },
Interval: 100 * time.Millisecond, Interval: 100 * time.Millisecond,
MaxDataPoints: 100, MaxDataPoints: 100,
@ -110,13 +109,14 @@ func TestTestdataScenarios(t *testing.T) {
}) })
t.Run("Should return a table with some nil values", func(t *testing.T) { t.Run("Should return a table with some nil values", func(t *testing.T) {
timeRange := legacydata.DataTimeRange{From: "5m", To: "now", Now: time.Now()} from := time.Now()
to := from.Add(5 * time.Minute)
query := backend.DataQuery{ query := backend.DataQuery{
RefID: "A", RefID: "A",
TimeRange: backend.TimeRange{ TimeRange: backend.TimeRange{
From: timeRange.MustGetFrom(), From: from,
To: timeRange.MustGetTo(), To: to,
}, },
Interval: 100 * time.Millisecond, Interval: 100 * time.Millisecond,
MaxDataPoints: 100, MaxDataPoints: 100,

@ -9,8 +9,6 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend/log" "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/backend/resource/httpadapter"
"github.com/grafana/grafana-plugin-sdk-go/data" "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" "github.com/grafana/grafana/pkg/tsdb/testdatasource/sims"
) )

Loading…
Cancel
Save