Dashboards: Refactor service to make it injectable by wire (#44588)

* Add providers to folder and dashboard services

* Refactor folder and dashboard services

* Move store implementation to its own file due wire cannot allow us to cast to SQLStore

* Add store in some places and more missing dependencies

* Bad merge fix

* Remove old functions from tests and few fixes

* Fix provisioning

* Remove store from http server and some test fixes

* Test fixes

* Fix dashboard and folder tests

* Fix library tests

* Fix provisioning tests

* Fix plugins manager tests

* Fix alert and org users tests

* Refactor service package and more test fixes

* Fix dashboard_test tets

* Fix api tests

* Some lint fixes

* Fix lint

* More lint :/

* Move dashboard integration tests to dashboards service and fix dependencies

* Lint + tests

* More integration tests fixes

* Lint

* Lint again

* Fix tests again and again anda again

* Update searchstore_test

* Fix goimports

* More go imports

* More imports fixes

* Fix lint

* Move UnprovisionDashboard function into dashboard service and remove bus

* Use search service instead of bus

* Fix test

* Fix go imports

* Use nil in tests
This commit is contained in:
Selene
2022-02-16 14:15:44 +01:00
committed by GitHub
parent 4393992775
commit d5b98772ed
66 changed files with 2377 additions and 1844 deletions
@@ -1,19 +1,16 @@
//go:build integration
// +build integration
// package search_test contains integration tests for search
package searchstore_test
import (
"context"
"testing"
"time"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/services/sqlstore/permissions"
"github.com/grafana/grafana/pkg/services/sqlstore/searchstore"
"github.com/grafana/grafana/pkg/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -171,11 +168,27 @@ func createDashboards(t *testing.T, db *sqlstore.SQLStore, startID, endID int, o
"version": 0
}`))
require.NoError(t, err)
dash, err := db.SaveDashboard(models.SaveDashboardCommand{
Dashboard: dashboard,
UserId: 1,
OrgId: orgID,
UpdatedAt: time.Now(),
var dash *models.Dashboard
err = db.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
dash = models.NewDashboardFromJson(dashboard)
dash.OrgId = orgID
dash.Uid = util.GenerateShortUID()
dash.CreatedBy = 1
dash.UpdatedBy = 1
_, err := sess.Insert(dash)
require.NoError(t, err)
tags := dash.GetTags()
if len(tags) > 0 {
for _, tag := range tags {
if _, err := sess.Insert(&sqlstore.DashboardTag{DashboardId: dash.Id, Term: tag}); err != nil {
return err
}
}
}
return nil
})
require.NoError(t, err)