coremodels: Combine static and generic registries (#53246)
* Stop generating non-dynamic registry code * Remove generic, errors, s/static/base/ * Sort during codegen, not runtime * Not a method call * Precisiate a comment * Remove generic registry, fix assignability test
This commit is contained in:
@@ -353,7 +353,7 @@ func (hs *HTTPServer) PostDashboard(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
if hs.Features.IsEnabled(featuremgmt.FlagValidateDashboardsOnSave) {
|
||||
cm := hs.CoremodelStaticRegistry.Dashboard()
|
||||
cm := hs.Coremodels.Dashboard()
|
||||
|
||||
// Ideally, coremodel validation calls would be integrated into the web
|
||||
// framework. But this does the job for now.
|
||||
|
||||
@@ -57,8 +57,8 @@ func TestGetHomeDashboard(t *testing.T) {
|
||||
SQLStore: mockstore.NewSQLStoreMock(),
|
||||
preferenceService: prefService,
|
||||
dashboardVersionService: dashboardVersionService,
|
||||
Coremodels: registry.NewBase(),
|
||||
}
|
||||
hs.CoremodelStaticRegistry, hs.CoremodelRegistry = setupDashboardCoremodel(t)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -141,8 +141,8 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
DashboardService: dashboardService,
|
||||
dashboardVersionService: fakeDashboardVersionService,
|
||||
Coremodels: registry.NewBase(),
|
||||
}
|
||||
hs.CoremodelStaticRegistry, hs.CoremodelRegistry = setupDashboardCoremodel(t)
|
||||
|
||||
setUp := func() {
|
||||
viewerRole := models.ROLE_VIEWER
|
||||
@@ -262,8 +262,8 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
DashboardService: dashboardService,
|
||||
dashboardVersionService: fakeDashboardVersionService,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
Coremodels: registry.NewBase(),
|
||||
}
|
||||
hs.CoremodelStaticRegistry, hs.CoremodelRegistry = setupDashboardCoremodel(t)
|
||||
|
||||
setUp := func() {
|
||||
origCanEdit := setting.ViewersCanEdit
|
||||
@@ -903,8 +903,8 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
AccessControl: accesscontrolmock.New(),
|
||||
DashboardService: dashboardService,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
Coremodels: registry.NewBase(),
|
||||
}
|
||||
hs.CoremodelStaticRegistry, hs.CoremodelRegistry = setupDashboardCoremodel(t)
|
||||
hs.callGetDashboard(sc)
|
||||
|
||||
assert.Equal(t, 200, sc.resp.Code)
|
||||
@@ -958,8 +958,8 @@ func getDashboardShouldReturn200WithConfig(t *testing.T, sc *scenarioContext, pr
|
||||
),
|
||||
DashboardService: dashboardService,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
Coremodels: registry.NewBase(),
|
||||
}
|
||||
hs.CoremodelStaticRegistry, hs.CoremodelRegistry = setupDashboardCoremodel(t)
|
||||
|
||||
hs.callGetDashboard(sc)
|
||||
|
||||
@@ -1024,8 +1024,8 @@ func postDashboardScenario(t *testing.T, desc string, url string, routePattern s
|
||||
DashboardService: dashboardService,
|
||||
folderService: folderService,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
Coremodels: registry.NewBase(),
|
||||
}
|
||||
hs.CoremodelStaticRegistry, hs.CoremodelRegistry = setupDashboardCoremodel(t)
|
||||
|
||||
sc := setupScenarioContext(t, url)
|
||||
sc.defaultHandler = routing.Wrap(func(c *models.ReqContext) response.Response {
|
||||
@@ -1057,8 +1057,8 @@ func postDiffScenario(t *testing.T, desc string, url string, routePattern string
|
||||
SQLStore: sqlmock,
|
||||
dashboardVersionService: fakeDashboardVersionService,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
Coremodels: registry.NewBase(),
|
||||
}
|
||||
hs.CoremodelStaticRegistry, hs.CoremodelRegistry = setupDashboardCoremodel(t)
|
||||
|
||||
sc := setupScenarioContext(t, url)
|
||||
sc.defaultHandler = routing.Wrap(func(c *models.ReqContext) response.Response {
|
||||
@@ -1096,8 +1096,8 @@ func restoreDashboardVersionScenario(t *testing.T, desc string, url string, rout
|
||||
SQLStore: sqlStore,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
dashboardVersionService: fakeDashboardVersionService,
|
||||
Coremodels: registry.NewBase(),
|
||||
}
|
||||
hs.CoremodelStaticRegistry, hs.CoremodelRegistry = setupDashboardCoremodel(t)
|
||||
|
||||
sc := setupScenarioContext(t, url)
|
||||
sc.sqlStore = sqlStore
|
||||
@@ -1121,16 +1121,6 @@ func restoreDashboardVersionScenario(t *testing.T, desc string, url string, rout
|
||||
})
|
||||
}
|
||||
|
||||
func setupDashboardCoremodel(t *testing.T) (*registry.Static, *registry.Generic) {
|
||||
// TODO abstract and generalize this further for wider reuse
|
||||
t.Helper()
|
||||
sreg, err := registry.ProvideStatic()
|
||||
require.NoError(t, err)
|
||||
greg, err := registry.ProvideGeneric()
|
||||
require.NoError(t, err)
|
||||
return sreg, greg
|
||||
}
|
||||
|
||||
func (sc *scenarioContext) ToJSON() *simplejson.Json {
|
||||
result := simplejson.New()
|
||||
err := json.NewDecoder(sc.resp.Body).Decode(result)
|
||||
|
||||
@@ -171,10 +171,9 @@ type HTTPServer struct {
|
||||
dashboardVersionService dashver.Service
|
||||
PublicDashboardsApi *publicdashboardsApi.Api
|
||||
starService star.Service
|
||||
Coremodels *registry.Base
|
||||
playlistService playlist.Service
|
||||
apiKeyService apikey.Service
|
||||
CoremodelRegistry *registry.Generic
|
||||
CoremodelStaticRegistry *registry.Static
|
||||
kvStore kvstore.KVStore
|
||||
secretsMigrator secrets.Migrator
|
||||
userService user.Service
|
||||
@@ -211,7 +210,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
||||
avatarCacheServer *avatar.AvatarCacheServer, preferenceService pref.Service,
|
||||
teamsPermissionsService accesscontrol.TeamPermissionsService, folderPermissionsService accesscontrol.FolderPermissionsService,
|
||||
dashboardPermissionsService accesscontrol.DashboardPermissionsService, dashboardVersionService dashver.Service,
|
||||
starService star.Service, csrfService csrf.Service, coremodelRegistry *registry.Generic, coremodelStaticRegistry *registry.Static,
|
||||
starService star.Service, csrfService csrf.Service, coremodels *registry.Base,
|
||||
playlistService playlist.Service, apiKeyService apikey.Service, kvStore kvstore.KVStore, secretsMigrator secrets.Migrator, remoteSecretsCheck secretsKV.UseRemoteSecretsPluginCheck,
|
||||
publicDashboardsApi *publicdashboardsApi.Api, userService user.Service) (*HTTPServer, error) {
|
||||
web.Env = cfg.Env
|
||||
@@ -294,10 +293,9 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
||||
dashboardPermissionsService: dashboardPermissionsService,
|
||||
dashboardVersionService: dashboardVersionService,
|
||||
starService: starService,
|
||||
Coremodels: coremodels,
|
||||
playlistService: playlistService,
|
||||
apiKeyService: apiKeyService,
|
||||
CoremodelRegistry: coremodelRegistry,
|
||||
CoremodelStaticRegistry: coremodelStaticRegistry,
|
||||
kvStore: kvStore,
|
||||
PublicDashboardsApi: publicDashboardsApi,
|
||||
secretsMigrator: secretsMigrator,
|
||||
|
||||
Reference in New Issue
Block a user