Chore: Remove global bus variable (#50765)

* Chore: Remove global bus variable

* fix bus in tests
This commit is contained in:
Serge Zaitsev
2022-06-14 16:07:41 +02:00
committed by GitHub
parent 99c8ce5ab9
commit 0b55c41d05
15 changed files with 68 additions and 92 deletions

View File

@@ -5,14 +5,22 @@ import (
"testing"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func newBus(t *testing.T) bus.Bus {
t.Helper()
tracer, err := tracing.InitializeTracerForTest()
require.NoError(t, err)
return bus.ProvideBus(tracer)
}
func TestProvideService(t *testing.T) {
bus := bus.New()
bus := newBus(t)
t.Run("When invalid from_address in configuration", func(t *testing.T) {
cfg := createSmtpConfig()
@@ -32,7 +40,7 @@ func TestProvideService(t *testing.T) {
}
func TestSendEmailSync(t *testing.T) {
bus := bus.New()
bus := newBus(t)
t.Run("When sending emails synchronously", func(t *testing.T) {
ns, mailer := createSut(t, bus)
@@ -173,7 +181,7 @@ func TestSendEmailSync(t *testing.T) {
}
func TestSendEmailAsync(t *testing.T) {
bus := bus.New()
bus := newBus(t)
t.Run("When sending reset email password", func(t *testing.T) {
sut, _ := createSut(t, bus)

View File

@@ -5,7 +5,6 @@ import (
"io/ioutil"
"testing"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
@@ -20,7 +19,7 @@ func TestEmailIntegrationTest(t *testing.T) {
setting.BuildVersion = "4.0.0"
ns := &NotificationService{}
ns.Bus = bus.New()
ns.Bus = newBus(t)
ns.Cfg = setting.NewCfg()
ns.Cfg.Smtp.Enabled = true
ns.Cfg.Smtp.TemplatesPatterns = []string{"emails/*.html", "emails/*.txt"}