mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove global bus variable (#50765)
* Chore: Remove global bus variable * fix bus in tests
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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"}
|
||||
|
||||
Reference in New Issue
Block a user