mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Add context to org (#40685)
* Add context to org * Rebase * Fix rebase
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
@@ -8,9 +9,9 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
func CheckOrgExists(orgID int64) error {
|
||||
func CheckOrgExists(ctx context.Context, orgID int64) error {
|
||||
query := models.GetOrgByIdQuery{Id: orgID}
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
if err := bus.DispatchCtx(ctx, &query); err != nil {
|
||||
if errors.Is(err, models.ErrOrgNotFound) {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
@@ -14,16 +15,16 @@ func TestCheckOrgExists(t *testing.T) {
|
||||
sqlstore.InitTestDB(t)
|
||||
|
||||
defaultOrg := models.CreateOrgCommand{Name: "Main Org."}
|
||||
err := sqlstore.CreateOrg(&defaultOrg)
|
||||
err := sqlstore.CreateOrg(context.Background(), &defaultOrg)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("default org exists", func(t *testing.T) {
|
||||
err := CheckOrgExists(defaultOrg.Result.Id)
|
||||
err := CheckOrgExists(context.Background(), defaultOrg.Result.Id)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("other org doesn't exist", func(t *testing.T) {
|
||||
err := CheckOrgExists(defaultOrg.Result.Id + 1)
|
||||
err := CheckOrgExists(context.Background(), defaultOrg.Result.Id+1)
|
||||
require.Equal(t, err, models.ErrOrgNotFound)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user