chore: remove sqlstore & mockstore dependencies from (most) packages (#57087)

* chore: add alias for InitTestDB and Session

Adds an alias for the sqlstore InitTestDB and Session, and updates tests using these to reduce dependencies on the sqlstore.Store.

* next pass of removing sqlstore imports
* last little bit
* remove mockstore where possible
This commit is contained in:
Kristin Laemmert
2022-10-19 09:02:15 -04:00
committed by GitHub
parent 5285d34cc0
commit 05709ce411
273 changed files with 1595 additions and 1491 deletions

View File

@@ -4,9 +4,9 @@ import (
"fmt"
"time"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/localcache"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore/db"
)
type Storage struct {
@@ -24,7 +24,7 @@ func getLiveMessageCacheKey(orgID int64, channel string) string {
func (s *Storage) SaveLiveMessage(query *models.SaveLiveMessageQuery) error {
// Come back to saving into database after evaluating database structure.
//err := s.store.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
//err := s.store.WithDbSession(context.Background(), func(sess *db.Session) error {
// params := []interface{}{query.OrgId, query.Channel, query.Data, time.Now()}
// upsertSQL := s.store.Dialect.UpsertSQL(
// "live_message",
@@ -48,7 +48,7 @@ func (s *Storage) GetLiveMessage(query *models.GetLiveMessageQuery) (models.Live
// Come back to saving into database after evaluating database structure.
//var msg models.LiveMessage
//var exists bool
//err := s.store.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
//err := s.store.WithDbSession(context.Background(), func(sess *db.Session) error {
// var err error
// exists, err = sess.Where("org_id=? AND channel=?", query.OrgId, query.Channel).Get(&msg)
// return err

View File

@@ -4,15 +4,15 @@ import (
"testing"
"time"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/localcache"
"github.com/grafana/grafana/pkg/services/live/database"
"github.com/grafana/grafana/pkg/services/sqlstore"
)
// SetupTestStorage initializes a storage to used by the integration tests.
// This is required to properly register and execute migrations.
func SetupTestStorage(t *testing.T) *database.Storage {
sqlStore := sqlstore.InitTestDB(t)
sqlStore := db.InitTestDB(t)
localCache := localcache.New(time.Hour, time.Hour)
return database.NewStorage(sqlStore, localCache)
}