mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove bus.Dispatch from provisioning services (#44989)
* make getordbyname a method * remove one dispatch from plugins provisioner * remove bus from the plugins provisioner, skip test for now * remove bus from datasource provisioning * resolve tests in notifier provisioning * remove bus from the dashboards provisioning service * fix missing struct field * fix getorgbyid method calls * pass org store into dashboard provisioner * fix test function prototype * fix tests * attempt to fix tests after the rebase * fix integration test * avoid using transaction * remove comments
This commit is contained in:
@@ -5,13 +5,16 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
func CheckOrgExists(ctx context.Context, orgID int64) error {
|
||||
type OrgStore interface {
|
||||
GetOrgById(context.Context, *models.GetOrgByIdQuery) error
|
||||
}
|
||||
|
||||
func CheckOrgExists(ctx context.Context, store OrgStore, orgID int64) error {
|
||||
query := models.GetOrgByIdQuery{Id: orgID}
|
||||
if err := bus.Dispatch(ctx, &query); err != nil {
|
||||
if err := store.GetOrgById(ctx, &query); err != nil {
|
||||
if errors.Is(err, models.ErrOrgNotFound) {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,32 +1 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCheckOrgExists(t *testing.T) {
|
||||
t.Run("with default org in database", func(t *testing.T) {
|
||||
sqlstore.InitTestDB(t)
|
||||
|
||||
defaultOrg := models.CreateOrgCommand{Name: "Main Org."}
|
||||
|
||||
err := sqlstore.CreateOrg(context.Background(), &defaultOrg)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("default org exists", func(t *testing.T) {
|
||||
err := CheckOrgExists(context.Background(), defaultOrg.Result.Id)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("other org doesn't exist", func(t *testing.T) {
|
||||
err := CheckOrgExists(context.Background(), defaultOrg.Result.Id+1)
|
||||
require.Equal(t, err, models.ErrOrgNotFound)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user