From 46a2420ed1576fac207676030079b44227065a3c Mon Sep 17 00:00:00 2001 From: Giuseppe Guerra Date: Tue, 9 Jan 2024 17:42:59 +0100 Subject: [PATCH] fix tests --- pkg/api/metrics_test.go | 6 +++--- pkg/api/plugin_resource_test.go | 2 +- pkg/expr/dataplane_test.go | 2 +- pkg/expr/service_test.go | 4 ++-- pkg/plugins/envvars/envvars_test.go | 16 ++++++++-------- .../pluginsintegration/loader/loader_test.go | 4 ++-- .../plugincontext/plugincontext_test.go | 3 ++- pkg/services/publicdashboards/api/common_test.go | 2 +- pkg/services/query/query_test.go | 2 +- pkg/tsdb/legacydata/service/service_test.go | 2 +- 10 files changed, 22 insertions(+), 21 deletions(-) diff --git a/pkg/api/metrics_test.go b/pkg/api/metrics_test.go index 7eeeb890891..f88b3120073 100644 --- a/pkg/api/metrics_test.go +++ b/pkg/api/metrics_test.go @@ -78,7 +78,7 @@ func TestAPIEndpoint_Metrics_QueryMetricsV2(t *testing.T) { }, }, }, &fakeDatasources.FakeDataSourceService{}, pluginSettings.ProvideService(dbtest.NewFakeDB(), - secretstest.NewFakeSecretsService()), pluginFakes.NewFakeLicensingService(), &config.Cfg{}), + secretstest.NewFakeSecretsService()), pluginFakes.NewFakeLicensingService(), &config.Cfg{}, featuremgmt.WithFeatures()), ) serverFeatureEnabled := SetupAPITestServer(t, func(hs *HTTPServer) { hs.queryDataService = qds @@ -124,7 +124,7 @@ func TestAPIEndpoint_Metrics_PluginDecryptionFailure(t *testing.T) { }, }, }, - ds, pluginSettings.ProvideService(db, secretstest.NewFakeSecretsService()), pluginFakes.NewFakeLicensingService(), &config.Cfg{}, + ds, pluginSettings.ProvideService(db, secretstest.NewFakeSecretsService()), pluginFakes.NewFakeLicensingService(), &config.Cfg{}, featuremgmt.WithFeatures(), ) qds := query.ProvideService( cfg, @@ -301,7 +301,7 @@ func TestDataSourceQueryError(t *testing.T) { PluginList: []pluginstore.Plugin{pluginstore.ToGrafanaDTO(p)}, }, ds, pluginSettings.ProvideService(dbtest.NewFakeDB(), - secretstest.NewFakeSecretsService()), pluginFakes.NewFakeLicensingService(), &config.Cfg{}), + secretstest.NewFakeSecretsService()), pluginFakes.NewFakeLicensingService(), &config.Cfg{}, featuremgmt.WithFeatures()), ) hs.QuotaService = quotatest.New(false, nil) }) diff --git a/pkg/api/plugin_resource_test.go b/pkg/api/plugin_resource_test.go index df94ea6d2b8..5a9b43701eb 100644 --- a/pkg/api/plugin_resource_test.go +++ b/pkg/api/plugin_resource_test.go @@ -56,7 +56,7 @@ func TestCallResource(t *testing.T) { textCtx := pluginsintegration.CreateIntegrationTestCtx(t, cfg, coreRegistry) pcp := plugincontext.ProvideService(cfg, localcache.ProvideService(), textCtx.PluginStore, &datasources.FakeDataSourceService{}, - pluginSettings.ProvideService(db.InitTestDB(t), fakeSecrets.NewFakeSecretsService()), nil, &pCfg) + pluginSettings.ProvideService(db.InitTestDB(t), fakeSecrets.NewFakeSecretsService()), nil, &pCfg, featuremgmt.WithFeatures()) srv := SetupAPITestServer(t, func(hs *HTTPServer) { hs.Cfg = cfg diff --git a/pkg/expr/dataplane_test.go b/pkg/expr/dataplane_test.go index 3973dd8c86e..0648c4d405d 100644 --- a/pkg/expr/dataplane_test.go +++ b/pkg/expr/dataplane_test.go @@ -61,7 +61,7 @@ func framesPassThroughService(t *testing.T, frames data.Frames) (data.Frames, er PluginList: []pluginstore.Plugin{ {JSONData: plugins.JSONData{ID: "test"}}, }}, - &datafakes.FakeDataSourceService{}, nil, pluginFakes.NewFakeLicensingService(), &config.Cfg{}), + &datafakes.FakeDataSourceService{}, nil, pluginFakes.NewFakeLicensingService(), &config.Cfg{}, featuremgmt.WithFeatures()), tracer: tracing.InitializeTracerForTest(), metrics: newMetrics(nil), } diff --git a/pkg/expr/service_test.go b/pkg/expr/service_test.go index 9b0c417a09e..cbf77df022e 100644 --- a/pkg/expr/service_test.go +++ b/pkg/expr/service_test.go @@ -42,7 +42,7 @@ func TestService(t *testing.T) { PluginList: []pluginstore.Plugin{ {JSONData: plugins.JSONData{ID: "test"}}, }, - }, &datafakes.FakeDataSourceService{}, nil, fakes.NewFakeLicensingService(), &config.Cfg{}) + }, &datafakes.FakeDataSourceService{}, nil, fakes.NewFakeLicensingService(), &config.Cfg{}, featuremgmt.WithFeatures()) s := Service{ cfg: setting.NewCfg(), @@ -128,7 +128,7 @@ func TestDSQueryError(t *testing.T) { PluginList: []pluginstore.Plugin{ {JSONData: plugins.JSONData{ID: "test"}}, }, - }, &datafakes.FakeDataSourceService{}, nil, nil, &config.Cfg{}) + }, &datafakes.FakeDataSourceService{}, nil, nil, &config.Cfg{}, featuremgmt.WithFeatures()) s := Service{ cfg: setting.NewCfg(), diff --git a/pkg/plugins/envvars/envvars_test.go b/pkg/plugins/envvars/envvars_test.go index daf8df83c75..2b5fa1eba0a 100644 --- a/pkg/plugins/envvars/envvars_test.go +++ b/pkg/plugins/envvars/envvars_test.go @@ -39,7 +39,7 @@ func TestInitializer_envVars(t *testing.T) { "custom_env_var": "customVal", }, }, - }, licensing) + }, licensing, featuremgmt.WithFeatures()) envVars := envVarsProvider.Get(context.Background(), p) assert.Len(t, envVars, 6) @@ -67,7 +67,7 @@ func TestInitializer_skipHostEnvVars(t *testing.T) { } t.Run("without FlagPluginsSkipHostEnvVars should not populate host env vars", func(t *testing.T) { - envVarsProvider := NewProvider(&config.Cfg{Features: featuremgmt.WithFeatures()}, nil) + envVarsProvider := NewProvider(&config.Cfg{Features: featuremgmt.WithFeatures()}, nil, featuremgmt.WithFeatures()) envVars := envVarsProvider.Get(context.Background(), p) // We want to test that the envvars.Provider does not add any of the host env vars. @@ -82,7 +82,7 @@ func TestInitializer_skipHostEnvVars(t *testing.T) { JSONData: plugins.JSONData{ID: "test"}, SkipHostEnvVars: true, } - envVarsProvider := NewProvider(&config.Cfg{}, nil) + envVarsProvider := NewProvider(&config.Cfg{}, nil, featuremgmt.WithFeatures()) t.Run("should populate allowed host env vars", func(t *testing.T) { // Set all allowed variables @@ -493,7 +493,7 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) { }, } { t.Run(tc.name, func(t *testing.T) { - envVarsProvider := NewProvider(tc.cfg, nil) + envVarsProvider := NewProvider(tc.cfg, nil, featuremgmt.WithFeatures()) envVars := envVarsProvider.Get(context.Background(), tc.plugin) tc.exp(t, envVars) }) @@ -542,7 +542,7 @@ func TestInitializer_authEnvVars(t *testing.T) { envVarsProvider := NewProvider(&config.Cfg{ GrafanaAppURL: "https://myorg.com/", - }, nil) + }, nil, featuremgmt.WithFeatures()) envVars := envVarsProvider.Get(context.Background(), p) assert.Equal(t, "GF_VERSION=", envVars[0]) assert.Equal(t, "GF_APP_URL=https://myorg.com/", envVars[1]) @@ -559,7 +559,7 @@ func TestInitalizer_awsEnvVars(t *testing.T) { AWSAssumeRoleEnabled: true, AWSAllowedAuthProviders: []string{"grafana_assume_role", "keys"}, AWSExternalId: "mock_external_id", - }, nil) + }, nil, featuremgmt.WithFeatures()) envVars := envVarsProvider.Get(context.Background(), p) assert.ElementsMatch(t, []string{"GF_VERSION=", "AWS_AUTH_AssumeRoleEnabled=true", "AWS_AUTH_AllowedAuthProviders=grafana_assume_role,keys", "AWS_AUTH_EXTERNAL_ID=mock_external_id"}, envVars) }) @@ -576,7 +576,7 @@ func TestInitializer_featureToggleEnvVar(t *testing.T) { p := &plugins.Plugin{} envVarsProvider := NewProvider(&config.Cfg{ Features: featuremgmt.WithFeatures(expectedFeatures[0], true, expectedFeatures[1], true), - }, nil) + }, nil, featuremgmt.WithFeatures()) envVars := envVarsProvider.Get(context.Background(), p) assert.Equal(t, 2, len(envVars)) @@ -621,7 +621,7 @@ func TestInitalizer_azureEnvVars(t *testing.T) { UsernameAssertion: true, }, }, - }, nil) + }, nil, featuremgmt.WithFeatures()) envVars := envVarsProvider.Get(context.Background(), p) assert.ElementsMatch(t, []string{"GF_VERSION=", "GFAZPL_AZURE_CLOUD=AzureCloud", "GFAZPL_MANAGED_IDENTITY_ENABLED=true", "GFAZPL_MANAGED_IDENTITY_CLIENT_ID=mock_managed_identity_client_id", diff --git a/pkg/services/pluginsintegration/loader/loader_test.go b/pkg/services/pluginsintegration/loader/loader_test.go index 1f3386851ee..8c5c3845773 100644 --- a/pkg/services/pluginsintegration/loader/loader_test.go +++ b/pkg/services/pluginsintegration/loader/loader_test.go @@ -1623,7 +1623,7 @@ func newLoader(t *testing.T, cfg *config.Cfg, reg registry.Service, proc process finder.NewLocalFinder(false, featuremgmt.WithFeatures()), reg), pipeline.ProvideBootstrapStage(cfg, signature.DefaultCalculator(cfg), assets), pipeline.ProvideValidationStage(cfg, signature.NewValidator(signature.NewUnsignedAuthorizer(cfg)), angularInspector, sigErrTracker), - pipeline.ProvideInitializationStage(cfg, reg, lic, backendFactory, proc, &fakes.FakeAuthService{}, fakes.NewFakeRoleRegistry()), + pipeline.ProvideInitializationStage(cfg, reg, lic, backendFactory, proc, &fakes.FakeAuthService{}, fakes.NewFakeRoleRegistry(), featuremgmt.WithFeatures()), terminate) } @@ -1656,7 +1656,7 @@ func newLoaderWithOpts(t *testing.T, cfg *config.Cfg, opts loaderDepOpts) *Loade finder.NewLocalFinder(false, featuremgmt.WithFeatures()), reg), pipeline.ProvideBootstrapStage(cfg, signature.DefaultCalculator(cfg), assets), pipeline.ProvideValidationStage(cfg, signature.NewValidator(signature.NewUnsignedAuthorizer(cfg)), angularInspector, sigErrTracker), - pipeline.ProvideInitializationStage(cfg, reg, lic, backendFactoryProvider, proc, authServiceRegistry, fakes.NewFakeRoleRegistry()), + pipeline.ProvideInitializationStage(cfg, reg, lic, backendFactoryProvider, proc, authServiceRegistry, fakes.NewFakeRoleRegistry(), featuremgmt.WithFeatures()), terminate) } diff --git a/pkg/services/pluginsintegration/plugincontext/plugincontext_test.go b/pkg/services/pluginsintegration/plugincontext/plugincontext_test.go index 9d4c750ff2c..bcc03835437 100644 --- a/pkg/services/pluginsintegration/plugincontext/plugincontext_test.go +++ b/pkg/services/pluginsintegration/plugincontext/plugincontext_test.go @@ -15,6 +15,7 @@ import ( "github.com/grafana/grafana/pkg/plugins/manager/registry" "github.com/grafana/grafana/pkg/services/datasources" fakeDatasources "github.com/grafana/grafana/pkg/services/datasources/fakes" + "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext" "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginsettings" pluginSettings "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginsettings/service" @@ -43,7 +44,7 @@ func TestGet(t *testing.T) { db := &dbtest.FakeDB{ExpectedError: pluginsettings.ErrPluginSettingNotFound} pcp := plugincontext.ProvideService(cfg, localcache.ProvideService(), pluginstore.New(preg, &pluginFakes.FakeLoader{}), - ds, pluginSettings.ProvideService(db, secretstest.NewFakeSecretsService()), pluginFakes.NewFakeLicensingService(), &config.Cfg{}, + ds, pluginSettings.ProvideService(db, secretstest.NewFakeSecretsService()), pluginFakes.NewFakeLicensingService(), &config.Cfg{}, featuremgmt.WithFeatures(), ) identity := &user.SignedInUser{OrgID: int64(1), Login: "admin"} diff --git a/pkg/services/publicdashboards/api/common_test.go b/pkg/services/publicdashboards/api/common_test.go index b8dc715b71c..5d5b032576d 100644 --- a/pkg/services/publicdashboards/api/common_test.go +++ b/pkg/services/publicdashboards/api/common_test.go @@ -141,7 +141,7 @@ func buildQueryDataService(t *testing.T, cs datasources.CacheService, fpc *fakeP }, }, }, ds, pluginSettings.ProvideService(store, fakeSecrets.NewFakeSecretsService()), fakes.NewFakeLicensingService(), - &config.Cfg{}) + &config.Cfg{}, featuremgmt.WithFeatures()) return query.ProvideService( setting.NewCfg(), diff --git a/pkg/services/query/query_test.go b/pkg/services/query/query_test.go index c1cd5166b6f..12cb385d64d 100644 --- a/pkg/services/query/query_test.go +++ b/pkg/services/query/query_test.go @@ -477,7 +477,7 @@ func setup(t *testing.T) *testContext { {JSONData: plugins.JSONData{ID: "mysql"}}, }, }, fakeDatasourceService, - pluginSettings.ProvideService(sqlStore, secretsService), pluginFakes.NewFakeLicensingService(), &config.Cfg{}, + pluginSettings.ProvideService(sqlStore, secretsService), pluginFakes.NewFakeLicensingService(), &config.Cfg{}, featuremgmt.WithFeatures(), ) exprService := expr.ProvideService(&setting.Cfg{ExpressionsEnabled: true}, pc, pCtxProvider, &featuremgmt.FeatureManager{}, nil, tracing.InitializeTracerForTest()) diff --git a/pkg/tsdb/legacydata/service/service_test.go b/pkg/tsdb/legacydata/service/service_test.go index ebf5f98d488..6919262aa92 100644 --- a/pkg/tsdb/legacydata/service/service_test.go +++ b/pkg/tsdb/legacydata/service/service_test.go @@ -47,7 +47,7 @@ func TestHandleRequest(t *testing.T) { pCtxProvider := plugincontext.ProvideService(sqlStore.Cfg, localcache.ProvideService(), &pluginstore.FakePluginStore{ PluginList: []pluginstore.Plugin{{JSONData: plugins.JSONData{ID: "test"}}}, - }, dsService, pluginSettings.ProvideService(sqlStore, secretsService), pluginFakes.NewFakeLicensingService(), &config.Cfg{}) + }, dsService, pluginSettings.ProvideService(sqlStore, secretsService), pluginFakes.NewFakeLicensingService(), &config.Cfg{}, featuremgmt.WithFeatures()) s := ProvideService(client, nil, dsService, pCtxProvider) ds := &datasources.DataSource{ID: 12, Type: "test", JsonData: simplejson.New()}