remove datasource from sqlstore (#55288)

This commit is contained in:
ying-jeanne
2022-09-16 06:20:26 -04:00
committed by GitHub
parent 18f33871d1
commit e4741ce8d6
9 changed files with 26 additions and 842 deletions
@@ -8,8 +8,10 @@ import (
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/datasources"
dsService "github.com/grafana/grafana/pkg/services/datasources/service"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/services/user"
)
@@ -51,8 +53,8 @@ func benchmarkFilter(b *testing.B, numDs, numPermissions int) {
func setupFilterBenchmark(b *testing.B, numDs, numPermissions int) (*sqlstore.SQLStore, []accesscontrol.Permission) {
b.Helper()
store := sqlstore.InitTestDB(b)
sqlStore := sqlstore.InitTestDB(b)
store := dsService.CreateStore(sqlStore, log.New("accesscontrol.test"))
for i := 1; i <= numDs; i++ {
err := store.AddDataSource(context.Background(), &datasources.AddDataSourceCommand{
Name: fmt.Sprintf("ds:%d", i),
@@ -73,5 +75,5 @@ func setupFilterBenchmark(b *testing.B, numDs, numPermissions int) (*sqlstore.SQ
})
}
return store, permissions
return sqlStore, permissions
}
+4 -1
View File
@@ -8,8 +8,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/datasources"
dsService "github.com/grafana/grafana/pkg/services/datasources/service"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/services/user"
)
@@ -171,7 +173,8 @@ func TestFilter_Datasources(t *testing.T) {
// seed 10 data sources
for i := 1; i <= 10; i++ {
err := store.AddDataSource(context.Background(), &datasources.AddDataSourceCommand{Name: fmt.Sprintf("ds:%d", i), Uid: fmt.Sprintf("uid%d", i)})
dsStore := dsService.CreateStore(store, log.New("accesscontrol.test"))
err := dsStore.AddDataSource(context.Background(), &datasources.AddDataSourceCommand{Name: fmt.Sprintf("ds:%d", i), Uid: fmt.Sprintf("uid%d", i)})
require.NoError(t, err)
}
@@ -10,8 +10,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/datasources"
datasourcesService "github.com/grafana/grafana/pkg/services/datasources/service"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/services/user"
)
@@ -82,8 +84,8 @@ func GenerateDatasourcePermissions(b *testing.B, db *sqlstore.SQLStore, ac *stor
Access: datasources.DS_ACCESS_DIRECT,
Url: "http://test",
}
_ = db.AddDataSource(context.Background(), addDSCommand)
dsStore := datasourcesService.CreateStore(db, log.New("publicdashboards.test"))
_ = dsStore.AddDataSource(context.Background(), addDSCommand)
dataSources = append(dataSources, addDSCommand.Result.Id)
}