From 3651a8e976acc7bfc57d481660d27e204a384356 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Tue, 30 Jun 2020 11:05:47 +0200 Subject: [PATCH] Chore: Disable scopelint for tests (#25923) Signed-off-by: Arve Knudsen --- pkg/api/dashboard_test.go | 2 -- pkg/api/folder_test.go | 2 -- pkg/api/login_test.go | 2 -- pkg/api/pluginproxy/access_token_provider_test.go | 1 - pkg/api/pluginproxy/ds_proxy_test.go | 1 - pkg/cmd/grafana-cli/commands/upgrade_all_command_test.go | 6 ++---- pkg/cmd/grafana-server/diagnostics_test.go | 2 -- pkg/components/gtime/gtime_test.go | 1 - pkg/login/social/azuread_oauth_test.go | 1 - pkg/login/social/generic_oauth_test.go | 3 --- pkg/plugins/backendplugin/grpcplugin/log_wrapper_test.go | 1 - pkg/plugins/plugins_test.go | 1 - pkg/services/alerting/alerting_usage_test.go | 1 - pkg/services/guardian/guardian_test.go | 6 ------ pkg/services/sqlstore/migrations/migrations_test.go | 1 - pkg/services/sqlstore/sqlstore_test.go | 1 - .../azuremonitor/applicationinsights-datasource_test.go | 1 - pkg/tsdb/azuremonitor/applicationinsights-metrics_test.go | 1 - .../azuremonitor/azure-log-analytics-datasource_test.go | 2 -- .../azuremonitor/azure-log-analytics-table-frame_test.go | 1 - pkg/tsdb/azuremonitor/azuremonitor-datasource_test.go | 3 --- pkg/tsdb/azuremonitor/macros_test.go | 1 - pkg/tsdb/frame_util_test.go | 1 - pkg/tsdb/influxdb/flux/macros_test.go | 1 - scripts/go/configs/.golangci.toml | 4 ++++ scripts/go/configs/ci/.golangci.toml | 4 ++++ 26 files changed, 10 insertions(+), 41 deletions(-) diff --git a/pkg/api/dashboard_test.go b/pkg/api/dashboard_test.go index 318678ac31c..b58cf217d3a 100644 --- a/pkg/api/dashboard_test.go +++ b/pkg/api/dashboard_test.go @@ -42,7 +42,6 @@ func TestGetHomeDashboard(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { dash := dtos.DashboardFullWithMeta{} dash.Meta.IsHome = true @@ -802,7 +801,6 @@ func TestDashboardApiEndpoint(t *testing.T) { } for _, tc := range testCases { - tc := tc mock := &dashboards.FakeDashboardService{ SaveDashboardError: tc.SaveError, } diff --git a/pkg/api/folder_test.go b/pkg/api/folder_test.go index 046b4674fad..af1dd8f94e6 100644 --- a/pkg/api/folder_test.go +++ b/pkg/api/folder_test.go @@ -62,7 +62,6 @@ func TestFoldersApiEndpoint(t *testing.T) { } for _, tc := range testCases { - tc := tc mock := &fakeFolderService{ CreateFolderError: tc.Error, } @@ -120,7 +119,6 @@ func TestFoldersApiEndpoint(t *testing.T) { } for _, tc := range testCases { - tc := tc mock := &fakeFolderService{ UpdateFolderError: tc.Error, } diff --git a/pkg/api/login_test.go b/pkg/api/login_test.go index f87a5b7dca1..bf76921eeb3 100644 --- a/pkg/api/login_test.go +++ b/pkg/api/login_test.go @@ -252,7 +252,6 @@ func TestLoginViewRedirect(t *testing.T) { } for _, c := range redirectCases { - c := c hs.Cfg.AppUrl = c.appURL hs.Cfg.AppSubUrl = c.appSubURL t.Run(c.desc, func(t *testing.T) { @@ -421,7 +420,6 @@ func TestLoginPostRedirect(t *testing.T) { } for _, c := range redirectCases { - c := c hs.Cfg.AppUrl = c.appURL hs.Cfg.AppSubUrl = c.appSubURL t.Run(c.desc, func(t *testing.T) { diff --git a/pkg/api/pluginproxy/access_token_provider_test.go b/pkg/api/pluginproxy/access_token_provider_test.go index aee616eccda..220f2570d43 100644 --- a/pkg/api/pluginproxy/access_token_provider_test.go +++ b/pkg/api/pluginproxy/access_token_provider_test.go @@ -189,7 +189,6 @@ func TestAccessToken(t *testing.T) { }, } for _, testCase := range testCases { - testCase := testCase Convey(testCase.desc, func() { clearTokenCache() // reset the httphandler counter diff --git a/pkg/api/pluginproxy/ds_proxy_test.go b/pkg/api/pluginproxy/ds_proxy_test.go index 4909d2428f6..da415b5752e 100644 --- a/pkg/api/pluginproxy/ds_proxy_test.go +++ b/pkg/api/pluginproxy/ds_proxy_test.go @@ -617,7 +617,6 @@ func TestNewDataSourceProxy_MSSQL(t *testing.T) { }, } for _, tc := range tcs { - tc := tc t.Run(tc.description, func(t *testing.T) { cfg := setting.Cfg{} plugin := plugins.DataSourcePlugin{} diff --git a/pkg/cmd/grafana-cli/commands/upgrade_all_command_test.go b/pkg/cmd/grafana-cli/commands/upgrade_all_command_test.go index c2024d2ed1a..57ea8c15dbc 100644 --- a/pkg/cmd/grafana-cli/commands/upgrade_all_command_test.go +++ b/pkg/cmd/grafana-cli/commands/upgrade_all_command_test.go @@ -21,10 +21,9 @@ func TestVersionComparison(t *testing.T) { } for k, v := range upgradeablePlugins { - key := k val := v t.Run(fmt.Sprintf("for %s should be true", k), func(t *testing.T) { - assert.True(t, shouldUpgrade(key, &val)) + assert.True(t, shouldUpgrade(k, &val)) }) } }) @@ -41,10 +40,9 @@ func TestVersionComparison(t *testing.T) { } for k, v := range shouldNotUpgrade { - key := k val := v t.Run(fmt.Sprintf("for %s should be false", k), func(t *testing.T) { - assert.False(t, shouldUpgrade(key, &val)) + assert.False(t, shouldUpgrade(k, &val)) }) } }) diff --git a/pkg/cmd/grafana-server/diagnostics_test.go b/pkg/cmd/grafana-server/diagnostics_test.go index 0f73fff3ba7..f7e7b9874aa 100644 --- a/pkg/cmd/grafana-server/diagnostics_test.go +++ b/pkg/cmd/grafana-server/diagnostics_test.go @@ -23,7 +23,6 @@ func TestProfilingDiagnostics(t *testing.T) { } for i, tc := range tcs { - tc := tc t.Run(fmt.Sprintf("testcase %d", i), func(t *testing.T) { os.Clearenv() if tc.enabledEnv != "" { @@ -56,7 +55,6 @@ func TestTracingDiagnostics(t *testing.T) { } for i, tc := range tcs { - tc := tc t.Run(fmt.Sprintf("testcase %d", i), func(t *testing.T) { os.Clearenv() if tc.enabledEnv != "" { diff --git a/pkg/components/gtime/gtime_test.go b/pkg/components/gtime/gtime_test.go index 460afda022f..4dab30fbf6a 100644 --- a/pkg/components/gtime/gtime_test.go +++ b/pkg/components/gtime/gtime_test.go @@ -26,7 +26,6 @@ func TestParseInterval(t *testing.T) { } for i, tc := range tcs { - tc := tc t.Run(fmt.Sprintf("testcase %d", i), func(t *testing.T) { res, err := ParseInterval(tc.interval) if tc.err == "" { diff --git a/pkg/login/social/azuread_oauth_test.go b/pkg/login/social/azuread_oauth_test.go index b110d775aa7..7fc04a9b733 100644 --- a/pkg/login/social/azuread_oauth_test.go +++ b/pkg/login/social/azuread_oauth_test.go @@ -221,7 +221,6 @@ func TestSocialAzureAD_UserInfo(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { s := &SocialAzureAD{ SocialBase: tt.fields.SocialBase, diff --git a/pkg/login/social/generic_oauth_test.go b/pkg/login/social/generic_oauth_test.go index 69ee26ccf02..dfed846b0fd 100644 --- a/pkg/login/social/generic_oauth_test.go +++ b/pkg/login/social/generic_oauth_test.go @@ -89,7 +89,6 @@ func TestSearchJSONForEmail(t *testing.T) { } for _, test := range tests { - test := test provider.emailAttributePath = test.EmailAttributePath t.Run(test.Name, func(t *testing.T) { actualResult, err := provider.searchJSONForAttr(test.EmailAttributePath, test.UserInfoJSONResponse) @@ -153,7 +152,6 @@ func TestSearchJSONForRole(t *testing.T) { } for _, test := range tests { - test := test provider.roleAttributePath = test.RoleAttributePath t.Run(test.Name, func(t *testing.T) { actualResult, err := provider.searchJSONForAttr(test.RoleAttributePath, test.UserInfoJSONResponse) @@ -306,7 +304,6 @@ func TestUserInfoSearchesForEmailAndRole(t *testing.T) { } for _, test := range tests { - test := test provider.roleAttributePath = test.RoleAttributePath t.Run(test.Name, func(t *testing.T) { response, err := json.Marshal(test.APIURLResponse) diff --git a/pkg/plugins/backendplugin/grpcplugin/log_wrapper_test.go b/pkg/plugins/backendplugin/grpcplugin/log_wrapper_test.go index de28aea1b6a..e1ffc650faf 100644 --- a/pkg/plugins/backendplugin/grpcplugin/log_wrapper_test.go +++ b/pkg/plugins/backendplugin/grpcplugin/log_wrapper_test.go @@ -21,7 +21,6 @@ func TestLogWrapper(t *testing.T) { } for i, tc := range tcs { - tc := tc t.Run(fmt.Sprintf("formatArgs testcase %d", i), func(t *testing.T) { res := formatArgs(tc.args...) assert.Exactly(t, tc.expectedResult, res) diff --git a/pkg/plugins/plugins_test.go b/pkg/plugins/plugins_test.go index a8e98ba8923..94a4d1fd4ea 100644 --- a/pkg/plugins/plugins_test.go +++ b/pkg/plugins/plugins_test.go @@ -177,7 +177,6 @@ func TestPluginManager_IsBackendOnlyPlugin(t *testing.T) { {name: "renderer", isBackendOnly: true}, {name: "app", isBackendOnly: false}, } { - c := c t.Run(fmt.Sprintf("Plugin %s", c.name), func(t *testing.T) { result := pluginScanner.IsBackendOnlyPlugin(c.name) diff --git a/pkg/services/alerting/alerting_usage_test.go b/pkg/services/alerting/alerting_usage_test.go index b60fc5626f2..5816d1aa3ec 100644 --- a/pkg/services/alerting/alerting_usage_test.go +++ b/pkg/services/alerting/alerting_usage_test.go @@ -107,7 +107,6 @@ func TestParsingAlertRuleSettings(t *testing.T) { require.NoError(t, err, "Init should not return an error") for _, tc := range tcs { - tc := tc t.Run(tc.name, func(t *testing.T) { content, err := ioutil.ReadFile(tc.file) require.NoError(t, err, "expected to be able to read file") diff --git a/pkg/services/guardian/guardian_test.go b/pkg/services/guardian/guardian_test.go index 9b67d0a26d6..24f44d4497e 100644 --- a/pkg/services/guardian/guardian_test.go +++ b/pkg/services/guardian/guardian_test.go @@ -372,7 +372,6 @@ func (sc *scenarioContext) verifyUpdateDashboardPermissionsShouldBeAllowed(pt pe } for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} { - p := p tc := fmt.Sprintf("When updating dashboard permissions with %s permissions should be allowed", p.String()) Convey(tc, func() { @@ -421,7 +420,6 @@ func (sc *scenarioContext) verifyUpdateDashboardPermissionsShouldNotBeAllowed(pt } for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} { - p := p tc := fmt.Sprintf("When updating dashboard permissions with %s permissions should NOT be allowed", p.String()) Convey(tc, func() { @@ -462,7 +460,6 @@ func (sc *scenarioContext) verifyUpdateChildDashboardPermissionsShouldBeAllowed( } for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} { - p := p tc := fmt.Sprintf("When updating child dashboard permissions with %s permissions should be allowed", p.String()) Convey(tc, func() { @@ -526,7 +523,6 @@ func (sc *scenarioContext) verifyUpdateChildDashboardPermissionsShouldNotBeAllow } for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} { - p := p tc := fmt.Sprintf("When updating child dashboard permissions with %s permissions should NOT be allowed", p.String()) Convey(tc, func() { @@ -590,7 +586,6 @@ func (sc *scenarioContext) verifyUpdateChildDashboardPermissionsWithOverrideShou } for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} { - p := p // permission to update is higher than parent folder permission if p > parentFolderPermission { continue @@ -636,7 +631,6 @@ func (sc *scenarioContext) verifyUpdateChildDashboardPermissionsWithOverrideShou } for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} { - p := p // permission to update is lower than or equal to parent folder permission if p <= parentFolderPermission { continue diff --git a/pkg/services/sqlstore/migrations/migrations_test.go b/pkg/services/sqlstore/migrations/migrations_test.go index c4d12a57f23..9172912d963 100644 --- a/pkg/services/sqlstore/migrations/migrations_test.go +++ b/pkg/services/sqlstore/migrations/migrations_test.go @@ -16,7 +16,6 @@ func TestMigrations(t *testing.T) { } for _, testDB := range testDBs { - testDB := testDB sql := `select count(*) as count from migration_log` r := struct { Count int64 diff --git a/pkg/services/sqlstore/sqlstore_test.go b/pkg/services/sqlstore/sqlstore_test.go index f87a865c4cf..99896ca4e9d 100644 --- a/pkg/services/sqlstore/sqlstore_test.go +++ b/pkg/services/sqlstore/sqlstore_test.go @@ -71,7 +71,6 @@ func TestSqlConnectionString(t *testing.T) { t.Helper() for _, testCase := range sqlStoreTestCases { - testCase := testCase Convey(testCase.name, func() { sqlstore := &SqlStore{} sqlstore.Cfg = makeSqlStoreTestConfig(testCase.dbType, testCase.dbHost) diff --git a/pkg/tsdb/azuremonitor/applicationinsights-datasource_test.go b/pkg/tsdb/azuremonitor/applicationinsights-datasource_test.go index 32a2f13f2e2..dd2ab3df8ea 100644 --- a/pkg/tsdb/azuremonitor/applicationinsights-datasource_test.go +++ b/pkg/tsdb/azuremonitor/applicationinsights-datasource_test.go @@ -195,7 +195,6 @@ func TestAppInsightsPluginRoutes(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { route, routeName, err := datasource.getPluginRoute(plugin, tt.cloudName) tt.Err(t, err) diff --git a/pkg/tsdb/azuremonitor/applicationinsights-metrics_test.go b/pkg/tsdb/azuremonitor/applicationinsights-metrics_test.go index 98eebada898..53a3debce22 100644 --- a/pkg/tsdb/azuremonitor/applicationinsights-metrics_test.go +++ b/pkg/tsdb/azuremonitor/applicationinsights-metrics_test.go @@ -104,7 +104,6 @@ func TestInsightsMetricsResultToFrame(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { res, err := loadInsightsMetricsResponse(tt.testFile) require.NoError(t, err) diff --git a/pkg/tsdb/azuremonitor/azure-log-analytics-datasource_test.go b/pkg/tsdb/azuremonitor/azure-log-analytics-datasource_test.go index 62ba45aebb7..879a80c0d8a 100644 --- a/pkg/tsdb/azuremonitor/azure-log-analytics-datasource_test.go +++ b/pkg/tsdb/azuremonitor/azure-log-analytics-datasource_test.go @@ -69,7 +69,6 @@ func TestBuildingAzureLogAnalyticsQueries(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { queries, err := datasource.buildQueries(tt.queryModel, tt.timeRange) tt.Err(t, err) @@ -142,7 +141,6 @@ func TestPluginRoutes(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { route, proxypass, err := datasource.getPluginRoute(plugin, tt.cloudName) tt.Err(t, err) diff --git a/pkg/tsdb/azuremonitor/azure-log-analytics-table-frame_test.go b/pkg/tsdb/azuremonitor/azure-log-analytics-table-frame_test.go index a9e624c9adb..28dc7cc10de 100644 --- a/pkg/tsdb/azuremonitor/azure-log-analytics-table-frame_test.go +++ b/pkg/tsdb/azuremonitor/azure-log-analytics-table-frame_test.go @@ -122,7 +122,6 @@ func TestLogTableToFrame(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { res, err := loadLogAnalyticsTestFileWithNumber(tt.testFile) require.NoError(t, err) diff --git a/pkg/tsdb/azuremonitor/azuremonitor-datasource_test.go b/pkg/tsdb/azuremonitor/azuremonitor-datasource_test.go index df2641135b4..89aaa24049e 100644 --- a/pkg/tsdb/azuremonitor/azuremonitor-datasource_test.go +++ b/pkg/tsdb/azuremonitor/azuremonitor-datasource_test.go @@ -98,7 +98,6 @@ func TestAzureMonitorBuildQueries(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { for k, v := range commonAzureModelProps { tt.azureMonitorVariedProperties[k] = v @@ -364,7 +363,6 @@ func TestAzureMonitorParseResponse(t *testing.T) { datasource := &AzureMonitorDatasource{} for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { azData, err := loadTestFile("azuremonitor/" + tt.responseFile) require.NoError(t, err) @@ -422,7 +420,6 @@ func TestFindClosestAllowIntervalMS(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { interval := findClosestAllowedIntervalMS(tt.inputInterval, tt.allowedTimeGrains) require.Equal(t, tt.expectedInterval, interval) diff --git a/pkg/tsdb/azuremonitor/macros_test.go b/pkg/tsdb/azuremonitor/macros_test.go index 00ff3446180..98554832a06 100644 --- a/pkg/tsdb/azuremonitor/macros_test.go +++ b/pkg/tsdb/azuremonitor/macros_test.go @@ -139,7 +139,6 @@ func TestAzureLogAnalyticsMacros(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { defaultTimeField := "TimeGenerated" rawQuery, err := KqlInterpolate(tt.query, timeRange, tt.kql, defaultTimeField) diff --git a/pkg/tsdb/frame_util_test.go b/pkg/tsdb/frame_util_test.go index f84d06b3d6a..d4a35192bf4 100644 --- a/pkg/tsdb/frame_util_test.go +++ b/pkg/tsdb/frame_util_test.go @@ -128,7 +128,6 @@ func TestFrameToSeriesSlice(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { seriesSlice, err := FrameToSeriesSlice(tt.frame) tt.Err(t, err) diff --git a/pkg/tsdb/influxdb/flux/macros_test.go b/pkg/tsdb/influxdb/flux/macros_test.go index 75521d0bf03..3a939bbc827 100644 --- a/pkg/tsdb/influxdb/flux/macros_test.go +++ b/pkg/tsdb/influxdb/flux/macros_test.go @@ -35,7 +35,6 @@ func TestInterpolate(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { query := QueryModel{ diff --git a/scripts/go/configs/.golangci.toml b/scripts/go/configs/.golangci.toml index 8b1019a46ec..304733530e9 100644 --- a/scripts/go/configs/.golangci.toml +++ b/scripts/go/configs/.golangci.toml @@ -44,6 +44,10 @@ enable = [ # "gocyclo", # "unparam" +[[issues.exclude-rules]] +path = "_test\\.go" +linters = ["scopelint"] + [[issues.exclude-rules]] linters = ["gosec"] text = "G108" diff --git a/scripts/go/configs/ci/.golangci.toml b/scripts/go/configs/ci/.golangci.toml index 57bc7588c62..e38382bcf98 100644 --- a/scripts/go/configs/ci/.golangci.toml +++ b/scripts/go/configs/ci/.golangci.toml @@ -11,6 +11,10 @@ min-occurrences = 5 [linters] disable-all = true +[[issues.exclude-rules]] +path = "_test\\.go" +linters = ["scopelint"] + [[issues.exclude-rules]] linters = ["gosec"] text = "G108"