mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
coremodels: Always take runtime arg for NewBase() (#56677)
This commit is contained in:
parent
10a34a041c
commit
5641029a4a
@ -64,7 +64,7 @@ func TestGetHomeDashboard(t *testing.T) {
|
||||
SQLStore: mockstore.NewSQLStoreMock(),
|
||||
preferenceService: prefService,
|
||||
dashboardVersionService: dashboardVersionService,
|
||||
Coremodels: registry.NewBase(),
|
||||
Coremodels: registry.NewBase(nil),
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@ -148,7 +148,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
DashboardService: dashboardService,
|
||||
dashboardVersionService: fakeDashboardVersionService,
|
||||
Coremodels: registry.NewBase(),
|
||||
Coremodels: registry.NewBase(nil),
|
||||
}
|
||||
|
||||
setUp := func() {
|
||||
@ -270,7 +270,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
DashboardService: dashboardService,
|
||||
dashboardVersionService: fakeDashboardVersionService,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
Coremodels: registry.NewBase(),
|
||||
Coremodels: registry.NewBase(nil),
|
||||
}
|
||||
|
||||
setUp := func() {
|
||||
@ -913,7 +913,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
AccessControl: accesscontrolmock.New(),
|
||||
DashboardService: dashboardService,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
Coremodels: registry.NewBase(),
|
||||
Coremodels: registry.NewBase(nil),
|
||||
}
|
||||
hs.callGetDashboard(sc)
|
||||
|
||||
@ -968,7 +968,7 @@ func getDashboardShouldReturn200WithConfig(t *testing.T, sc *scenarioContext, pr
|
||||
),
|
||||
DashboardService: dashboardService,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
Coremodels: registry.NewBase(),
|
||||
Coremodels: registry.NewBase(nil),
|
||||
}
|
||||
|
||||
hs.callGetDashboard(sc)
|
||||
@ -1034,7 +1034,7 @@ func postDashboardScenario(t *testing.T, desc string, url string, routePattern s
|
||||
DashboardService: dashboardService,
|
||||
folderService: folderService,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
Coremodels: registry.NewBase(),
|
||||
Coremodels: registry.NewBase(nil),
|
||||
}
|
||||
|
||||
sc := setupScenarioContext(t, url)
|
||||
@ -1067,7 +1067,7 @@ func postDiffScenario(t *testing.T, desc string, url string, routePattern string
|
||||
SQLStore: sqlmock,
|
||||
dashboardVersionService: fakeDashboardVersionService,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
Coremodels: registry.NewBase(),
|
||||
Coremodels: registry.NewBase(nil),
|
||||
}
|
||||
|
||||
sc := setupScenarioContext(t, url)
|
||||
@ -1106,7 +1106,7 @@ func restoreDashboardVersionScenario(t *testing.T, desc string, url string, rout
|
||||
SQLStore: sqlStore,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
dashboardVersionService: fakeDashboardVersionService,
|
||||
Coremodels: registry.NewBase(),
|
||||
Coremodels: registry.NewBase(nil),
|
||||
}
|
||||
|
||||
sc := setupScenarioContext(t, url)
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestSchemaAssignability(t *testing.T) {
|
||||
reg := registry.NewBase()
|
||||
reg := registry.NewBase(nil)
|
||||
|
||||
for _, cm := range reg.All() {
|
||||
tcm := cm
|
||||
|
@ -14,34 +14,22 @@ var CoremodelSet = wire.NewSet(
|
||||
NewBase,
|
||||
)
|
||||
|
||||
// NewBase provides a registry of all coremodels, without any composition of
|
||||
// plugin-defined schemas.
|
||||
//
|
||||
// The returned registry will use Grafana's singleton [thema.Runtime],
|
||||
// returned from [cuectx.GrafanaThemaRuntime].
|
||||
func NewBase() *Base {
|
||||
return provideBase(nil)
|
||||
}
|
||||
|
||||
// NewBaseWithRuntime is the same as NewBase, but allows control over the
|
||||
// [thema.Runtime] used to initialize the underlying coremodels.
|
||||
//
|
||||
// Prefer NewBase unless you absolutely need this control.
|
||||
//
|
||||
// TODO it's OK to export this if it's ever actually needed
|
||||
func NewBaseWithRuntime(rt *thema.Runtime) *Base {
|
||||
return provideBase(rt)
|
||||
}
|
||||
|
||||
var (
|
||||
baseOnce sync.Once
|
||||
defaultBase *Base
|
||||
)
|
||||
|
||||
func provideBase(rt *thema.Runtime) *Base {
|
||||
if rt == nil {
|
||||
// NewBase provides a registry of all coremodels, without any composition of
|
||||
// plugin-defined schemas.
|
||||
//
|
||||
// All calling code within grafana/grafana is expected to use Grafana's
|
||||
// singleton [thema.Runtime], returned from [cuectx.GrafanaThemaRuntime]. If nil
|
||||
// is passed, the singleton will be used.
|
||||
func NewBase(rt *thema.Runtime) *Base {
|
||||
allrt := cuectx.GrafanaThemaRuntime()
|
||||
if rt == nil || rt == allrt {
|
||||
baseOnce.Do(func() {
|
||||
defaultBase = doProvideBase(cuectx.GrafanaThemaRuntime())
|
||||
defaultBase = doProvideBase(allrt)
|
||||
})
|
||||
return defaultBase
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user