Search: Move entity events to transaction (#52394)
This commit is contained in:
@@ -353,7 +353,7 @@ func setupHTTPServerWithCfgDb(t *testing.T, useFakeAccessControl, enableAccessCo
|
|||||||
|
|
||||||
license := &licensing.OSSLicensingService{}
|
license := &licensing.OSSLicensingService{}
|
||||||
routeRegister := routing.NewRouteRegister()
|
routeRegister := routing.NewRouteRegister()
|
||||||
dashboardsStore := dashboardsstore.ProvideDashboardStore(db)
|
dashboardsStore := dashboardsstore.ProvideDashboardStore(db, featuremgmt.WithFeatures())
|
||||||
|
|
||||||
var acmock *accesscontrolmock.Mock
|
var acmock *accesscontrolmock.Mock
|
||||||
var ac accesscontrol.AccessControl
|
var ac accesscontrol.AccessControl
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/guardian"
|
"github.com/grafana/grafana/pkg/services/guardian"
|
||||||
pref "github.com/grafana/grafana/pkg/services/preference"
|
pref "github.com/grafana/grafana/pkg/services/preference"
|
||||||
"github.com/grafana/grafana/pkg/services/star"
|
"github.com/grafana/grafana/pkg/services/star"
|
||||||
"github.com/grafana/grafana/pkg/services/store"
|
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
"github.com/grafana/grafana/pkg/web"
|
"github.com/grafana/grafana/pkg/web"
|
||||||
)
|
)
|
||||||
@@ -318,15 +317,6 @@ func (hs *HTTPServer) deleteDashboard(c *models.ReqContext) response.Response {
|
|||||||
return response.Error(500, "Failed to delete dashboard", err)
|
return response.Error(500, "Failed to delete dashboard", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if hs.entityEventsService != nil {
|
|
||||||
if err := hs.entityEventsService.SaveEvent(c.Req.Context(), store.SaveEventCmd{
|
|
||||||
EntityId: store.CreateDatabaseEntityId(dash.Uid, dash.OrgId, store.EntityTypeDashboard),
|
|
||||||
EventType: store.EntityEventTypeDelete,
|
|
||||||
}); err != nil {
|
|
||||||
hs.log.Warn("failed to save dashboard entity event", "uid", dash.Uid, "error", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if hs.Live != nil {
|
if hs.Live != nil {
|
||||||
err := hs.Live.GrafanaScope.Dashboards.DashboardDeleted(c.OrgId, c.ToUserDisplayDTO(), dash.Uid)
|
err := hs.Live.GrafanaScope.Dashboards.DashboardDeleted(c.OrgId, c.ToUserDisplayDTO(), dash.Uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -449,15 +439,6 @@ func (hs *HTTPServer) postDashboard(c *models.ReqContext, cmd models.SaveDashboa
|
|||||||
|
|
||||||
dashboard, err := hs.DashboardService.SaveDashboard(alerting.WithUAEnabled(ctx, hs.Cfg.UnifiedAlerting.IsEnabled()), dashItem, allowUiUpdate)
|
dashboard, err := hs.DashboardService.SaveDashboard(alerting.WithUAEnabled(ctx, hs.Cfg.UnifiedAlerting.IsEnabled()), dashItem, allowUiUpdate)
|
||||||
|
|
||||||
if dashboard != nil && hs.entityEventsService != nil {
|
|
||||||
if err := hs.entityEventsService.SaveEvent(ctx, store.SaveEventCmd{
|
|
||||||
EntityId: store.CreateDatabaseEntityId(dashboard.Uid, dashboard.OrgId, store.EntityTypeDashboard),
|
|
||||||
EventType: store.EntityEventTypeUpdate,
|
|
||||||
}); err != nil {
|
|
||||||
hs.log.Warn("failed to save dashboard entity event", "uid", dashboard.Uid, "error", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if hs.Live != nil {
|
if hs.Live != nil {
|
||||||
// Tell everyone listening that the dashboard changed
|
// Tell everyone listening that the dashboard changed
|
||||||
if dashboard == nil {
|
if dashboard == nil {
|
||||||
|
|||||||
@@ -927,7 +927,7 @@ func getDashboardShouldReturn200WithConfig(t *testing.T, sc *scenarioContext, pr
|
|||||||
|
|
||||||
if dashboardStore == nil {
|
if dashboardStore == nil {
|
||||||
sql := sqlstore.InitTestDB(t)
|
sql := sqlstore.InitTestDB(t)
|
||||||
dashboardStore = database.ProvideDashboardStore(sql)
|
dashboardStore = database.ProvideDashboardStore(sql, featuremgmt.WithFeatures())
|
||||||
}
|
}
|
||||||
|
|
||||||
libraryPanelsService := mockLibraryPanelService{}
|
libraryPanelsService := mockLibraryPanelService{}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/guardian"
|
"github.com/grafana/grafana/pkg/services/guardian"
|
||||||
"github.com/grafana/grafana/pkg/services/libraryelements"
|
"github.com/grafana/grafana/pkg/services/libraryelements"
|
||||||
"github.com/grafana/grafana/pkg/services/store"
|
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
"github.com/grafana/grafana/pkg/web"
|
"github.com/grafana/grafana/pkg/web"
|
||||||
)
|
)
|
||||||
@@ -123,14 +122,6 @@ func (hs *HTTPServer) CreateFolder(c *models.ReqContext) response.Response {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return apierrors.ToFolderErrorResponse(err)
|
return apierrors.ToFolderErrorResponse(err)
|
||||||
}
|
}
|
||||||
if hs.entityEventsService != nil {
|
|
||||||
if err := hs.entityEventsService.SaveEvent(c.Req.Context(), store.SaveEventCmd{
|
|
||||||
EntityId: store.CreateDatabaseEntityId(folder.Uid, c.OrgId, store.EntityTypeFolder),
|
|
||||||
EventType: store.EntityEventTypeCreate,
|
|
||||||
}); err != nil {
|
|
||||||
hs.log.Warn("failed to save folder entity event", "uid", folder.Uid, "error", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g := guardian.New(c.Req.Context(), folder.Id, c.OrgId, c.SignedInUser)
|
g := guardian.New(c.Req.Context(), folder.Id, c.OrgId, c.SignedInUser)
|
||||||
return response.JSON(http.StatusOK, hs.toFolderDto(c, g, folder))
|
return response.JSON(http.StatusOK, hs.toFolderDto(c, g, folder))
|
||||||
@@ -157,15 +148,6 @@ func (hs *HTTPServer) UpdateFolder(c *models.ReqContext) response.Response {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return apierrors.ToFolderErrorResponse(err)
|
return apierrors.ToFolderErrorResponse(err)
|
||||||
}
|
}
|
||||||
if hs.entityEventsService != nil {
|
|
||||||
if err := hs.entityEventsService.SaveEvent(c.Req.Context(), store.SaveEventCmd{
|
|
||||||
EntityId: store.CreateDatabaseEntityId(cmd.Uid, c.OrgId, store.EntityTypeFolder),
|
|
||||||
EventType: store.EntityEventTypeUpdate,
|
|
||||||
}); err != nil {
|
|
||||||
hs.log.Warn("failed to save folder entity event", "uid", cmd.Uid, "error", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g := guardian.New(c.Req.Context(), cmd.Result.Id, c.OrgId, c.SignedInUser)
|
g := guardian.New(c.Req.Context(), cmd.Result.Id, c.OrgId, c.SignedInUser)
|
||||||
return response.JSON(http.StatusOK, hs.toFolderDto(c, g, cmd.Result))
|
return response.JSON(http.StatusOK, hs.toFolderDto(c, g, cmd.Result))
|
||||||
}
|
}
|
||||||
@@ -197,14 +179,6 @@ func (hs *HTTPServer) DeleteFolder(c *models.ReqContext) response.Response { //
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return apierrors.ToFolderErrorResponse(err)
|
return apierrors.ToFolderErrorResponse(err)
|
||||||
}
|
}
|
||||||
if hs.entityEventsService != nil {
|
|
||||||
if err := hs.entityEventsService.SaveEvent(c.Req.Context(), store.SaveEventCmd{
|
|
||||||
EntityId: store.CreateDatabaseEntityId(uid, c.OrgId, store.EntityTypeFolder),
|
|
||||||
EventType: store.EntityEventTypeDelete,
|
|
||||||
}); err != nil {
|
|
||||||
hs.log.Warn("failed to save folder entity event", "uid", uid, "error", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.JSON(http.StatusOK, util.DynMap{
|
return response.JSON(http.StatusOK, util.DynMap{
|
||||||
"title": f.Title,
|
"title": f.Title,
|
||||||
|
|||||||
@@ -165,7 +165,6 @@ type HTTPServer struct {
|
|||||||
AvatarCacheServer *avatar.AvatarCacheServer
|
AvatarCacheServer *avatar.AvatarCacheServer
|
||||||
preferenceService pref.Service
|
preferenceService pref.Service
|
||||||
Csrf csrf.Service
|
Csrf csrf.Service
|
||||||
entityEventsService store.EntityEventsService
|
|
||||||
folderPermissionsService accesscontrol.FolderPermissionsService
|
folderPermissionsService accesscontrol.FolderPermissionsService
|
||||||
dashboardPermissionsService accesscontrol.DashboardPermissionsService
|
dashboardPermissionsService accesscontrol.DashboardPermissionsService
|
||||||
dashboardVersionService dashver.Service
|
dashboardVersionService dashver.Service
|
||||||
@@ -207,7 +206,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
|||||||
dashboardProvisioningService dashboards.DashboardProvisioningService, folderService dashboards.FolderService,
|
dashboardProvisioningService dashboards.DashboardProvisioningService, folderService dashboards.FolderService,
|
||||||
datasourcePermissionsService permissions.DatasourcePermissionsService, alertNotificationService *alerting.AlertNotificationService,
|
datasourcePermissionsService permissions.DatasourcePermissionsService, alertNotificationService *alerting.AlertNotificationService,
|
||||||
dashboardsnapshotsService dashboardsnapshots.Service, commentsService *comments.Service, pluginSettings *pluginSettings.Service,
|
dashboardsnapshotsService dashboardsnapshots.Service, commentsService *comments.Service, pluginSettings *pluginSettings.Service,
|
||||||
avatarCacheServer *avatar.AvatarCacheServer, preferenceService pref.Service, entityEventsService store.EntityEventsService,
|
avatarCacheServer *avatar.AvatarCacheServer, preferenceService pref.Service,
|
||||||
teamsPermissionsService accesscontrol.TeamPermissionsService, folderPermissionsService accesscontrol.FolderPermissionsService,
|
teamsPermissionsService accesscontrol.TeamPermissionsService, folderPermissionsService accesscontrol.FolderPermissionsService,
|
||||||
dashboardPermissionsService accesscontrol.DashboardPermissionsService, dashboardVersionService dashver.Service,
|
dashboardPermissionsService accesscontrol.DashboardPermissionsService, dashboardVersionService dashver.Service,
|
||||||
starService star.Service, csrfService csrf.Service, coremodelRegistry *registry.Generic, coremodelStaticRegistry *registry.Static,
|
starService star.Service, csrfService csrf.Service, coremodelRegistry *registry.Generic, coremodelStaticRegistry *registry.Static,
|
||||||
@@ -289,7 +288,6 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
|||||||
AvatarCacheServer: avatarCacheServer,
|
AvatarCacheServer: avatarCacheServer,
|
||||||
preferenceService: preferenceService,
|
preferenceService: preferenceService,
|
||||||
Csrf: csrfService,
|
Csrf: csrfService,
|
||||||
entityEventsService: entityEventsService,
|
|
||||||
folderPermissionsService: folderPermissionsService,
|
folderPermissionsService: folderPermissionsService,
|
||||||
dashboardPermissionsService: dashboardPermissionsService,
|
dashboardPermissionsService: dashboardPermissionsService,
|
||||||
dashboardVersionService: dashboardVersionService,
|
dashboardVersionService: dashboardVersionService,
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
|
|
||||||
setup := func(t *testing.T) {
|
setup := func(t *testing.T) {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore = ProvideDashboardStore(sqlStore)
|
dashboardStore = ProvideDashboardStore(sqlStore, testFeatureToggles)
|
||||||
currentUser = createUser(t, sqlStore, "viewer", "Viewer", false)
|
currentUser = createUser(t, sqlStore, "viewer", "Viewer", false)
|
||||||
savedFolder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
savedFolder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
||||||
childDash = insertTestDashboard(t, dashboardStore, "2 test dash", 1, savedFolder.Id, false, "prod", "webapp")
|
childDash = insertTestDashboard(t, dashboardStore, "2 test dash", 1, savedFolder.Id, false, "prod", "webapp")
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ import (
|
|||||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
|
dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
|
||||||
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/permissions"
|
"github.com/grafana/grafana/pkg/services/sqlstore/permissions"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/searchstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/searchstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/store"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,13 +27,18 @@ type DashboardStore struct {
|
|||||||
sqlStore *sqlstore.SQLStore
|
sqlStore *sqlstore.SQLStore
|
||||||
log log.Logger
|
log log.Logger
|
||||||
dialect migrator.Dialect
|
dialect migrator.Dialect
|
||||||
|
features featuremgmt.FeatureToggles
|
||||||
}
|
}
|
||||||
|
|
||||||
// DashboardStore implements the Store interface
|
// DashboardStore implements the Store interface
|
||||||
var _ dashboards.Store = (*DashboardStore)(nil)
|
var _ dashboards.Store = (*DashboardStore)(nil)
|
||||||
|
|
||||||
func ProvideDashboardStore(sqlStore *sqlstore.SQLStore) *DashboardStore {
|
func ProvideDashboardStore(sqlStore *sqlstore.SQLStore, features featuremgmt.FeatureToggles) *DashboardStore {
|
||||||
return &DashboardStore{sqlStore: sqlStore, log: log.New("dashboard-store"), dialect: sqlStore.Dialect}
|
return &DashboardStore{sqlStore: sqlStore, log: log.New("dashboard-store"), dialect: sqlStore.Dialect, features: features}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DashboardStore) emitEntityEvent() bool {
|
||||||
|
return d.features != nil && d.features.IsEnabled(featuremgmt.FlagPanelTitleSearch)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DashboardStore) ValidateDashboardBeforeSave(dashboard *models.Dashboard, overwrite bool) (bool, error) {
|
func (d *DashboardStore) ValidateDashboardBeforeSave(dashboard *models.Dashboard, overwrite bool) (bool, error) {
|
||||||
@@ -171,7 +178,7 @@ func (d *DashboardStore) GetProvisionedDashboardData(name string) ([]*models.Das
|
|||||||
|
|
||||||
func (d *DashboardStore) SaveProvisionedDashboard(cmd models.SaveDashboardCommand, provisioning *models.DashboardProvisioning) (*models.Dashboard, error) {
|
func (d *DashboardStore) SaveProvisionedDashboard(cmd models.SaveDashboardCommand, provisioning *models.DashboardProvisioning) (*models.Dashboard, error) {
|
||||||
err := d.sqlStore.WithTransactionalDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
err := d.sqlStore.WithTransactionalDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
||||||
if err := saveDashboard(sess, &cmd); err != nil {
|
if err := saveDashboard(sess, &cmd, d.emitEntityEvent()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +194,7 @@ func (d *DashboardStore) SaveProvisionedDashboard(cmd models.SaveDashboardComman
|
|||||||
|
|
||||||
func (d *DashboardStore) SaveDashboard(cmd models.SaveDashboardCommand) (*models.Dashboard, error) {
|
func (d *DashboardStore) SaveDashboard(cmd models.SaveDashboardCommand) (*models.Dashboard, error) {
|
||||||
err := d.sqlStore.WithTransactionalDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
err := d.sqlStore.WithTransactionalDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
||||||
return saveDashboard(sess, &cmd)
|
return saveDashboard(sess, &cmd, d.emitEntityEvent())
|
||||||
})
|
})
|
||||||
return cmd.Result, err
|
return cmd.Result, err
|
||||||
}
|
}
|
||||||
@@ -396,7 +403,7 @@ func getExistingDashboardByTitleAndFolder(sess *sqlstore.DBSession, dash *models
|
|||||||
return isParentFolderChanged, nil
|
return isParentFolderChanged, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveDashboard(sess *sqlstore.DBSession, cmd *models.SaveDashboardCommand) error {
|
func saveDashboard(sess *sqlstore.DBSession, cmd *models.SaveDashboardCommand, emitEntityEvent bool) error {
|
||||||
dash := cmd.GetDashboardModel()
|
dash := cmd.GetDashboardModel()
|
||||||
|
|
||||||
userId := cmd.UserId
|
userId := cmd.UserId
|
||||||
@@ -507,6 +514,12 @@ func saveDashboard(sess *sqlstore.DBSession, cmd *models.SaveDashboardCommand) e
|
|||||||
|
|
||||||
cmd.Result = dash
|
cmd.Result = dash
|
||||||
|
|
||||||
|
if emitEntityEvent {
|
||||||
|
_, err := sess.Insert(createEntityEvent(dash, store.EntityEventTypeUpdate))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -698,11 +711,11 @@ func (d *DashboardStore) GetDashboardsByPluginID(ctx context.Context, query *mod
|
|||||||
|
|
||||||
func (d *DashboardStore) DeleteDashboard(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
func (d *DashboardStore) DeleteDashboard(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
||||||
return d.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
return d.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||||
return d.deleteDashboard(cmd, sess)
|
return d.deleteDashboard(cmd, sess, d.emitEntityEvent())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DashboardStore) deleteDashboard(cmd *models.DeleteDashboardCommand, sess *sqlstore.DBSession) error {
|
func (d *DashboardStore) deleteDashboard(cmd *models.DeleteDashboardCommand, sess *sqlstore.DBSession, emitEntityEvent bool) error {
|
||||||
dashboard := models.Dashboard{Id: cmd.Id, OrgId: cmd.OrgId}
|
dashboard := models.Dashboard{Id: cmd.Id, OrgId: cmd.OrgId}
|
||||||
has, err := sess.Get(&dashboard)
|
has, err := sess.Get(&dashboard)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -812,9 +825,33 @@ func (d *DashboardStore) deleteDashboard(cmd *models.DeleteDashboardCommand, ses
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if emitEntityEvent {
|
||||||
|
_, err := sess.Insert(createEntityEvent(&dashboard, store.EntityEventTypeDelete))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createEntityEvent(dashboard *models.Dashboard, eventType store.EntityEventType) *store.EntityEvent {
|
||||||
|
var entityEvent *store.EntityEvent
|
||||||
|
if dashboard.IsFolder {
|
||||||
|
entityEvent = &store.EntityEvent{
|
||||||
|
EventType: eventType,
|
||||||
|
EntityId: store.CreateDatabaseEntityId(dashboard.Uid, dashboard.OrgId, store.EntityTypeFolder),
|
||||||
|
Created: time.Now().Unix(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
entityEvent = &store.EntityEvent{
|
||||||
|
EventType: eventType,
|
||||||
|
EntityId: store.CreateDatabaseEntityId(dashboard.Uid, dashboard.OrgId, store.EntityTypeDashboard),
|
||||||
|
Created: time.Now().Unix(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return entityEvent
|
||||||
|
}
|
||||||
|
|
||||||
func (d *DashboardStore) deleteAlertDefinition(dashboardId int64, sess *sqlstore.DBSession) error {
|
func (d *DashboardStore) deleteAlertDefinition(dashboardId int64, sess *sqlstore.DBSession) error {
|
||||||
alerts := make([]*models.Alert, 0)
|
alerts := make([]*models.Alert, 0)
|
||||||
if err := sess.Where("dashboard_id = ?", dashboardId).Find(&alerts); err != nil {
|
if err := sess.Where("dashboard_id = ?", dashboardId).Find(&alerts); err != nil {
|
||||||
|
|||||||
@@ -9,10 +9,13 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var testFeatureToggles = featuremgmt.WithFeatures(featuremgmt.FlagPanelTitleSearch)
|
||||||
|
|
||||||
func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
@@ -26,7 +29,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
sqlStore.Cfg.RBACEnabled = false
|
sqlStore.Cfg.RBACEnabled = false
|
||||||
dashboardStore = ProvideDashboardStore(sqlStore)
|
dashboardStore = ProvideDashboardStore(sqlStore, testFeatureToggles)
|
||||||
folder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
folder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
||||||
dashInRoot = insertTestDashboard(t, dashboardStore, "test dash 67", 1, 0, false, "prod", "webapp")
|
dashInRoot = insertTestDashboard(t, dashboardStore, "test dash 67", 1, 0, false, "prod", "webapp")
|
||||||
childDash = insertTestDashboard(t, dashboardStore, "test dash 23", 1, folder.Id, false, "prod", "webapp")
|
childDash = insertTestDashboard(t, dashboardStore, "test dash 23", 1, folder.Id, false, "prod", "webapp")
|
||||||
@@ -179,7 +182,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
|
|
||||||
setup2 := func() {
|
setup2 := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore)
|
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles)
|
||||||
folder1 = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod")
|
folder1 = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod")
|
||||||
folder2 = insertTestDashboard(t, dashboardStore, "2 test dash folder", 1, 0, true, "prod")
|
folder2 = insertTestDashboard(t, dashboardStore, "2 test dash folder", 1, 0, true, "prod")
|
||||||
dashInRoot = insertTestDashboard(t, dashboardStore, "test dash 67", 1, 0, false, "prod")
|
dashInRoot = insertTestDashboard(t, dashboardStore, "test dash 67", 1, 0, false, "prod")
|
||||||
@@ -284,7 +287,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
|
|
||||||
setup3 := func() {
|
setup3 := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore)
|
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles)
|
||||||
folder1 = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod")
|
folder1 = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod")
|
||||||
folder2 = insertTestDashboard(t, dashboardStore, "2 test dash folder", 1, 0, true, "prod")
|
folder2 = insertTestDashboard(t, dashboardStore, "2 test dash folder", 1, 0, true, "prod")
|
||||||
insertTestDashboard(t, dashboardStore, "folder in another org", 2, 0, true, "prod")
|
insertTestDashboard(t, dashboardStore, "folder in another org", 2, 0, true, "prod")
|
||||||
@@ -466,7 +469,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
var sqlStore *sqlstore.SQLStore
|
var sqlStore *sqlstore.SQLStore
|
||||||
var folder1, folder2 *models.Dashboard
|
var folder1, folder2 *models.Dashboard
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore)
|
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles)
|
||||||
folder2 = insertTestDashboard(t, dashboardStore, "TEST", orgId, 0, true, "prod")
|
folder2 = insertTestDashboard(t, dashboardStore, "TEST", orgId, 0, true, "prod")
|
||||||
_ = insertTestDashboard(t, dashboardStore, title, orgId, folder2.Id, false, "prod")
|
_ = insertTestDashboard(t, dashboardStore, title, orgId, folder2.Id, false, "prod")
|
||||||
folder1 = insertTestDashboard(t, dashboardStore, title, orgId, 0, true, "prod")
|
folder1 = insertTestDashboard(t, dashboardStore, title, orgId, 0, true, "prod")
|
||||||
@@ -481,7 +484,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
t.Run("GetFolderByUID", func(t *testing.T) {
|
t.Run("GetFolderByUID", func(t *testing.T) {
|
||||||
var orgId int64 = 1
|
var orgId int64 = 1
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore)
|
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles)
|
||||||
folder := insertTestDashboard(t, dashboardStore, "TEST", orgId, 0, true, "prod")
|
folder := insertTestDashboard(t, dashboardStore, "TEST", orgId, 0, true, "prod")
|
||||||
dash := insertTestDashboard(t, dashboardStore, "Very Unique Name", orgId, folder.Id, false, "prod")
|
dash := insertTestDashboard(t, dashboardStore, "Very Unique Name", orgId, folder.Id, false, "prod")
|
||||||
|
|
||||||
@@ -505,7 +508,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
t.Run("GetFolderByID", func(t *testing.T) {
|
t.Run("GetFolderByID", func(t *testing.T) {
|
||||||
var orgId int64 = 1
|
var orgId int64 = 1
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore)
|
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles)
|
||||||
folder := insertTestDashboard(t, dashboardStore, "TEST", orgId, 0, true, "prod")
|
folder := insertTestDashboard(t, dashboardStore, "TEST", orgId, 0, true, "prod")
|
||||||
dash := insertTestDashboard(t, dashboardStore, "Very Unique Name", orgId, folder.Id, false, "prod")
|
dash := insertTestDashboard(t, dashboardStore, "Very Unique Name", orgId, folder.Id, false, "prod")
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore)
|
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles)
|
||||||
|
|
||||||
folderCmd := models.SaveDashboardCommand{
|
folderCmd := models.SaveDashboardCommand{
|
||||||
OrgId: 1,
|
OrgId: 1,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
|||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
starService = starimpl.ProvideService(sqlStore)
|
starService = starimpl.ProvideService(sqlStore)
|
||||||
dashboardStore = ProvideDashboardStore(sqlStore)
|
dashboardStore = ProvideDashboardStore(sqlStore, testFeatureToggles)
|
||||||
savedFolder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
savedFolder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
||||||
savedDash = insertTestDashboard(t, dashboardStore, "test dash 23", 1, savedFolder.Id, false, "prod", "webapp")
|
savedDash = insertTestDashboard(t, dashboardStore, "test dash 23", 1, savedFolder.Id, false, "prod", "webapp")
|
||||||
insertTestDashboard(t, dashboardStore, "test dash 45", 1, savedFolder.Id, false, "prod")
|
insertTestDashboard(t, dashboardStore, "test dash 45", 1, savedFolder.Id, false, "prod")
|
||||||
@@ -484,7 +484,7 @@ func TestIntegrationDashboardDataAccessGivenPluginWithImportedDashboards(t *test
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore)
|
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles)
|
||||||
pluginId := "test-app"
|
pluginId := "test-app"
|
||||||
|
|
||||||
appFolder := insertTestDashboardForPlugin(t, dashboardStore, "app-test", 1, 0, true, pluginId)
|
appFolder := insertTestDashboardForPlugin(t, dashboardStore, "app-test", 1, 0, true, pluginId)
|
||||||
@@ -506,7 +506,7 @@ func TestIntegrationDashboard_SortingOptions(t *testing.T) {
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore)
|
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles)
|
||||||
|
|
||||||
dashB := insertTestDashboard(t, dashboardStore, "Beta", 1, 0, false)
|
dashB := insertTestDashboard(t, dashboardStore, "Beta", 1, 0, false)
|
||||||
dashA := insertTestDashboard(t, dashboardStore, "Alfa", 1, 0, false)
|
dashA := insertTestDashboard(t, dashboardStore, "Alfa", 1, 0, false)
|
||||||
@@ -555,7 +555,7 @@ func TestIntegrationDashboard_Filter(t *testing.T) {
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore)
|
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles)
|
||||||
insertTestDashboard(t, dashboardStore, "Alfa", 1, 0, false)
|
insertTestDashboard(t, dashboardStore, "Alfa", 1, 0, false)
|
||||||
dashB := insertTestDashboard(t, dashboardStore, "Beta", 1, 0, false)
|
dashB := insertTestDashboard(t, dashboardStore, "Beta", 1, 0, false)
|
||||||
qNoFilter := &models.FindPersistedDashboardsQuery{
|
qNoFilter := &models.FindPersistedDashboardsQuery{
|
||||||
|
|||||||
@@ -814,7 +814,7 @@ func permissionScenario(t *testing.T, desc string, canSave bool, fn permissionSc
|
|||||||
|
|
||||||
t.Run(desc, func(t *testing.T) {
|
t.Run(desc, func(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore)
|
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
service := ProvideDashboardService(
|
service := ProvideDashboardService(
|
||||||
&setting.Cfg{}, dashboardStore, &dummyDashAlertExtractor{},
|
&setting.Cfg{}, dashboardStore, &dummyDashAlertExtractor{},
|
||||||
featuremgmt.WithFeatures(),
|
featuremgmt.WithFeatures(),
|
||||||
@@ -868,7 +868,7 @@ func callSaveWithResult(t *testing.T, cmd models.SaveDashboardCommand, sqlStore
|
|||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
dto := toSaveDashboardDto(cmd)
|
dto := toSaveDashboardDto(cmd)
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore)
|
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
||||||
service := ProvideDashboardService(
|
service := ProvideDashboardService(
|
||||||
@@ -886,7 +886,7 @@ func callSaveWithResult(t *testing.T, cmd models.SaveDashboardCommand, sqlStore
|
|||||||
|
|
||||||
func callSaveWithError(cmd models.SaveDashboardCommand, sqlStore *sqlstore.SQLStore) error {
|
func callSaveWithError(cmd models.SaveDashboardCommand, sqlStore *sqlstore.SQLStore) error {
|
||||||
dto := toSaveDashboardDto(cmd)
|
dto := toSaveDashboardDto(cmd)
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore)
|
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
||||||
service := ProvideDashboardService(
|
service := ProvideDashboardService(
|
||||||
@@ -922,7 +922,7 @@ func saveTestDashboard(t *testing.T, title string, orgID, folderID int64, sqlSto
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore)
|
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
||||||
service := ProvideDashboardService(
|
service := ProvideDashboardService(
|
||||||
@@ -959,7 +959,7 @@ func saveTestFolder(t *testing.T, title string, orgID int64, sqlStore *sqlstore.
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore)
|
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
||||||
service := ProvideDashboardService(
|
service := ProvideDashboardService(
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -587,7 +589,7 @@ func setupAccessControlGuardianTest(t *testing.T, uid string, permissions []acce
|
|||||||
toSave.SetUid(uid)
|
toSave.SetUid(uid)
|
||||||
|
|
||||||
// seed dashboard
|
// seed dashboard
|
||||||
dashStore := dashdb.ProvideDashboardStore(store)
|
dashStore := dashdb.ProvideDashboardStore(store, featuremgmt.WithFeatures())
|
||||||
dash, err := dashStore.SaveDashboard(models.SaveDashboardCommand{
|
dash, err := dashStore.SaveDashboard(models.SaveDashboardCommand{
|
||||||
Dashboard: toSave.Data,
|
Dashboard: toSave.Data,
|
||||||
UserId: 1,
|
UserId: 1,
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ func createDashboard(t *testing.T, sqlStore *sqlstore.SQLStore, user models.Sign
|
|||||||
Overwrite: false,
|
Overwrite: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore)
|
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
dashAlertExtractor := alerting.ProvideDashAlertExtractorService(nil, nil, nil)
|
dashAlertExtractor := alerting.ProvideDashAlertExtractorService(nil, nil, nil)
|
||||||
features := featuremgmt.WithFeatures()
|
features := featuremgmt.WithFeatures()
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
@@ -297,7 +297,7 @@ func createFolderWithACL(t *testing.T, sqlStore *sqlstore.SQLStore, title string
|
|||||||
ac := acmock.New()
|
ac := acmock.New()
|
||||||
folderPermissions := acmock.NewMockedPermissionsService()
|
folderPermissions := acmock.NewMockedPermissionsService()
|
||||||
dashboardPermissions := acmock.NewMockedPermissionsService()
|
dashboardPermissions := acmock.NewMockedPermissionsService()
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore)
|
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
|
|
||||||
d := dashboardservice.ProvideDashboardService(
|
d := dashboardservice.ProvideDashboardService(
|
||||||
cfg, dashboardStore, nil,
|
cfg, dashboardStore, nil,
|
||||||
@@ -401,7 +401,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
|||||||
orgID := int64(1)
|
orgID := int64(1)
|
||||||
role := models.ROLE_ADMIN
|
role := models.ROLE_ADMIN
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore)
|
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
features := featuremgmt.WithFeatures()
|
features := featuremgmt.WithFeatures()
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.IsFeatureToggleEnabled = features.IsEnabled
|
cfg.IsFeatureToggleEnabled = features.IsEnabled
|
||||||
|
|||||||
@@ -1374,7 +1374,7 @@ func createDashboard(t *testing.T, sqlStore *sqlstore.SQLStore, user *models.Sig
|
|||||||
Overwrite: false,
|
Overwrite: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore)
|
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
dashAlertService := alerting.ProvideDashAlertExtractorService(nil, nil, nil)
|
dashAlertService := alerting.ProvideDashAlertExtractorService(nil, nil, nil)
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
||||||
@@ -1399,7 +1399,7 @@ func createFolderWithACL(t *testing.T, sqlStore *sqlstore.SQLStore, title string
|
|||||||
features := featuremgmt.WithFeatures()
|
features := featuremgmt.WithFeatures()
|
||||||
folderPermissions := acmock.NewMockedPermissionsService()
|
folderPermissions := acmock.NewMockedPermissionsService()
|
||||||
dashboardPermissions := acmock.NewMockedPermissionsService()
|
dashboardPermissions := acmock.NewMockedPermissionsService()
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore)
|
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
d := dashboardservice.ProvideDashboardService(cfg, dashboardStore, nil, features, folderPermissions, dashboardPermissions, ac)
|
d := dashboardservice.ProvideDashboardService(cfg, dashboardStore, nil, features, folderPermissions, dashboardPermissions, ac)
|
||||||
s := dashboardservice.ProvideFolderService(cfg, d, dashboardStore, nil, features, folderPermissions, ac, busmock.New())
|
s := dashboardservice.ProvideFolderService(cfg, d, dashboardStore, nil, features, folderPermissions, ac, busmock.New())
|
||||||
|
|
||||||
@@ -1491,7 +1491,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
|||||||
orgID := int64(1)
|
orgID := int64(1)
|
||||||
role := models.ROLE_ADMIN
|
role := models.ROLE_ADMIN
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore)
|
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
|
|
||||||
features := featuremgmt.WithFeatures()
|
features := featuremgmt.WithFeatures()
|
||||||
ac := acmock.New()
|
ac := acmock.New()
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func SetupTestEnv(t *testing.T, baseInterval time.Duration) (*ngalert.AlertNG, *
|
|||||||
m := metrics.NewNGAlert(prometheus.NewRegistry())
|
m := metrics.NewNGAlert(prometheus.NewRegistry())
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
secretsService := secretsManager.SetupTestService(t, database.ProvideSecretsStore(sqlStore))
|
secretsService := secretsManager.SetupTestService(t, database.ProvideSecretsStore(sqlStore))
|
||||||
dashboardStore := databasestore.ProvideDashboardStore(sqlStore)
|
dashboardStore := databasestore.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
|
|
||||||
ac := acmock.New()
|
ac := acmock.New()
|
||||||
features := featuremgmt.WithFeatures()
|
features := featuremgmt.WithFeatures()
|
||||||
|
|||||||
@@ -531,7 +531,7 @@ func TestIntegrationUnauthenticatedUserCanGetPubdashPanelQueryData(t *testing.T)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create dashboard
|
// create dashboard
|
||||||
dashboardStore := dashboardStore.ProvideDashboardStore(db)
|
dashboardStore := dashboardStore.ProvideDashboardStore(db, featuremgmt.WithFeatures())
|
||||||
dashboard, err := dashboardStore.SaveDashboard(saveDashboardCmd)
|
dashboard, err := dashboardStore.SaveDashboard(saveDashboardCmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func TestIntegrationGetDashboard(t *testing.T) {
|
|||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore)
|
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
publicdashboardStore = ProvideStore(sqlStore)
|
publicdashboardStore = ProvideStore(sqlStore)
|
||||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ func TestIntegrationGetPublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore)
|
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
publicdashboardStore = ProvideStore(sqlStore)
|
publicdashboardStore = ProvideStore(sqlStore)
|
||||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ func TestIntegrationGetPublicDashboardConfig(t *testing.T) {
|
|||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore)
|
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
publicdashboardStore = ProvideStore(sqlStore)
|
publicdashboardStore = ProvideStore(sqlStore)
|
||||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||||
}
|
}
|
||||||
@@ -227,7 +227,7 @@ func TestIntegrationSavePublicDashboardConfig(t *testing.T) {
|
|||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{FeatureFlags: []string{featuremgmt.FlagPublicDashboards}})
|
sqlStore = sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{FeatureFlags: []string{featuremgmt.FlagPublicDashboards}})
|
||||||
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore)
|
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
publicdashboardStore = ProvideStore(sqlStore)
|
publicdashboardStore = ProvideStore(sqlStore)
|
||||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||||
savedDashboard2 = insertTestDashboard(t, dashboardStore, "testDashie2", 1, 0, true)
|
savedDashboard2 = insertTestDashboard(t, dashboardStore, "testDashie2", 1, 0, true)
|
||||||
@@ -276,7 +276,7 @@ func TestIntegrationUpdatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{FeatureFlags: []string{featuremgmt.FlagPublicDashboards}})
|
sqlStore = sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{FeatureFlags: []string{featuremgmt.FlagPublicDashboards}})
|
||||||
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore)
|
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
publicdashboardStore = ProvideStore(sqlStore)
|
publicdashboardStore = ProvideStore(sqlStore)
|
||||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||||
anotherSavedDashboard = insertTestDashboard(t, dashboardStore, "test another Dashie", 1, 0, true)
|
anotherSavedDashboard = insertTestDashboard(t, dashboardStore, "test another Dashie", 1, 0, true)
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
@@ -118,7 +120,7 @@ func TestGetPublicDashboard(t *testing.T) {
|
|||||||
func TestSavePublicDashboard(t *testing.T) {
|
func TestSavePublicDashboard(t *testing.T) {
|
||||||
t.Run("Saving public dashboard", func(t *testing.T) {
|
t.Run("Saving public dashboard", func(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore)
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
||||||
|
|
||||||
@@ -162,7 +164,7 @@ func TestSavePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Validate pubdash has default time setting value", func(t *testing.T) {
|
t.Run("Validate pubdash has default time setting value", func(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore)
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
||||||
|
|
||||||
@@ -192,7 +194,7 @@ func TestSavePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Validate pubdash whose dashboard has template variables returns error", func(t *testing.T) {
|
t.Run("Validate pubdash whose dashboard has template variables returns error", func(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore)
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
templateVars := make([]map[string]interface{}, 1)
|
templateVars := make([]map[string]interface{}, 1)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, templateVars)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, templateVars)
|
||||||
@@ -221,7 +223,7 @@ func TestSavePublicDashboard(t *testing.T) {
|
|||||||
func TestUpdatePublicDashboard(t *testing.T) {
|
func TestUpdatePublicDashboard(t *testing.T) {
|
||||||
t.Run("Updating public dashboard", func(t *testing.T) {
|
t.Run("Updating public dashboard", func(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore)
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
||||||
|
|
||||||
@@ -288,7 +290,7 @@ func TestUpdatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Updating set empty time settings", func(t *testing.T) {
|
t.Run("Updating set empty time settings", func(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore)
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
||||||
|
|
||||||
@@ -347,7 +349,7 @@ func TestUpdatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
func TestBuildAnonymousUser(t *testing.T) {
|
func TestBuildAnonymousUser(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore)
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
service := &PublicDashboardServiceImpl{
|
service := &PublicDashboardServiceImpl{
|
||||||
@@ -368,7 +370,7 @@ func TestBuildAnonymousUser(t *testing.T) {
|
|||||||
|
|
||||||
func TestBuildPublicDashboardMetricRequest(t *testing.T) {
|
func TestBuildPublicDashboardMetricRequest(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore)
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures())
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
|
|
||||||
publicDashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
publicDashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ type dashboardLoader interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type eventStore interface {
|
type eventStore interface {
|
||||||
OnEvent(handler store.EventHandler)
|
|
||||||
GetLastEvent(ctx context.Context) (*store.EntityEvent, error)
|
GetLastEvent(ctx context.Context) (*store.EntityEvent, error)
|
||||||
GetAllEventsAfter(ctx context.Context, id int64) ([]*store.EntityEvent, error)
|
GetAllEventsAfter(ctx context.Context, id int64) ([]*store.EntityEvent, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
@@ -47,7 +49,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
dashboardStore := dashboardstore.ProvideDashboardStore(sql)
|
dashboardStore := dashboardstore.ProvideDashboardStore(sql, featuremgmt.WithFeatures())
|
||||||
|
|
||||||
testDashboard1 := models.SaveDashboardCommand{
|
testDashboard1 := models.SaveDashboardCommand{
|
||||||
UserId: 1,
|
UserId: 1,
|
||||||
@@ -388,7 +390,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
|||||||
}
|
}
|
||||||
sql := sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{})
|
sql := sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{})
|
||||||
repo := sqlstore.NewSQLAnnotationRepo(sql)
|
repo := sqlstore.NewSQLAnnotationRepo(sql)
|
||||||
dashboardStore := dashboardstore.ProvideDashboardStore(sql)
|
dashboardStore := dashboardstore.ProvideDashboardStore(sql, featuremgmt.WithFeatures())
|
||||||
|
|
||||||
testDashboard1 := models.SaveDashboardCommand{
|
testDashboard1 := models.SaveDashboardCommand{
|
||||||
UserId: 1,
|
UserId: 1,
|
||||||
|
|||||||
@@ -62,10 +62,8 @@ type EventHandler func(ctx context.Context, e *EntityEvent) error
|
|||||||
type EntityEventsService interface {
|
type EntityEventsService interface {
|
||||||
registry.BackgroundService
|
registry.BackgroundService
|
||||||
registry.CanBeDisabled
|
registry.CanBeDisabled
|
||||||
SaveEvent(ctx context.Context, cmd SaveEventCmd) error
|
|
||||||
GetLastEvent(ctx context.Context) (*EntityEvent, error)
|
GetLastEvent(ctx context.Context) (*EntityEvent, error)
|
||||||
GetAllEventsAfter(ctx context.Context, id int64) ([]*EntityEvent, error)
|
GetAllEventsAfter(ctx context.Context, id int64) ([]*EntityEvent, error)
|
||||||
OnEvent(handler EventHandler)
|
|
||||||
|
|
||||||
deleteEventsOlderThan(ctx context.Context, duration time.Duration) error
|
deleteEventsOlderThan(ctx context.Context, duration time.Duration) error
|
||||||
}
|
}
|
||||||
@@ -90,36 +88,6 @@ type entityEventService struct {
|
|||||||
eventHandlers []EventHandler
|
eventHandlers []EventHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *entityEventService) SaveEvent(ctx context.Context, cmd SaveEventCmd) error {
|
|
||||||
entityEvent := &EntityEvent{
|
|
||||||
EventType: cmd.EventType,
|
|
||||||
EntityId: cmd.EntityId,
|
|
||||||
Created: time.Now().Unix(),
|
|
||||||
}
|
|
||||||
err := e.sql.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
|
||||||
_, err := sess.Insert(entityEvent)
|
|
||||||
return err
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return e.broadcastEvent(ctx, entityEvent)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *entityEventService) broadcastEvent(ctx context.Context, event *EntityEvent) error {
|
|
||||||
for _, h := range e.eventHandlers {
|
|
||||||
err := h(ctx, event)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *entityEventService) OnEvent(handler EventHandler) {
|
|
||||||
e.eventHandlers = append(e.eventHandlers, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *entityEventService) GetLastEvent(ctx context.Context) (*EntityEvent, error) {
|
func (e *entityEventService) GetLastEvent(ctx context.Context) (*EntityEvent, error) {
|
||||||
var entityEvent *EntityEvent
|
var entityEvent *EntityEvent
|
||||||
err := e.sql.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
err := e.sql.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||||
@@ -187,13 +155,6 @@ func (d dummyEntityEventsService) IsDisabled() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d dummyEntityEventsService) SaveEvent(ctx context.Context, cmd SaveEventCmd) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d dummyEntityEventsService) OnEvent(handler EventHandler) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d dummyEntityEventsService) GetLastEvent(ctx context.Context) (*EntityEvent, error) {
|
func (d dummyEntityEventsService) GetLastEvent(ctx context.Context) (*EntityEvent, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,25 +10,34 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func saveEvent(ctx context.Context, sql *sqlstore.SQLStore, cmd SaveEventCmd) error {
|
||||||
|
entityEvent := &EntityEvent{
|
||||||
|
EventType: cmd.EventType,
|
||||||
|
EntityId: cmd.EntityId,
|
||||||
|
Created: time.Now().Unix(),
|
||||||
|
}
|
||||||
|
return sql.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||||
|
_, err := sess.Insert(entityEvent)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestIntegrationEntityEventsService(t *testing.T) {
|
func TestIntegrationEntityEventsService(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
var ctx context.Context
|
ctx := context.Background()
|
||||||
var service EntityEventsService
|
|
||||||
|
|
||||||
setup := func() {
|
setup := func() *entityEventService {
|
||||||
service = &entityEventService{
|
return &entityEventService{
|
||||||
sql: sqlstore.InitTestDB(t),
|
sql: sqlstore.InitTestDB(t),
|
||||||
log: log.New("entity-event-test"),
|
log: log.New("entity-event-test"),
|
||||||
}
|
}
|
||||||
ctx = context.Background()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("Should insert an entity event", func(t *testing.T) {
|
t.Run("Should insert an entity event", func(t *testing.T) {
|
||||||
setup()
|
service := setup()
|
||||||
|
err := saveEvent(ctx, service.sql, SaveEventCmd{
|
||||||
err := service.SaveEvent(ctx, SaveEventCmd{
|
|
||||||
EntityId: "database/dash/1",
|
EntityId: "database/dash/1",
|
||||||
EventType: EntityEventTypeCreate,
|
EventType: EntityEventTypeCreate,
|
||||||
})
|
})
|
||||||
@@ -36,28 +45,27 @@ func TestIntegrationEntityEventsService(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should retrieve nil entity if database is empty", func(t *testing.T) {
|
t.Run("Should retrieve nil entity if database is empty", func(t *testing.T) {
|
||||||
setup()
|
service := setup()
|
||||||
|
|
||||||
ev, err := service.GetLastEvent(ctx)
|
ev, err := service.GetLastEvent(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Nil(t, ev)
|
require.Nil(t, ev)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should retrieve last entity event", func(t *testing.T) {
|
t.Run("Should retrieve last entity event", func(t *testing.T) {
|
||||||
setup()
|
service := setup()
|
||||||
lastEventEntityId := "database/dash/1"
|
lastEventEntityId := "database/dash/1"
|
||||||
|
|
||||||
err := service.SaveEvent(ctx, SaveEventCmd{
|
err := saveEvent(ctx, service.sql, SaveEventCmd{
|
||||||
EntityId: "database/dash/3",
|
EntityId: "database/dash/3",
|
||||||
EventType: EntityEventTypeCreate,
|
EventType: EntityEventTypeCreate,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = service.SaveEvent(ctx, SaveEventCmd{
|
err = saveEvent(ctx, service.sql, SaveEventCmd{
|
||||||
EntityId: "database/dash/2",
|
EntityId: "database/dash/2",
|
||||||
EventType: EntityEventTypeCreate,
|
EventType: EntityEventTypeCreate,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = service.SaveEvent(ctx, SaveEventCmd{
|
err = saveEvent(ctx, service.sql, SaveEventCmd{
|
||||||
EntityId: lastEventEntityId,
|
EntityId: lastEventEntityId,
|
||||||
EventType: EntityEventTypeCreate,
|
EventType: EntityEventTypeCreate,
|
||||||
})
|
})
|
||||||
@@ -69,10 +77,10 @@ func TestIntegrationEntityEventsService(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should retrieve sorted events after an id", func(t *testing.T) {
|
t.Run("Should retrieve sorted events after an id", func(t *testing.T) {
|
||||||
setup()
|
service := setup()
|
||||||
lastEventEntityId := "database/dash/1"
|
lastEventEntityId := "database/dash/1"
|
||||||
|
|
||||||
err := service.SaveEvent(ctx, SaveEventCmd{
|
err := saveEvent(ctx, service.sql, SaveEventCmd{
|
||||||
EntityId: "database/dash/3",
|
EntityId: "database/dash/3",
|
||||||
EventType: EntityEventTypeCreate,
|
EventType: EntityEventTypeCreate,
|
||||||
})
|
})
|
||||||
@@ -81,12 +89,12 @@ func TestIntegrationEntityEventsService(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
firstEvId := firstEv.Id
|
firstEvId := firstEv.Id
|
||||||
|
|
||||||
err = service.SaveEvent(ctx, SaveEventCmd{
|
err = saveEvent(ctx, service.sql, SaveEventCmd{
|
||||||
EntityId: "database/dash/2",
|
EntityId: "database/dash/2",
|
||||||
EventType: EntityEventTypeCreate,
|
EventType: EntityEventTypeCreate,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = service.SaveEvent(ctx, SaveEventCmd{
|
err = saveEvent(ctx, service.sql, SaveEventCmd{
|
||||||
EntityId: lastEventEntityId,
|
EntityId: lastEventEntityId,
|
||||||
EventType: EntityEventTypeCreate,
|
EventType: EntityEventTypeCreate,
|
||||||
})
|
})
|
||||||
@@ -100,16 +108,16 @@ func TestIntegrationEntityEventsService(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should delete old events", func(t *testing.T) {
|
t.Run("Should delete old events", func(t *testing.T) {
|
||||||
setup()
|
service := setup()
|
||||||
_ = service.SaveEvent(ctx, SaveEventCmd{
|
_ = saveEvent(ctx, service.sql, SaveEventCmd{
|
||||||
EntityId: "database/dash/3",
|
EntityId: "database/dash/3",
|
||||||
EventType: EntityEventTypeCreate,
|
EventType: EntityEventTypeCreate,
|
||||||
})
|
})
|
||||||
_ = service.SaveEvent(ctx, SaveEventCmd{
|
_ = saveEvent(ctx, service.sql, SaveEventCmd{
|
||||||
EntityId: "database/dash/2",
|
EntityId: "database/dash/2",
|
||||||
EventType: EntityEventTypeCreate,
|
EventType: EntityEventTypeCreate,
|
||||||
})
|
})
|
||||||
_ = service.SaveEvent(ctx, SaveEventCmd{
|
_ = saveEvent(ctx, service.sql, SaveEventCmd{
|
||||||
EntityId: "database/dash/1",
|
EntityId: "database/dash/1",
|
||||||
EventType: EntityEventTypeCreate,
|
EventType: EntityEventTypeCreate,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user