Chore: Add context to org (#40685)

* Add context to org

* Rebase

* Fix rebase
This commit is contained in:
idafurjes
2021-11-03 11:31:56 +01:00
committed by GitHub
parent 91da1bbb79
commit 47f6bb3583
24 changed files with 120 additions and 112 deletions
@@ -1,6 +1,7 @@
package notifiers
import (
"context"
"fmt"
"os"
"testing"
@@ -40,7 +41,7 @@ func TestNotificationAsConfig(t *testing.T) {
for i := 1; i < 5; i++ {
orgCommand := models.CreateOrgCommand{Name: fmt.Sprintf("Main Org. %v", i)}
err := sqlstore.CreateOrg(&orgCommand)
err := sqlstore.CreateOrg(context.Background(), &orgCommand)
require.NoError(t, err)
}
@@ -65,7 +66,7 @@ func TestNotificationAsConfig(t *testing.T) {
log: log.New("test logger"),
}
cfg, err := cfgProvider.readConfig(correctProperties)
cfg, err := cfgProvider.readConfig(context.Background(), correctProperties)
_ = os.Unsetenv("TEST_VAR")
if err != nil {
t.Fatalf("readConfig return an error %v", err)
@@ -140,7 +141,7 @@ func TestNotificationAsConfig(t *testing.T) {
setup()
dc := newNotificationProvisioner(ossencryption.ProvideService(), logger)
err := dc.applyChanges(twoNotificationsConfig)
err := dc.applyChanges(context.Background(), twoNotificationsConfig)
if err != nil {
t.Fatalf("applyChanges return an error %v", err)
}
@@ -170,7 +171,7 @@ func TestNotificationAsConfig(t *testing.T) {
t.Run("should update one notification", func(t *testing.T) {
dc := newNotificationProvisioner(ossencryption.ProvideService(), logger)
err = dc.applyChanges(twoNotificationsConfig)
err = dc.applyChanges(context.Background(), twoNotificationsConfig)
if err != nil {
t.Fatalf("applyChanges return an error %v", err)
}
@@ -194,7 +195,7 @@ func TestNotificationAsConfig(t *testing.T) {
t.Run("Two notifications with is_default", func(t *testing.T) {
setup()
dc := newNotificationProvisioner(ossencryption.ProvideService(), logger)
err := dc.applyChanges(doubleNotificationsConfig)
err := dc.applyChanges(context.Background(), doubleNotificationsConfig)
t.Run("should both be inserted", func(t *testing.T) {
require.NoError(t, err)
notificationsQuery := models.GetAllAlertNotificationsQuery{OrgId: 1}
@@ -237,7 +238,7 @@ func TestNotificationAsConfig(t *testing.T) {
t.Run("should have two new notifications", func(t *testing.T) {
dc := newNotificationProvisioner(ossencryption.ProvideService(), logger)
err := dc.applyChanges(twoNotificationsConfig)
err := dc.applyChanges(context.Background(), twoNotificationsConfig)
if err != nil {
t.Fatalf("applyChanges return an error %v", err)
}
@@ -253,11 +254,11 @@ func TestNotificationAsConfig(t *testing.T) {
t.Run("Can read correct properties with orgName instead of orgId", func(t *testing.T) {
setup()
existingOrg1 := models.GetOrgByNameQuery{Name: "Main Org. 1"}
err := sqlstore.GetOrgByName(&existingOrg1)
err := sqlstore.GetOrgByName(context.Background(), &existingOrg1)
require.NoError(t, err)
require.NotNil(t, existingOrg1.Result)
existingOrg2 := models.GetOrgByNameQuery{Name: "Main Org. 2"}
err = sqlstore.GetOrgByName(&existingOrg2)
err = sqlstore.GetOrgByName(context.Background(), &existingOrg2)
require.NoError(t, err)
require.NotNil(t, existingOrg2.Result)
@@ -271,7 +272,7 @@ func TestNotificationAsConfig(t *testing.T) {
require.NoError(t, err)
dc := newNotificationProvisioner(ossencryption.ProvideService(), logger)
err = dc.applyChanges(correctPropertiesWithOrgName)
err = dc.applyChanges(context.Background(), correctPropertiesWithOrgName)
if err != nil {
t.Fatalf("applyChanges return an error %v", err)
}
@@ -290,7 +291,7 @@ func TestNotificationAsConfig(t *testing.T) {
t.Run("Config doesn't contain required field", func(t *testing.T) {
setup()
dc := newNotificationProvisioner(ossencryption.ProvideService(), logger)
err := dc.applyChanges(noRequiredFields)
err := dc.applyChanges(context.Background(), noRequiredFields)
require.NotNil(t, err)
errString := err.Error()
@@ -304,7 +305,7 @@ func TestNotificationAsConfig(t *testing.T) {
t.Run("should have not changed repo", func(t *testing.T) {
setup()
dc := newNotificationProvisioner(ossencryption.ProvideService(), logger)
err := dc.applyChanges(emptyFile)
err := dc.applyChanges(context.Background(), emptyFile)
if err != nil {
t.Fatalf("applyChanges return an error %v", err)
}
@@ -321,7 +322,7 @@ func TestNotificationAsConfig(t *testing.T) {
log: log.New("test logger"),
}
_, err := reader.readConfig(brokenYaml)
_, err := reader.readConfig(context.Background(), brokenYaml)
require.NotNil(t, err)
})
@@ -331,7 +332,7 @@ func TestNotificationAsConfig(t *testing.T) {
log: log.New("test logger"),
}
cfg, err := cfgProvider.readConfig(emptyFolder)
cfg, err := cfgProvider.readConfig(context.Background(), emptyFolder)
if err != nil {
t.Fatalf("readConfig return an error %v", err)
}
@@ -343,7 +344,7 @@ func TestNotificationAsConfig(t *testing.T) {
encryptionService: ossencryption.ProvideService(),
log: log.New("test logger"),
}
_, err := cfgProvider.readConfig(unknownNotifier)
_, err := cfgProvider.readConfig(context.Background(), unknownNotifier)
require.NotNil(t, err)
require.Equal(t, err.Error(), `unsupported notification type "nonexisting"`)
})
@@ -353,7 +354,7 @@ func TestNotificationAsConfig(t *testing.T) {
encryptionService: ossencryption.ProvideService(),
log: log.New("test logger"),
}
_, err := cfgProvider.readConfig(incorrectSettings)
_, err := cfgProvider.readConfig(context.Background(), incorrectSettings)
require.NotNil(t, err)
require.Equal(t, err.Error(), "alert validation error: token must be specified when using the Slack chat API")
})
@@ -362,7 +363,7 @@ func TestNotificationAsConfig(t *testing.T) {
func setupBusHandlers(sqlStore *sqlstore.SQLStore) {
bus.AddHandler("getOrg", func(q *models.GetOrgByNameQuery) error {
return sqlstore.GetOrgByName(q)
return sqlstore.GetOrgByName(context.Background(), q)
})
bus.AddHandler("getAlertNotifications", func(q *models.GetAlertNotificationsWithUidQuery) error {