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:
@@ -3,11 +3,11 @@ package starimpl
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
)
|
||||
|
||||
func TestIntegrationSQLxUserStarsDataAccess(t *testing.T) {
|
||||
testIntegrationUserStarsDataAccess(t, func(ss *sqlstore.SQLStore) store {
|
||||
testIntegrationUserStarsDataAccess(t, func(ss db.DB) store {
|
||||
return &sqlxStore{sess: ss.GetSqlxSession()}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package starimpl
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/services/star"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
@@ -4,19 +4,20 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/star"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/services/star"
|
||||
)
|
||||
|
||||
type getStore func(*sqlstore.SQLStore) store
|
||||
type getStore func(db.DB) store
|
||||
|
||||
func testIntegrationUserStarsDataAccess(t *testing.T, fn getStore) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
t.Run("Testing User Stars Data Access", func(t *testing.T) {
|
||||
ss := sqlstore.InitTestDB(t)
|
||||
ss := db.InitTestDB(t)
|
||||
starStore := fn(ss)
|
||||
|
||||
t.Run("Given saved star", func(t *testing.T) {
|
||||
|
||||
@@ -3,8 +3,7 @@ package starimpl
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/services/star"
|
||||
)
|
||||
|
||||
@@ -14,7 +13,7 @@ type sqlStore struct {
|
||||
|
||||
func (s *sqlStore) Get(ctx context.Context, query *star.IsStarredByUserQuery) (bool, error) {
|
||||
var isStarred bool
|
||||
err := s.db.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
err := s.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
rawSQL := "SELECT 1 from star where user_id=? and dashboard_id=?"
|
||||
results, err := sess.Query(rawSQL, query.UserID, query.DashboardID)
|
||||
|
||||
@@ -29,7 +28,7 @@ func (s *sqlStore) Get(ctx context.Context, query *star.IsStarredByUserQuery) (b
|
||||
}
|
||||
|
||||
func (s *sqlStore) Insert(ctx context.Context, cmd *star.StarDashboardCommand) error {
|
||||
return s.db.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
return s.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
entity := star.Star{
|
||||
UserID: cmd.UserID,
|
||||
DashboardID: cmd.DashboardID,
|
||||
@@ -41,7 +40,7 @@ func (s *sqlStore) Insert(ctx context.Context, cmd *star.StarDashboardCommand) e
|
||||
}
|
||||
|
||||
func (s *sqlStore) Delete(ctx context.Context, cmd *star.UnstarDashboardCommand) error {
|
||||
return s.db.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
return s.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
var rawSQL = "DELETE FROM star WHERE user_id=? and dashboard_id=?"
|
||||
_, err := sess.Exec(rawSQL, cmd.UserID, cmd.DashboardID)
|
||||
return err
|
||||
@@ -49,7 +48,7 @@ func (s *sqlStore) Delete(ctx context.Context, cmd *star.UnstarDashboardCommand)
|
||||
}
|
||||
|
||||
func (s *sqlStore) DeleteByUser(ctx context.Context, userID int64) error {
|
||||
return s.db.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
return s.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
var rawSQL = "DELETE FROM star WHERE user_id = ?"
|
||||
_, err := sess.Exec(rawSQL, userID)
|
||||
return err
|
||||
@@ -58,7 +57,7 @@ func (s *sqlStore) DeleteByUser(ctx context.Context, userID int64) error {
|
||||
|
||||
func (s *sqlStore) List(ctx context.Context, query *star.GetUserStarsQuery) (*star.GetUserStarsResult, error) {
|
||||
userStars := make(map[int64]bool)
|
||||
err := s.db.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
||||
err := s.db.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
var stars = make([]star.Star, 0)
|
||||
err := dbSession.Where("user_id=?", query.UserID).Find(&stars)
|
||||
for _, star := range stars {
|
||||
|
||||
@@ -3,11 +3,11 @@ package starimpl
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
)
|
||||
|
||||
func TestIntegrationXormUserStarsDataAccess(t *testing.T) {
|
||||
testIntegrationUserStarsDataAccess(t, func(ss *sqlstore.SQLStore) store {
|
||||
testIntegrationUserStarsDataAccess(t, func(ss db.DB) store {
|
||||
return &sqlStore{db: ss}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user