Replace AddHandler with AddHandlerCtx in tests (#42585)
This commit is contained in:
@@ -106,7 +106,7 @@ func TestDashboardFileReader(t *testing.T) {
|
||||
setup := func() {
|
||||
bus.ClearBusHandlers()
|
||||
fakeService = mockDashboardProvisioningService()
|
||||
bus.AddHandler("test", mockGetDashboardQuery)
|
||||
bus.AddHandlerCtx("test", mockGetDashboardQuery)
|
||||
cfg = &config{
|
||||
Name: "Default",
|
||||
Type: "file",
|
||||
@@ -637,7 +637,7 @@ func (s *fakeDashboardProvisioningService) GetProvisionedDashboardDataByDashboar
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func mockGetDashboardQuery(cmd *models.GetDashboardQuery) error {
|
||||
func mockGetDashboardQuery(ctx context.Context, cmd *models.GetDashboardQuery) error {
|
||||
for _, d := range fakeService.getDashboard {
|
||||
if d.Slug == cmd.Slug {
|
||||
cmd.Result = d
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestDuplicatesValidator(t *testing.T) {
|
||||
bus.ClearBusHandlers()
|
||||
fakeService = mockDashboardProvisioningService()
|
||||
|
||||
bus.AddHandler("test", mockGetDashboardQuery)
|
||||
bus.AddHandlerCtx("test", mockGetDashboardQuery)
|
||||
cfg := &config{
|
||||
Name: "Default",
|
||||
Type: "file",
|
||||
|
||||
@@ -32,11 +32,11 @@ func TestDatasourceAsConfig(t *testing.T) {
|
||||
setup := func() {
|
||||
fakeRepo = &fakeRepository{}
|
||||
bus.ClearBusHandlers()
|
||||
bus.AddHandler("test", mockDelete)
|
||||
bus.AddHandler("test", mockInsert)
|
||||
bus.AddHandler("test", mockUpdate)
|
||||
bus.AddHandler("test", mockGet)
|
||||
bus.AddHandler("test", mockGetOrg)
|
||||
bus.AddHandlerCtx("test", mockDelete)
|
||||
bus.AddHandlerCtx("test", mockInsert)
|
||||
bus.AddHandlerCtx("test", mockUpdate)
|
||||
bus.AddHandlerCtx("test", mockGet)
|
||||
bus.AddHandlerCtx("test", mockGetOrg)
|
||||
}
|
||||
|
||||
t.Run("apply default values when missing", func(t *testing.T) {
|
||||
@@ -280,22 +280,22 @@ type fakeRepository struct {
|
||||
loadAll []*models.DataSource
|
||||
}
|
||||
|
||||
func mockDelete(cmd *models.DeleteDataSourceCommand) error {
|
||||
func mockDelete(ctx context.Context, cmd *models.DeleteDataSourceCommand) error {
|
||||
fakeRepo.deleted = append(fakeRepo.deleted, cmd)
|
||||
return nil
|
||||
}
|
||||
|
||||
func mockUpdate(cmd *models.UpdateDataSourceCommand) error {
|
||||
func mockUpdate(ctx context.Context, cmd *models.UpdateDataSourceCommand) error {
|
||||
fakeRepo.updated = append(fakeRepo.updated, cmd)
|
||||
return nil
|
||||
}
|
||||
|
||||
func mockInsert(cmd *models.AddDataSourceCommand) error {
|
||||
func mockInsert(ctx context.Context, cmd *models.AddDataSourceCommand) error {
|
||||
fakeRepo.inserted = append(fakeRepo.inserted, cmd)
|
||||
return nil
|
||||
}
|
||||
|
||||
func mockGet(cmd *models.GetDataSourceQuery) error {
|
||||
func mockGet(ctx context.Context, cmd *models.GetDataSourceQuery) error {
|
||||
for _, v := range fakeRepo.loadAll {
|
||||
if cmd.Name == v.Name && cmd.OrgId == v.OrgId {
|
||||
cmd.Result = v
|
||||
@@ -306,6 +306,6 @@ func mockGet(cmd *models.GetDataSourceQuery) error {
|
||||
return models.ErrDataSourceNotFound
|
||||
}
|
||||
|
||||
func mockGetOrg(_ *models.GetOrgByIdQuery) error {
|
||||
func mockGetOrg(ctx context.Context, _ *models.GetOrgByIdQuery) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
@@ -20,7 +21,7 @@ func TestPluginProvisioner(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Should apply configurations", func(t *testing.T) {
|
||||
bus.AddHandler("test", func(query *models.GetOrgByNameQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetOrgByNameQuery) error {
|
||||
if query.Name == "Org 4" {
|
||||
query.Result = &models.Org{Id: 4}
|
||||
}
|
||||
@@ -28,7 +29,7 @@ func TestPluginProvisioner(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetPluginSettingByIdQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetPluginSettingByIdQuery) error {
|
||||
if query.PluginId == "test-plugin" && query.OrgId == 2 {
|
||||
query.Result = &models.PluginSetting{
|
||||
PluginVersion: "2.0.1",
|
||||
@@ -41,7 +42,7 @@ func TestPluginProvisioner(t *testing.T) {
|
||||
|
||||
sentCommands := []*models.UpdatePluginSettingCmd{}
|
||||
|
||||
bus.AddHandler("test", func(cmd *models.UpdatePluginSettingCmd) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpdatePluginSettingCmd) error {
|
||||
sentCommands = append(sentCommands, cmd)
|
||||
return nil
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user