From dd8f88b194e0aedd98e5b51ced7a088e03681f6f Mon Sep 17 00:00:00 2001 From: Andres Martinez Gotor Date: Thu, 21 Sep 2023 10:39:28 +0200 Subject: [PATCH] Chore: Remove lint exceptions from testdata backend (#75148) --- .golangci.toml | 43 +++++++++++++++++------ pkg/tsdb/testdatasource/scenarios_test.go | 24 ++++++------- pkg/tsdb/testdatasource/testdata.go | 2 -- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/.golangci.toml b/.golangci.toml index 987f81349fa..e529b178e4d 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -16,21 +16,44 @@ confidence = 3 [linters-settings.depguard.rules.main] allow = [] # allow all 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 = "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/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 = "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 = "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/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/**/*", + { 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" }, + { pkg = "github.com/grafana/grafana/pkg/cuectx", desc = "Core plugins are not allowed to depend on Grafana core packages" }, + { pkg = "github.com/grafana/grafana/pkg/extensions", desc = "Core plugins are not allowed to depend on Grafana core packages" }, + { 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] enabled-checks = ["ruleguard"] diff --git a/pkg/tsdb/testdatasource/scenarios_test.go b/pkg/tsdb/testdatasource/scenarios_test.go index ed43bc8bcb8..cf66d1f061d 100644 --- a/pkg/tsdb/testdatasource/scenarios_test.go +++ b/pkg/tsdb/testdatasource/scenarios_test.go @@ -11,9 +11,6 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" "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" ) func TestTestdataScenarios(t *testing.T) { @@ -21,13 +18,14 @@ func TestTestdataScenarios(t *testing.T) { t.Run("random walk ", 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{ RefID: "A", TimeRange: backend.TimeRange{ - From: timeRange.MustGetFrom(), - To: timeRange.MustGetTo(), + From: from, + To: to, }, Interval: 100 * time.Millisecond, MaxDataPoints: 100, @@ -60,13 +58,14 @@ func TestTestdataScenarios(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) { - timeRange := legacydata.DataTimeRange{From: "5m", To: "now", Now: time.Now()} + from := time.Now() + to := from.Add(5 * time.Minute) query := backend.DataQuery{ RefID: "A", TimeRange: backend.TimeRange{ - From: timeRange.MustGetFrom(), - To: timeRange.MustGetTo(), + From: from, + To: to, }, Interval: 100 * time.Millisecond, 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) { - timeRange := legacydata.DataTimeRange{From: "5m", To: "now", Now: time.Now()} + from := time.Now() + to := from.Add(5 * time.Minute) query := backend.DataQuery{ RefID: "A", TimeRange: backend.TimeRange{ - From: timeRange.MustGetFrom(), - To: timeRange.MustGetTo(), + From: from, + To: to, }, Interval: 100 * time.Millisecond, MaxDataPoints: 100, diff --git a/pkg/tsdb/testdatasource/testdata.go b/pkg/tsdb/testdatasource/testdata.go index 44fc238ce45..8596bdf8ae3 100644 --- a/pkg/tsdb/testdatasource/testdata.go +++ b/pkg/tsdb/testdatasource/testdata.go @@ -9,8 +9,6 @@ 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" )