From ed98d7bc27cf3a9b9ae34faff4aa7e3042ace1db Mon Sep 17 00:00:00 2001 From: ying-jeanne <74549700+ying-jeanne@users.noreply.github.com> Date: Tue, 18 Oct 2022 21:31:56 +0800 Subject: [PATCH] Chore: remove busmock (#57170) --- pkg/bus/mock/mock.go | 11 ----------- pkg/services/folder/folderimpl/folder_test.go | 8 ++++---- pkg/services/libraryelements/libraryelements_test.go | 7 ++++--- pkg/services/librarypanels/librarypanels_test.go | 7 ++++--- pkg/services/ngalert/ngalert_test.go | 5 +++-- pkg/services/ngalert/tests/util.go | 5 +++-- 6 files changed, 18 insertions(+), 25 deletions(-) delete mode 100644 pkg/bus/mock/mock.go diff --git a/pkg/bus/mock/mock.go b/pkg/bus/mock/mock.go deleted file mode 100644 index f65e9b6b122..00000000000 --- a/pkg/bus/mock/mock.go +++ /dev/null @@ -1,11 +0,0 @@ -package mock - -import ( - "github.com/grafana/grafana/pkg/bus" - "github.com/grafana/grafana/pkg/infra/tracing" -) - -func New() bus.Bus { - tracer := tracing.InitializeTracerForTest() - return bus.ProvideBus(tracer) -} diff --git a/pkg/services/folder/folderimpl/folder_test.go b/pkg/services/folder/folderimpl/folder_test.go index 8457ae55465..45246154880 100644 --- a/pkg/services/folder/folderimpl/folder_test.go +++ b/pkg/services/folder/folderimpl/folder_test.go @@ -9,8 +9,9 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - busmock "github.com/grafana/grafana/pkg/bus/mock" + "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/infra/log" + "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/models" acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" "github.com/grafana/grafana/pkg/services/dashboards" @@ -32,8 +33,7 @@ func TestIntegrationProvideFolderService(t *testing.T) { t.Run("should register scope resolvers", func(t *testing.T) { cfg := setting.NewCfg() ac := acmock.New() - - ProvideService(ac, busmock.New(), cfg, nil, nil, nil, nil, nil) + ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), cfg, nil, nil, nil, nil, nil) require.Len(t, ac.Calls.RegisterAttributeScopeResolver, 2) }) @@ -61,7 +61,7 @@ func TestIntegrationFolderService(t *testing.T) { searchService: nil, features: features, permissions: folderPermissions, - bus: busmock.New(), + bus: bus.ProvideBus(tracing.InitializeTracerForTest()), } t.Run("Given user has no permissions", func(t *testing.T) { diff --git a/pkg/services/libraryelements/libraryelements_test.go b/pkg/services/libraryelements/libraryelements_test.go index 6ab40e71910..fe3572822af 100644 --- a/pkg/services/libraryelements/libraryelements_test.go +++ b/pkg/services/libraryelements/libraryelements_test.go @@ -13,8 +13,9 @@ import ( "github.com/stretchr/testify/require" "github.com/grafana/grafana/pkg/api/response" - busmock "github.com/grafana/grafana/pkg/bus/mock" + "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/simplejson" + "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/models" acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" "github.com/grafana/grafana/pkg/services/alerting" @@ -310,7 +311,7 @@ func createFolderWithACL(t *testing.T, sqlStore db.DB, title string, user user.S cfg, dashboardStore, nil, features, folderPermissions, dashboardPermissions, ac, ) - s := folderimpl.ProvideService(ac, busmock.New(), cfg, d, dashboardStore, features, folderPermissions, nil) + s := folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), cfg, d, dashboardStore, features, folderPermissions, nil) t.Logf("Creating folder with title and UID %q", title) folder, err := s.CreateFolder(context.Background(), &user, user.OrgID, title, title) require.NoError(t, err) @@ -420,7 +421,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo service := LibraryElementService{ Cfg: sqlStore.Cfg, SQLStore: sqlStore, - folderService: folderimpl.ProvideService(ac, busmock.New(), sqlStore.Cfg, dashboardService, dashboardStore, features, folderPermissions, nil), + folderService: folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), sqlStore.Cfg, dashboardService, dashboardStore, features, folderPermissions, nil), } usr := user.SignedInUser{ diff --git a/pkg/services/librarypanels/librarypanels_test.go b/pkg/services/librarypanels/librarypanels_test.go index fb9e5c82beb..e202ca3f1fd 100644 --- a/pkg/services/librarypanels/librarypanels_test.go +++ b/pkg/services/librarypanels/librarypanels_test.go @@ -10,8 +10,9 @@ import ( "github.com/stretchr/testify/require" "github.com/grafana/grafana/pkg/api/routing" - busmock "github.com/grafana/grafana/pkg/bus/mock" + "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/simplejson" + "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/models" acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" "github.com/grafana/grafana/pkg/services/alerting" @@ -1408,7 +1409,7 @@ func createFolderWithACL(t *testing.T, sqlStore db.DB, title string, user *user. dashboardPermissions := acmock.NewMockedPermissionsService() dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg)) d := dashboardservice.ProvideDashboardService(cfg, dashboardStore, nil, features, folderPermissions, dashboardPermissions, ac) - s := folderimpl.ProvideService(ac, busmock.New(), cfg, d, dashboardStore, features, folderPermissions, nil) + s := folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), cfg, d, dashboardStore, features, folderPermissions, nil) t.Logf("Creating folder with title and UID %q", title) folder, err := s.CreateFolder(context.Background(), user, user.OrgID, title, title) @@ -1510,7 +1511,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo cfg, dashboardStore, &alerting.DashAlertExtractorService{}, features, folderPermissions, dashboardPermissions, ac, ) - folderService := folderimpl.ProvideService(ac, busmock.New(), cfg, dashboardService, dashboardStore, features, folderPermissions, nil) + folderService := folderimpl.ProvideService(ac, bus.ProvideBus(tracing.InitializeTracerForTest()), cfg, dashboardService, dashboardStore, features, folderPermissions, nil) elementService := libraryelements.ProvideService(cfg, sqlStore, routing.NewRouteRegister(), folderService) service := LibraryPanelService{ diff --git a/pkg/services/ngalert/ngalert_test.go b/pkg/services/ngalert/ngalert_test.go index 30540c6f1e7..7004198e1eb 100644 --- a/pkg/services/ngalert/ngalert_test.go +++ b/pkg/services/ngalert/ngalert_test.go @@ -9,9 +9,10 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - busmock "github.com/grafana/grafana/pkg/bus/mock" + "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/events" "github.com/grafana/grafana/pkg/infra/log" + "github.com/grafana/grafana/pkg/infra/tracing" models2 "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/ngalert/schedule" @@ -28,7 +29,7 @@ func Test_subscribeToFolderChanges(t *testing.T) { } rules := models.GenerateAlertRules(5, models.AlertRuleGen(models.WithOrgID(orgID), models.WithNamespace(folder))) - bus := busmock.New() + bus := bus.ProvideBus(tracing.InitializeTracerForTest()) db := fakes.NewRuleStore(t) db.Folders[orgID] = append(db.Folders[orgID], folder) db.PutRule(context.Background(), rules...) diff --git a/pkg/services/ngalert/tests/util.go b/pkg/services/ngalert/tests/util.go index 4f4d6832c81..914aaf9d4cc 100644 --- a/pkg/services/ngalert/tests/util.go +++ b/pkg/services/ngalert/tests/util.go @@ -13,8 +13,9 @@ import ( "github.com/stretchr/testify/require" "github.com/grafana/grafana/pkg/api/routing" - busmock "github.com/grafana/grafana/pkg/bus/mock" + "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/infra/log" + "github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/services/accesscontrol" acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" "github.com/grafana/grafana/pkg/services/annotations/annotationstest" @@ -87,7 +88,7 @@ func SetupTestEnv(tb testing.TB, baseInterval time.Duration) (*ngalert.AlertNG, features, folderPermissions, dashboardPermissions, ac, ) - bus := busmock.New() + bus := bus.ProvideBus(tracing.InitializeTracerForTest()) folderService := folderimpl.ProvideService(ac, bus, cfg, dashboardService, dashboardStore, features, folderPermissions, nil) ng, err := ngalert.ProvideService(