mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Co-authored-by: Alexander Zobnin <alexander.zobnin@grafana.com> Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com> Co-authored-by: Arve Knudsen <arve.knudsen@grafana.com> Co-authored-by: Marcus Efraimsson <marcus.efraimsson@grafana.com>
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package database
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/grafana/grafana/pkg/registry"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
// accessControlStoreTestImpl is a test store implementation which additionally executes a database migrations
|
|
type accessControlStoreTestImpl struct {
|
|
AccessControlStore
|
|
}
|
|
|
|
func (ac *accessControlStoreTestImpl) AddMigration(mg *migrator.Migrator) {
|
|
AddAccessControlMigrations(mg)
|
|
}
|
|
|
|
func setupTestEnv(t testing.TB) *accessControlStoreTestImpl {
|
|
t.Helper()
|
|
|
|
cfg := setting.NewCfg()
|
|
store := overrideDatabaseInRegistry(cfg)
|
|
sqlStore := sqlstore.InitTestDB(t)
|
|
store.SQLStore = sqlStore
|
|
|
|
err := store.Init()
|
|
require.NoError(t, err)
|
|
return &store
|
|
}
|
|
|
|
func overrideDatabaseInRegistry(cfg *setting.Cfg) accessControlStoreTestImpl {
|
|
store := accessControlStoreTestImpl{
|
|
AccessControlStore: AccessControlStore{
|
|
SQLStore: nil,
|
|
},
|
|
}
|
|
|
|
overrideServiceFunc := func(descriptor registry.Descriptor) (*registry.Descriptor, bool) {
|
|
if _, ok := descriptor.Instance.(*AccessControlStore); ok {
|
|
return ®istry.Descriptor{
|
|
Name: "Database",
|
|
Instance: &store,
|
|
InitPriority: descriptor.InitPriority,
|
|
}, true
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
registry.RegisterOverride(overrideServiceFunc)
|
|
|
|
return store
|
|
}
|