mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Replace sqlstore with db interface (#85366)
* replace sqlstore with db interface in a few packages * remove from stats * remove sqlstore in admin test * remove sqlstore from api plugin tests * fix another createUser * remove sqlstore in publicdashboards * remove sqlstore from orgs * clean up orguser test * more clean up in sso * clean up service accounts * further cleanup * more cleanup in accesscontrol * last cleanup in accesscontrol * clean up teams * more removals * split cfg from db in testenv * few remaining fixes * fix test with bus * pass cfg for testing inside db as an option * set query retries when no opts provided * revert golden test data * rebase and rollback
This commit is contained in:
@@ -13,17 +13,18 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
@@ -115,7 +116,7 @@ func TestApi_getDescription(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
service, _, _ := setupTestEnvironment(t, tt.options)
|
||||
service, _, _, _ := setupTestEnvironment(t, tt.options)
|
||||
server := setupTestServer(t, &user.SignedInUser{OrgID: 1, Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)}}, service)
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/access-control/%s/description", tt.options.Resource), nil)
|
||||
@@ -162,10 +163,10 @@ func TestApi_getPermissions(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
service, sql, _ := setupTestEnvironment(t, testOptions)
|
||||
service, sql, cfg, _ := setupTestEnvironment(t, testOptions)
|
||||
server := setupTestServer(t, &user.SignedInUser{OrgID: 1, Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)}}, service)
|
||||
|
||||
seedPermissions(t, tt.resourceID, sql, service)
|
||||
seedPermissions(t, tt.resourceID, sql, cfg, service)
|
||||
|
||||
permissions, recorder := getPermission(t, server, testOptions.Resource, tt.resourceID)
|
||||
assert.Equal(t, tt.expectedStatus, recorder.Code)
|
||||
@@ -239,7 +240,7 @@ func TestApi_setBuiltinRolePermission(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
service, _, _ := setupTestEnvironment(t, testOptions)
|
||||
service, _, _, _ := setupTestEnvironment(t, testOptions)
|
||||
server := setupTestServer(t, &user.SignedInUser{OrgID: 1, Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)}}, service)
|
||||
|
||||
recorder := setPermission(t, server, testOptions.Resource, tt.resourceID, tt.permission, "builtInRoles", tt.builtInRole)
|
||||
@@ -317,7 +318,7 @@ func TestApi_setTeamPermission(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
service, _, teamSvc := setupTestEnvironment(t, testOptions)
|
||||
service, _, _, teamSvc := setupTestEnvironment(t, testOptions)
|
||||
server := setupTestServer(t, &user.SignedInUser{OrgID: 1, Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)}}, service)
|
||||
|
||||
// seed team
|
||||
@@ -400,16 +401,16 @@ func TestApi_setUserPermission(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
service, sql, _ := setupTestEnvironment(t, testOptions)
|
||||
service, sql, cfg, _ := setupTestEnvironment(t, testOptions)
|
||||
server := setupTestServer(t, &user.SignedInUser{
|
||||
OrgID: 1,
|
||||
Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)},
|
||||
}, service)
|
||||
|
||||
// seed user
|
||||
orgSvc, err := orgimpl.ProvideService(sql, sql.Cfg, quotatest.New(false, nil))
|
||||
orgSvc, err := orgimpl.ProvideService(sql, cfg, quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(sql, orgSvc, sql.Cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := userimpl.ProvideService(sql, orgSvc, cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
_, err = usrSvc.Create(context.Background(), &user.CreateUserCommand{Login: "test", OrgID: 1})
|
||||
require.NoError(t, err)
|
||||
@@ -505,19 +506,19 @@ func checkSeededPermissions(t *testing.T, permissions []resourcePermissionDTO) {
|
||||
}
|
||||
}
|
||||
|
||||
func seedPermissions(t *testing.T, resourceID string, sql *sqlstore.SQLStore, service *Service) {
|
||||
func seedPermissions(t *testing.T, resourceID string, sql db.DB, cfg *setting.Cfg, service *Service) {
|
||||
t.Helper()
|
||||
// seed team 1 with "Edit" permission on dashboard 1
|
||||
teamSvc, err := teamimpl.ProvideService(sql, sql.Cfg)
|
||||
teamSvc, err := teamimpl.ProvideService(sql, cfg)
|
||||
require.NoError(t, err)
|
||||
team, err := teamSvc.CreateTeam("test", "test@test.com", 1)
|
||||
require.NoError(t, err)
|
||||
_, err = service.SetTeamPermission(context.Background(), team.OrgID, team.ID, resourceID, "Edit")
|
||||
require.NoError(t, err)
|
||||
// seed user 1 with "View" permission on dashboard 1
|
||||
orgSvc, err := orgimpl.ProvideService(sql, sql.Cfg, quotatest.New(false, nil))
|
||||
orgSvc, err := orgimpl.ProvideService(sql, cfg, quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(sql, orgSvc, sql.Cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := userimpl.ProvideService(sql, orgSvc, cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
u, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{Login: "test", OrgID: 1})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/licensing/licensingtest"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
"github.com/grafana/grafana/pkg/services/team"
|
||||
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
||||
@@ -44,16 +43,16 @@ func TestService_SetUserPermission(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
service, sql, _ := setupTestEnvironment(t, Options{
|
||||
service, sql, cfg, _ := setupTestEnvironment(t, Options{
|
||||
Resource: "dashboards",
|
||||
Assignments: Assignments{Users: true},
|
||||
PermissionsToActions: nil,
|
||||
})
|
||||
|
||||
// seed user
|
||||
orgSvc, err := orgimpl.ProvideService(sql, sql.Cfg, quotatest.New(false, nil))
|
||||
orgSvc, err := orgimpl.ProvideService(sql, cfg, quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(sql, orgSvc, sql.Cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := userimpl.ProvideService(sql, orgSvc, cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
user, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{Login: "test", OrgID: 1})
|
||||
require.NoError(t, err)
|
||||
@@ -92,7 +91,7 @@ func TestService_SetTeamPermission(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
service, _, teamSvc := setupTestEnvironment(t, Options{
|
||||
service, _, _, teamSvc := setupTestEnvironment(t, Options{
|
||||
Resource: "dashboards",
|
||||
Assignments: Assignments{Teams: true},
|
||||
PermissionsToActions: nil,
|
||||
@@ -136,7 +135,7 @@ func TestService_SetBuiltInRolePermission(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
service, _, _ := setupTestEnvironment(t, Options{
|
||||
service, _, _, _ := setupTestEnvironment(t, Options{
|
||||
Resource: "dashboards",
|
||||
Assignments: Assignments{BuiltInRoles: true},
|
||||
PermissionsToActions: nil,
|
||||
@@ -209,12 +208,12 @@ func TestService_SetPermissions(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
service, sql, teamSvc := setupTestEnvironment(t, tt.options)
|
||||
service, sql, cfg, teamSvc := setupTestEnvironment(t, tt.options)
|
||||
|
||||
// seed user
|
||||
orgSvc, err := orgimpl.ProvideService(sql, sql.Cfg, quotatest.New(false, nil))
|
||||
orgSvc, err := orgimpl.ProvideService(sql, cfg, quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(sql, orgSvc, sql.Cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := userimpl.ProvideService(sql, orgSvc, cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
_, err = usrSvc.Create(context.Background(), &user.CreateUserCommand{Login: "user", OrgID: 1})
|
||||
require.NoError(t, err)
|
||||
@@ -232,7 +231,7 @@ func TestService_SetPermissions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func setupTestEnvironment(t *testing.T, ops Options) (*Service, *sqlstore.SQLStore, team.Service) {
|
||||
func setupTestEnvironment(t *testing.T, ops Options) (*Service, db.DB, *setting.Cfg, team.Service) {
|
||||
t.Helper()
|
||||
|
||||
sql := db.InitTestDB(t)
|
||||
@@ -251,5 +250,5 @@ func setupTestEnvironment(t *testing.T, ops Options) (*Service, *sqlstore.SQLSto
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return service, sql, teamSvc
|
||||
return service, sql, cfg, teamSvc
|
||||
}
|
||||
|
||||
@@ -10,17 +10,18 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"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/org/orgimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -74,12 +75,12 @@ func getDSPermissions(b *testing.B, store *store, dataSources []int64) {
|
||||
}
|
||||
|
||||
func setupResourceBenchmark(b *testing.B, dsNum, usersNum int) (*store, []int64) {
|
||||
ac, sql := setupTestEnv(b)
|
||||
dataSources := GenerateDatasourcePermissions(b, sql, ac, dsNum, usersNum, permissionsPerDs)
|
||||
ac, sql, cfg := setupTestEnv(b)
|
||||
dataSources := GenerateDatasourcePermissions(b, sql, cfg, ac, dsNum, usersNum, permissionsPerDs)
|
||||
return ac, dataSources
|
||||
}
|
||||
|
||||
func GenerateDatasourcePermissions(b *testing.B, db *sqlstore.SQLStore, ac *store, dsNum, usersNum, permissionsPerDs int) []int64 {
|
||||
func GenerateDatasourcePermissions(b *testing.B, db db.DB, cfg *setting.Cfg, ac *store, dsNum, usersNum, permissionsPerDs int) []int64 {
|
||||
dataSources := make([]int64, 0)
|
||||
for i := 0; i < dsNum; i++ {
|
||||
addDSCommand := &datasources.AddDataSourceCommand{
|
||||
@@ -94,7 +95,7 @@ func GenerateDatasourcePermissions(b *testing.B, db *sqlstore.SQLStore, ac *stor
|
||||
dataSources = append(dataSources, dataSource.ID)
|
||||
}
|
||||
|
||||
userIds, teamIds := generateTeamsAndUsers(b, db, usersNum)
|
||||
userIds, teamIds := generateTeamsAndUsers(b, db, cfg, usersNum)
|
||||
|
||||
for _, dsID := range dataSources {
|
||||
// Add DS permissions for the users
|
||||
@@ -137,15 +138,15 @@ func GenerateDatasourcePermissions(b *testing.B, db *sqlstore.SQLStore, ac *stor
|
||||
return dataSources
|
||||
}
|
||||
|
||||
func generateTeamsAndUsers(b *testing.B, db *sqlstore.SQLStore, users int) ([]int64, []int64) {
|
||||
teamSvc, err := teamimpl.ProvideService(db, db.Cfg)
|
||||
func generateTeamsAndUsers(b *testing.B, db db.DB, cfg *setting.Cfg, users int) ([]int64, []int64) {
|
||||
teamSvc, err := teamimpl.ProvideService(db, cfg)
|
||||
require.NoError(b, err)
|
||||
numberOfTeams := int(math.Ceil(float64(users) / UsersPerTeam))
|
||||
globalUserId := 0
|
||||
qs := quotatest.New(false, nil)
|
||||
orgSvc, err := orgimpl.ProvideService(db, db.Cfg, qs)
|
||||
orgSvc, err := orgimpl.ProvideService(db, cfg, qs)
|
||||
require.NoError(b, err)
|
||||
usrSvc, err := userimpl.ProvideService(db, orgSvc, db.Cfg, nil, nil, qs, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := userimpl.ProvideService(db, orgSvc, cfg, nil, nil, qs, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(b, err)
|
||||
userIds := make([]int64, 0)
|
||||
teamIds := make([]int64, 0)
|
||||
|
||||
@@ -17,10 +17,10 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||
)
|
||||
|
||||
@@ -88,7 +88,7 @@ func TestIntegrationStore_SetUserResourcePermission(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
store, _ := setupTestEnv(t)
|
||||
store, _, _ := setupTestEnv(t)
|
||||
|
||||
for _, s := range test.seeds {
|
||||
_, err := store.SetUserResourcePermission(context.Background(), test.orgID, accesscontrol.User{ID: test.userID}, s, nil)
|
||||
@@ -176,7 +176,7 @@ func TestIntegrationStore_SetTeamResourcePermission(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
store, _ := setupTestEnv(t)
|
||||
store, _, _ := setupTestEnv(t)
|
||||
|
||||
for _, s := range test.seeds {
|
||||
_, err := store.SetTeamResourcePermission(context.Background(), test.orgID, test.teamID, s, nil)
|
||||
@@ -264,7 +264,7 @@ func TestIntegrationStore_SetBuiltInResourcePermission(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
store, _ := setupTestEnv(t)
|
||||
store, _, _ := setupTestEnv(t)
|
||||
|
||||
for _, s := range test.seeds {
|
||||
_, err := store.SetBuiltInResourcePermission(context.Background(), test.orgID, test.builtInRole, s, nil)
|
||||
@@ -339,7 +339,7 @@ func TestIntegrationStore_SetResourcePermissions(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
store, _ := setupTestEnv(t)
|
||||
store, _, _ := setupTestEnv(t)
|
||||
|
||||
permissions, err := store.SetResourcePermissions(context.Background(), tt.orgID, tt.commands, ResourceHooks{})
|
||||
require.NoError(t, err)
|
||||
@@ -469,8 +469,8 @@ func TestIntegrationStore_GetResourcePermissions(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
store, sql := setupTestEnv(t)
|
||||
orgService, err := orgimpl.ProvideService(sql, sql.Cfg, quotatest.New(false, nil))
|
||||
store, sql, cfg := setupTestEnv(t)
|
||||
orgService, err := orgimpl.ProvideService(sql, cfg, quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
|
||||
err = sql.WithDbSession(context.Background(), func(sess *db.Session) error {
|
||||
@@ -508,7 +508,7 @@ func TestIntegrationStore_GetResourcePermissions(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
seedResourcePermissions(t, store, sql, orgService, tt.query.Actions, tt.query.Resource, tt.query.ResourceID, tt.query.ResourceAttribute, tt.numUsers, tt.numServiceAccounts)
|
||||
seedResourcePermissions(t, store, sql, cfg, orgService, tt.query.Actions, tt.query.Resource, tt.query.ResourceID, tt.query.ResourceAttribute, tt.numUsers, tt.numServiceAccounts)
|
||||
|
||||
tt.query.User = tt.user
|
||||
permissions, err := store.GetResourcePermissions(context.Background(), tt.user.OrgID, tt.query)
|
||||
@@ -519,7 +519,7 @@ func TestIntegrationStore_GetResourcePermissions(t *testing.T) {
|
||||
}
|
||||
|
||||
func seedResourcePermissions(
|
||||
t *testing.T, store *store, sql *sqlstore.SQLStore, orgService org.Service,
|
||||
t *testing.T, store *store, sql db.DB, cfg *setting.Cfg, orgService org.Service,
|
||||
actions []string, resource, resourceID, resourceAttribute string, numUsers, numServiceAccounts int,
|
||||
) {
|
||||
t.Helper()
|
||||
@@ -527,7 +527,7 @@ func seedResourcePermissions(
|
||||
orgID, err := orgService.GetOrCreate(context.Background(), "test")
|
||||
require.NoError(t, err)
|
||||
|
||||
usrSvc, err := userimpl.ProvideService(sql, orgService, sql.Cfg, nil, nil, quotatest.New(false, nil), supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := userimpl.ProvideService(sql, orgService, cfg, nil, nil, quotatest.New(false, nil), supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
|
||||
create := func(login string, isServiceAccount bool) {
|
||||
@@ -557,9 +557,9 @@ func seedResourcePermissions(
|
||||
}
|
||||
}
|
||||
|
||||
func setupTestEnv(t testing.TB) (*store, *sqlstore.SQLStore) {
|
||||
func setupTestEnv(t testing.TB) (*store, db.DB, *setting.Cfg) {
|
||||
sql := db.InitTestDB(t)
|
||||
return NewStore(sql, featuremgmt.WithFeatures()), sql
|
||||
return NewStore(sql, featuremgmt.WithFeatures()), sql, sql.Cfg
|
||||
}
|
||||
|
||||
func TestStore_IsInherited(t *testing.T) {
|
||||
@@ -681,7 +681,7 @@ func TestIntegrationStore_DeleteResourcePermissions(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
store, _ := setupTestEnv(t)
|
||||
store, _, _ := setupTestEnv(t)
|
||||
|
||||
_, err := store.SetResourcePermissions(context.Background(), 1, []SetResourcePermissionsCommand{
|
||||
{
|
||||
|
||||
@@ -28,8 +28,9 @@ func TestIntegrationAuthorize(t *testing.T) {
|
||||
}
|
||||
|
||||
sql := db.InitTestDB(t)
|
||||
cfg := sql.Cfg
|
||||
|
||||
dash1 := testutil.CreateDashboard(t, sql, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
dash1 := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
UserID: 1,
|
||||
OrgID: 1,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
@@ -37,7 +38,7 @@ func TestIntegrationAuthorize(t *testing.T) {
|
||||
}),
|
||||
})
|
||||
|
||||
dash2 := testutil.CreateDashboard(t, sql, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
dash2 := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
UserID: 1,
|
||||
OrgID: 1,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/folder/folderimpl"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
@@ -51,7 +50,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
||||
|
||||
repo := ProvideService(sql, cfg, features, tagService)
|
||||
|
||||
dashboard1 := testutil.CreateDashboard(t, sql, features, dashboards.SaveDashboardCommand{
|
||||
dashboard1 := testutil.CreateDashboard(t, sql, cfg, features, dashboards.SaveDashboardCommand{
|
||||
UserID: 1,
|
||||
OrgID: 1,
|
||||
IsFolder: false,
|
||||
@@ -60,7 +59,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
||||
}),
|
||||
})
|
||||
|
||||
_ = testutil.CreateDashboard(t, sql, features, dashboards.SaveDashboardCommand{
|
||||
_ = testutil.CreateDashboard(t, sql, cfg, features, dashboards.SaveDashboardCommand{
|
||||
UserID: 1,
|
||||
OrgID: 1,
|
||||
IsFolder: false,
|
||||
@@ -209,7 +208,7 @@ func TestIntegrationAnnotationListingWithInheritedRBAC(t *testing.T) {
|
||||
allDashboards := make([]dashInfo, 0, folder.MaxNestedFolderDepth+1)
|
||||
annotationsTexts := make([]string, 0, folder.MaxNestedFolderDepth+1)
|
||||
|
||||
setupFolderStructure := func() *sqlstore.SQLStore {
|
||||
setupFolderStructure := func() db.DB {
|
||||
sql := db.InitTestDB(t)
|
||||
|
||||
// enable nested folders so that the folder table is populated for all the tests
|
||||
@@ -253,7 +252,7 @@ func TestIntegrationAnnotationListingWithInheritedRBAC(t *testing.T) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
dashboard := testutil.CreateDashboard(t, sql, features, dashboards.SaveDashboardCommand{
|
||||
dashboard := testutil.CreateDashboard(t, sql, cfg, features, dashboards.SaveDashboardCommand{
|
||||
UserID: usr.UserID,
|
||||
OrgID: orgID,
|
||||
IsFolder: false,
|
||||
|
||||
@@ -43,8 +43,9 @@ func TestIntegrationAlertStateHistoryStore(t *testing.T) {
|
||||
}
|
||||
|
||||
sql := db.InitTestDB(t)
|
||||
cfg := sql.Cfg
|
||||
|
||||
dashboard1 := testutil.CreateDashboard(t, sql, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
dashboard1 := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
UserID: 1,
|
||||
OrgID: 1,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
@@ -52,7 +53,7 @@ func TestIntegrationAlertStateHistoryStore(t *testing.T) {
|
||||
}),
|
||||
})
|
||||
|
||||
dashboard2 := testutil.CreateDashboard(t, sql, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
dashboard2 := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
UserID: 1,
|
||||
OrgID: 1,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
dashboard := testutil.CreateDashboard(t, sql, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
dashboard := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
UserID: 1,
|
||||
OrgID: 1,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
@@ -67,7 +67,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
}),
|
||||
})
|
||||
|
||||
dashboard2 := testutil.CreateDashboard(t, sql, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
dashboard2 := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||
UserID: 1,
|
||||
OrgID: 1,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
dashboardstore "github.com/grafana/grafana/pkg/services/dashboards/database"
|
||||
@@ -13,10 +14,11 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func SetupRBACRole(t *testing.T, db *sqlstore.SQLStore, user *user.SignedInUser) *accesscontrol.Role {
|
||||
func SetupRBACRole(t *testing.T, db db.DB, user *user.SignedInUser) *accesscontrol.Role {
|
||||
t.Helper()
|
||||
|
||||
var role *accesscontrol.Role
|
||||
@@ -49,7 +51,7 @@ func SetupRBACRole(t *testing.T, db *sqlstore.SQLStore, user *user.SignedInUser)
|
||||
return role
|
||||
}
|
||||
|
||||
func SetupRBACPermission(t *testing.T, db *sqlstore.SQLStore, role *accesscontrol.Role, user *user.SignedInUser) {
|
||||
func SetupRBACPermission(t *testing.T, db db.DB, role *accesscontrol.Role, user *user.SignedInUser) {
|
||||
t.Helper()
|
||||
|
||||
err := db.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
||||
@@ -76,14 +78,14 @@ func SetupRBACPermission(t *testing.T, db *sqlstore.SQLStore, role *accesscontro
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func CreateDashboard(t *testing.T, sql *sqlstore.SQLStore, features featuremgmt.FeatureToggles, cmd dashboards.SaveDashboardCommand) *dashboards.Dashboard {
|
||||
func CreateDashboard(t *testing.T, db db.DB, cfg *setting.Cfg, features featuremgmt.FeatureToggles, cmd dashboards.SaveDashboardCommand) *dashboards.Dashboard {
|
||||
t.Helper()
|
||||
|
||||
dashboardStore, err := dashboardstore.ProvideDashboardStore(
|
||||
sql,
|
||||
sql.Cfg,
|
||||
db,
|
||||
cfg,
|
||||
features,
|
||||
tagimpl.ProvideService(sql),
|
||||
tagimpl.ProvideService(db),
|
||||
quotatest.New(false, nil),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -2,22 +2,23 @@ package correlationstest
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||
"github.com/grafana/grafana/pkg/services/correlations"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
fakeDatasources "github.com/grafana/grafana/pkg/services/datasources/fakes"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
func New(sqlStore *sqlstore.SQLStore) *correlations.CorrelationsService {
|
||||
func New(db db.DB, cfg *setting.Cfg, bus bus.Bus) *correlations.CorrelationsService {
|
||||
ds := &fakeDatasources.FakeDataSourceService{
|
||||
DataSources: []*datasources.DataSource{
|
||||
{ID: 1, UID: "graphite", Type: datasources.DS_GRAPHITE},
|
||||
},
|
||||
}
|
||||
|
||||
correlationsSvc, _ := correlations.ProvideService(sqlStore, routing.NewRouteRegister(), ds, acimpl.ProvideAccessControl(setting.NewCfg()), sqlStore.Bus(), quotatest.New(false, nil), sqlStore.Cfg)
|
||||
correlationsSvc, _ := correlations.ProvideService(db, routing.NewRouteRegister(), ds, acimpl.ProvideAccessControl(setting.NewCfg()), bus, quotatest.New(false, nil), cfg)
|
||||
return correlationsSvc
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
var testFeatureToggles = featuremgmt.WithFeatures(featuremgmt.FlagPanelTitleSearch)
|
||||
@@ -40,16 +40,18 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
t.Run("Testing DB", func(t *testing.T) {
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var sqlStore db.DB
|
||||
var cfg *setting.Cfg
|
||||
var flder, dashInRoot, childDash *dashboards.Dashboard
|
||||
var currentUser *user.SignedInUser
|
||||
var dashboardStore dashboards.Store
|
||||
|
||||
setup := func() {
|
||||
sqlStore = db.InitTestDB(t)
|
||||
sql := db.InitTestDB(t)
|
||||
sqlStore, cfg = sql, sql.Cfg
|
||||
quotaService := quotatest.New(false, nil)
|
||||
var err error
|
||||
dashboardStore, err = ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err = ProvideDashboardStore(sqlStore, cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
flder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, "", true, "prod", "webapp")
|
||||
dashInRoot = insertTestDashboard(t, dashboardStore, "test dash 67", 1, 0, "", false, "prod", "webapp")
|
||||
@@ -138,16 +140,18 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Given two dashboard folders with one dashboard each and one dashboard in the root folder", func(t *testing.T) {
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var sqlStore db.DB
|
||||
var cfg *setting.Cfg
|
||||
var folder1, folder2, dashInRoot, childDash1, childDash2 *dashboards.Dashboard
|
||||
var rootFolderId int64 = 0
|
||||
var currentUser *user.SignedInUser
|
||||
|
||||
setup2 := func() {
|
||||
sqlStore = db.InitTestDB(t)
|
||||
sql := db.InitTestDB(t)
|
||||
sqlStore, cfg = sql, sql.Cfg
|
||||
quotaService := quotatest.New(false, nil)
|
||||
var err error
|
||||
dashboardStore, err = ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err = ProvideDashboardStore(sqlStore, cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
folder1 = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, "", true, "prod")
|
||||
folder2 = insertTestDashboard(t, dashboardStore, "2 test dash folder", 1, 0, "", true, "prod")
|
||||
@@ -239,7 +243,8 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
|
||||
// the maximux nested folder hierarchy starting from parent down to subfolders
|
||||
nestedFolders := make([]*folder.Folder, 0, folder.MaxNestedFolderDepth+1)
|
||||
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var sqlStore db.DB
|
||||
var cfg *setting.Cfg
|
||||
const (
|
||||
dashInRootTitle = "dashboard in root"
|
||||
dashInParentTitle = "dashboard in parent"
|
||||
@@ -248,26 +253,27 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
|
||||
var viewer *user.SignedInUser
|
||||
|
||||
setup := func() {
|
||||
sqlStore = db.InitTestDB(t)
|
||||
sql := db.InitTestDB(t)
|
||||
sqlStore, cfg = sql, sql.Cfg
|
||||
quotaService := quotatest.New(false, nil)
|
||||
|
||||
// enable nested folders so that the folder table is populated for all the tests
|
||||
features := featuremgmt.WithFeatures(featuremgmt.FlagNestedFolders)
|
||||
|
||||
var err error
|
||||
dashboardWriteStore, err := ProvideDashboardStore(sqlStore, sqlStore.Cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardWriteStore, err := ProvideDashboardStore(sqlStore, cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
|
||||
usr := createUser(t, sqlStore, "viewer", "Viewer", false)
|
||||
usr := createUser(t, sqlStore, cfg, "viewer", "Viewer", false)
|
||||
viewer = &user.SignedInUser{
|
||||
UserID: usr.ID,
|
||||
OrgID: usr.OrgID,
|
||||
OrgRole: org.RoleViewer,
|
||||
}
|
||||
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
|
||||
// create admin user in the same org
|
||||
@@ -295,7 +301,7 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
|
||||
guardian.New = origNewGuardian
|
||||
})
|
||||
|
||||
folderSvc := folderimpl.ProvideService(mock.New(), bus.ProvideBus(tracing.InitializeTracerForTest()), sqlStore.Cfg, dashboardWriteStore, folderimpl.ProvideDashboardFolderStore(sqlStore), sqlStore, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||
folderSvc := folderimpl.ProvideService(mock.New(), bus.ProvideBus(tracing.InitializeTracerForTest()), cfg, dashboardWriteStore, folderimpl.ProvideDashboardFolderStore(sqlStore), sqlStore, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||
|
||||
parentUID := ""
|
||||
for i := 0; ; i++ {
|
||||
@@ -397,7 +403,7 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
dashboardReadStore, err := ProvideDashboardStore(sqlStore, sqlStore.Cfg, tc.features, tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
dashboardReadStore, err := ProvideDashboardStore(sqlStore, cfg, tc.features, tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
|
||||
viewer.Permissions = map[int64]map[string][]string{viewer.OrgID: tc.permissions}
|
||||
@@ -436,16 +442,16 @@ func moveDashboard(t *testing.T, dashboardStore dashboards.Store, orgId int64, d
|
||||
return dash
|
||||
}
|
||||
|
||||
func createUser(t *testing.T, sqlStore *sqlstore.SQLStore, name string, role string, isAdmin bool) user.User {
|
||||
func createUser(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, name string, role string, isAdmin bool) user.User {
|
||||
t.Helper()
|
||||
sqlStore.Cfg.AutoAssignOrg = true
|
||||
sqlStore.Cfg.AutoAssignOrgId = 1
|
||||
sqlStore.Cfg.AutoAssignOrgRole = role
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = 1
|
||||
cfg.AutoAssignOrgRole = role
|
||||
|
||||
qs := quotaimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, qs)
|
||||
qs := quotaimpl.ProvideService(sqlStore, cfg)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, cfg, qs)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, qs, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, cfg, nil, nil, qs, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
|
||||
o, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: fmt.Sprintf("test org %d", time.Now().UnixNano())})
|
||||
|
||||
@@ -43,7 +43,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var sqlStore db.DB
|
||||
var cfg *setting.Cfg
|
||||
var savedFolder, savedDash, savedDash2 *dashboards.Dashboard
|
||||
var dashboardStore dashboards.Store
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/dashboards/database"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||
@@ -24,7 +23,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestIntegrationDashboardFolderStore(t *testing.T) {
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var sqlStore db.DB
|
||||
var cfg *setting.Cfg
|
||||
var dashboardStore dashboards.Store
|
||||
|
||||
@@ -39,7 +38,7 @@ func TestIntegrationDashboardFolderStore(t *testing.T) {
|
||||
setup()
|
||||
var orgId int64 = 1
|
||||
title := "Very Unique Name"
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var sqlStore db.DB
|
||||
var folder1, folder2 *dashboards.Dashboard
|
||||
sqlStore = db.InitTestDB(t)
|
||||
folderStore := ProvideDashboardFolderStore(sqlStore)
|
||||
|
||||
@@ -13,11 +13,13 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/services/folder"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
@@ -32,7 +34,7 @@ func TestIntegrationCreate(t *testing.T) {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
|
||||
orgID := CreateOrg(t, db)
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
|
||||
t.Run("creating a folder without providing a UID should fail", func(t *testing.T) {
|
||||
_, err := folderStore.Create(context.Background(), folder.CreateFolderCommand{
|
||||
@@ -152,7 +154,7 @@ func TestIntegrationDelete(t *testing.T) {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
|
||||
orgID := CreateOrg(t, db)
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
|
||||
/*
|
||||
t.Run("attempt to delete unknown folder should fail", func(t *testing.T) {
|
||||
@@ -199,7 +201,7 @@ func TestIntegrationUpdate(t *testing.T) {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
|
||||
orgID := CreateOrg(t, db)
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
|
||||
// create parent folder
|
||||
parent, err := folderStore.Create(context.Background(), folder.CreateFolderCommand{
|
||||
@@ -374,7 +376,7 @@ func TestIntegrationGet(t *testing.T) {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
|
||||
orgID := CreateOrg(t, db)
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
|
||||
// create folder
|
||||
uid1 := util.GenerateShortUID()
|
||||
@@ -491,7 +493,7 @@ func TestIntegrationGetParents(t *testing.T) {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
|
||||
orgID := CreateOrg(t, db)
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
|
||||
// create folder
|
||||
uid1 := util.GenerateShortUID()
|
||||
@@ -559,7 +561,7 @@ func TestIntegrationGetChildren(t *testing.T) {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
|
||||
orgID := CreateOrg(t, db)
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
|
||||
// create folder
|
||||
uid1 := util.GenerateShortUID()
|
||||
@@ -739,7 +741,7 @@ func TestIntegrationGetHeight(t *testing.T) {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
|
||||
orgID := CreateOrg(t, db)
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
|
||||
// create folder
|
||||
uid1 := util.GenerateShortUID()
|
||||
@@ -772,7 +774,7 @@ func TestIntegrationGetFolders(t *testing.T) {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
folderStore := ProvideStore(db, db.Cfg)
|
||||
|
||||
orgID := CreateOrg(t, db)
|
||||
orgID := CreateOrg(t, db, db.Cfg)
|
||||
|
||||
// create folders
|
||||
uids := make([]string, 0)
|
||||
@@ -886,10 +888,10 @@ func TestIntegrationGetFolders(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func CreateOrg(t *testing.T, db *sqlstore.SQLStore) int64 {
|
||||
func CreateOrg(t *testing.T, db db.DB, cfg *setting.Cfg) int64 {
|
||||
t.Helper()
|
||||
|
||||
orgService, err := orgimpl.ProvideService(db, db.Cfg, quotatest.New(false, nil))
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
orgID, err := orgService.GetOrCreate(context.Background(), "test-org")
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/folder/folderimpl"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/testutil"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -867,7 +866,7 @@ func createFolder(t *testing.T, store *DBstore, uid, title string, orgID int64,
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func setupFolderService(t *testing.T, sqlStore *sqlstore.SQLStore, cfg *setting.Cfg, features featuremgmt.FeatureToggles) folder.Service {
|
||||
func setupFolderService(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, features featuremgmt.FeatureToggles) folder.Service {
|
||||
tracer := tracing.InitializeTracerForTest()
|
||||
inProcBus := bus.ProvideBus(tracer)
|
||||
folderStore := folderimpl.ProvideDashboardFolderStore(sqlStore)
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/folder/foldertest"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -30,7 +29,7 @@ func SetupFolderService(tb testing.TB, cfg *setting.Cfg, db db.DB, dashboardStor
|
||||
return folderimpl.ProvideService(ac, bus, cfg, dashboardStore, folderStore, db, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||
}
|
||||
|
||||
func SetupDashboardService(tb testing.TB, sqlStore *sqlstore.SQLStore, fs *folderimpl.DashboardFolderStoreImpl, cfg *setting.Cfg) (*dashboardservice.DashboardServiceImpl, dashboards.Store) {
|
||||
func SetupDashboardService(tb testing.TB, sqlStore db.DB, fs *folderimpl.DashboardFolderStoreImpl, cfg *setting.Cfg) (*dashboardservice.DashboardServiceImpl, dashboards.Store) {
|
||||
tb.Helper()
|
||||
|
||||
origNewGuardian := guardian.New
|
||||
@@ -51,7 +50,7 @@ func SetupDashboardService(tb testing.TB, sqlStore *sqlstore.SQLStore, fs *folde
|
||||
features := featuremgmt.WithFeatures()
|
||||
quotaService := quotatest.New(false, nil)
|
||||
|
||||
dashboardStore, err := database.ProvideDashboardStore(sqlStore, sqlStore.Cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := database.ProvideDashboardStore(sqlStore, cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(tb, err)
|
||||
|
||||
dashboardService, err := dashboardservice.ProvideDashboardServiceImpl(
|
||||
|
||||
@@ -621,7 +621,7 @@ func TestIntegration_SQLStore_GetOrgUsers(t *testing.T) {
|
||||
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "test org"})
|
||||
require.NoError(t, err)
|
||||
|
||||
seedOrgUsers(t, &orgUserStore, store, 10, userSvc, o.ID)
|
||||
seedOrgUsers(t, &orgUserStore, 10, userSvc, o.ID)
|
||||
|
||||
tests := []struct {
|
||||
desc string
|
||||
@@ -682,7 +682,7 @@ func TestIntegration_SQLStore_GetOrgUsers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func seedOrgUsers(t *testing.T, orgUserStore store, store *sqlstore.SQLStore, numUsers int, usrSvc user.Service, orgID int64) {
|
||||
func seedOrgUsers(t *testing.T, orgUserStore store, numUsers int, usrSvc user.Service, orgID int64) {
|
||||
t.Helper()
|
||||
|
||||
// Seed users
|
||||
@@ -798,7 +798,7 @@ func TestIntegration_SQLStore_SearchOrgUsers(t *testing.T) {
|
||||
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "test org"})
|
||||
require.NoError(t, err)
|
||||
|
||||
seedOrgUsers(t, &orgUserStore, store, 10, userSvc, o.ID)
|
||||
seedOrgUsers(t, &orgUserStore, 10, userSvc, o.ID)
|
||||
|
||||
tests := []struct {
|
||||
desc string
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
|
||||
"github.com/grafana/grafana/pkg/services/searchV2"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||
"github.com/grafana/grafana/pkg/tsdb/azuremonitor"
|
||||
@@ -88,7 +89,7 @@ func TestIntegrationPluginManager(t *testing.T) {
|
||||
pg := postgres.ProvideService(cfg)
|
||||
my := mysql.ProvideService()
|
||||
ms := mssql.ProvideService(cfg)
|
||||
sv2 := searchV2.ProvideService(cfg, db.InitTestDB(t), nil, nil, tracer, features, nil, nil, nil)
|
||||
sv2 := searchV2.ProvideService(cfg, db.InitTestDB(t, sqlstore.InitTestDBOpt{Cfg: cfg}), nil, nil, tracer, features, nil, nil, nil)
|
||||
graf := grafanads.ProvideService(sv2, nil)
|
||||
pyroscope := pyroscope.ProvideService(hcp)
|
||||
parca := parca.ProvideService(hcp)
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||
"github.com/grafana/grafana/pkg/services/publicdashboards/service"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -48,7 +47,7 @@ func TestIntegrationListPublicDashboard(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var sqlStore db.DB
|
||||
var cfg *setting.Cfg
|
||||
|
||||
var aDash *dashboards.Dashboard
|
||||
@@ -68,7 +67,7 @@ func TestIntegrationListPublicDashboard(t *testing.T) {
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
publicdashboardStore = ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
||||
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
|
||||
bDash = insertTestDashboard(t, dashboardStore, "b", orgId, "", false)
|
||||
aDash = insertTestDashboard(t, dashboardStore, "a", orgId, "", false)
|
||||
|
||||
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/annotations"
|
||||
"github.com/grafana/grafana/pkg/services/annotations/annotationsimpl"
|
||||
@@ -15,6 +16,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/publicdashboards/service/intervalv2"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
func newPublicDashboardServiceImpl(
|
||||
@@ -22,17 +24,17 @@ func newPublicDashboardServiceImpl(
|
||||
publicDashboardStore publicdashboards.Store,
|
||||
dashboardService dashboards.DashboardService,
|
||||
annotationsRepo annotations.Repository,
|
||||
) (*PublicDashboardServiceImpl, *sqlstore.SQLStore) {
|
||||
) (*PublicDashboardServiceImpl, db.DB, *setting.Cfg) {
|
||||
t.Helper()
|
||||
|
||||
sqlStore := sqlstore.InitTestDB(t)
|
||||
tagService := tagimpl.ProvideService(sqlStore)
|
||||
db := sqlstore.InitTestDB(t)
|
||||
tagService := tagimpl.ProvideService(db)
|
||||
if annotationsRepo == nil {
|
||||
annotationsRepo = annotationsimpl.ProvideService(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagService)
|
||||
annotationsRepo = annotationsimpl.ProvideService(db, db.Cfg, featuremgmt.WithFeatures(), tagService)
|
||||
}
|
||||
|
||||
if publicDashboardStore == nil {
|
||||
publicDashboardStore = database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
||||
publicDashboardStore = database.ProvideStore(db, db.Cfg, featuremgmt.WithFeatures())
|
||||
}
|
||||
serviceWrapper := ProvideServiceWrapper(publicDashboardStore)
|
||||
|
||||
@@ -48,5 +50,5 @@ func newPublicDashboardServiceImpl(
|
||||
serviceWrapper: serviceWrapper,
|
||||
license: license,
|
||||
features: featuremgmt.WithFeatures(),
|
||||
}, sqlStore
|
||||
}, db, db.Cfg
|
||||
}
|
||||
|
||||
@@ -677,12 +677,12 @@ const (
|
||||
|
||||
func TestGetQueryDataResponse(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
service, sqlStore, _ := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
fakeQueryService := &query.FakeQueryService{}
|
||||
fakeQueryService.On("QueryData", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&backend.QueryDataResponse{}, nil)
|
||||
service.QueryDataService = fakeQueryService
|
||||
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, service.cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
|
||||
publicDashboardQueryDTO := PublicDashboardQueryDTO{
|
||||
@@ -739,7 +739,7 @@ func TestFindAnnotations(t *testing.T) {
|
||||
Return(&PublicDashboard{Uid: "uid1", IsEnabled: true}, nil)
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboards.NewDashboard("dash1"), nil)
|
||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||
|
||||
reqDTO := AnnotationsQueryDTO{
|
||||
From: 1,
|
||||
@@ -792,7 +792,7 @@ func TestFindAnnotations(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
|
||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||
|
||||
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
||||
{
|
||||
@@ -849,7 +849,7 @@ func TestFindAnnotations(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
|
||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||
|
||||
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
||||
{
|
||||
@@ -918,7 +918,7 @@ func TestFindAnnotations(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
|
||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||
|
||||
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
||||
{
|
||||
@@ -958,7 +958,7 @@ func TestFindAnnotations(t *testing.T) {
|
||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||
|
||||
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
||||
|
||||
@@ -988,7 +988,7 @@ func TestFindAnnotations(t *testing.T) {
|
||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||
|
||||
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
||||
|
||||
@@ -1020,7 +1020,7 @@ func TestFindAnnotations(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dash, nil)
|
||||
|
||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||
|
||||
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
||||
|
||||
@@ -1061,7 +1061,7 @@ func TestFindAnnotations(t *testing.T) {
|
||||
},
|
||||
}, nil).Maybe()
|
||||
|
||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||
|
||||
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
||||
|
||||
@@ -1084,8 +1084,8 @@ func TestFindAnnotations(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetMetricRequest(t *testing.T) {
|
||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, nil, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, nil, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
||||
|
||||
@@ -1165,9 +1165,9 @@ func TestGetUniqueDashboardDatasourceUids(t *testing.T) {
|
||||
|
||||
func TestBuildMetricRequest(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
publicDashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
||||
nonPublicDashboard := insertTestDashboard(t, dashboardStore, "testNonPublicDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
||||
|
||||
@@ -387,7 +387,7 @@ func TestGetPublicDashboardForView(t *testing.T) {
|
||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||
|
||||
dashboardFullWithMeta, err := service.GetPublicDashboardForView(context.Background(), test.AccessToken)
|
||||
if test.ErrResp != nil {
|
||||
@@ -496,7 +496,7 @@ func TestGetPublicDashboard(t *testing.T) {
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
||||
fakeStore := &FakePublicDashboardStore{}
|
||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||
|
||||
pdc, dash, err := service.FindPublicDashboardAndDashboardByAccessToken(context.Background(), test.AccessToken)
|
||||
if test.ErrResp != nil {
|
||||
@@ -559,7 +559,7 @@ func TestGetEnabledPublicDashboard(t *testing.T) {
|
||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||
|
||||
pdc, dash, err := service.FindEnabledPublicDashboardAndDashboardByAccessToken(context.Background(), test.AccessToken)
|
||||
if test.ErrResp != nil {
|
||||
@@ -583,10 +583,10 @@ func TestGetEnabledPublicDashboard(t *testing.T) {
|
||||
func TestCreatePublicDashboard(t *testing.T) {
|
||||
t.Run("Create public dashboard", func(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
@@ -664,9 +664,9 @@ func TestCreatePublicDashboard(t *testing.T) {
|
||||
for _, tt := range testCases {
|
||||
t.Run(fmt.Sprintf("Create public dashboard with %s null boolean fields stores them as false", tt.Name), func(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
@@ -696,9 +696,9 @@ func TestCreatePublicDashboard(t *testing.T) {
|
||||
|
||||
t.Run("Validate pubdash has default time setting value", func(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
@@ -723,9 +723,9 @@ func TestCreatePublicDashboard(t *testing.T) {
|
||||
|
||||
t.Run("Creates pubdash whose dashboard has template variables successfully", func(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
|
||||
templateVars := make([]map[string]any, 1)
|
||||
@@ -769,7 +769,7 @@ func TestCreatePublicDashboard(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
|
||||
service, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, fakeDashboardService, nil)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, fakeDashboardService, nil)
|
||||
|
||||
isEnabled := true
|
||||
dto := &SavePublicDashboardDTO{
|
||||
@@ -789,9 +789,9 @@ func TestCreatePublicDashboard(t *testing.T) {
|
||||
|
||||
t.Run("Create public dashboard with given pubdash uid", func(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
@@ -835,7 +835,7 @@ func TestCreatePublicDashboard(t *testing.T) {
|
||||
publicDashboardStore.On("FindByDashboardUid", mock.Anything, mock.Anything, mock.Anything).Return(nil, ErrPublicDashboardNotFound.Errorf(""))
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
service, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, fakeDashboardService, nil)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, fakeDashboardService, nil)
|
||||
|
||||
isEnabled := true
|
||||
dto := &SavePublicDashboardDTO{
|
||||
@@ -855,9 +855,9 @@ func TestCreatePublicDashboard(t *testing.T) {
|
||||
|
||||
t.Run("Create public dashboard with given pubdash access token", func(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
@@ -895,7 +895,7 @@ func TestCreatePublicDashboard(t *testing.T) {
|
||||
|
||||
publicDashboardStore := &FakePublicDashboardStore{}
|
||||
publicDashboardStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(pubdash, nil)
|
||||
service, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, nil, nil)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, nil, nil)
|
||||
|
||||
_, err := service.NewPublicDashboardAccessToken(context.Background())
|
||||
require.Error(t, err)
|
||||
@@ -907,9 +907,9 @@ func TestCreatePublicDashboard(t *testing.T) {
|
||||
publicdashboardStore.On("FindByDashboardUid", mock.Anything, mock.Anything, mock.Anything).Return(&PublicDashboard{Uid: "newPubdashUid"}, nil)
|
||||
publicdashboardStore.On("Find", mock.Anything, mock.Anything).Return(nil, nil)
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
service, sqlStore := newPublicDashboardServiceImpl(t, publicdashboardStore, fakeDashboardService, nil)
|
||||
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, publicdashboardStore, fakeDashboardService, nil)
|
||||
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
@@ -932,10 +932,10 @@ func TestCreatePublicDashboard(t *testing.T) {
|
||||
|
||||
t.Run("Validate pubdash has default share value", func(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
@@ -970,10 +970,10 @@ func assertFalseIfNull(t *testing.T, expectedValue bool, nullableValue *bool) {
|
||||
|
||||
func TestUpdatePublicDashboard(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||
dashboard2 := insertTestDashboard(t, dashboardStore, "testDashie2", 1, 0, "", true, []map[string]any{}, nil)
|
||||
@@ -1153,10 +1153,10 @@ func TestUpdatePublicDashboard(t *testing.T) {
|
||||
for _, tt := range testCases {
|
||||
t.Run(fmt.Sprintf("Update public dashboard with %s null boolean fields let those fields with old persisted value", tt.Name), func(t *testing.T) {
|
||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||
|
||||
quotaService := quotatest.New(false, nil)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
@@ -1273,7 +1273,7 @@ func TestDeletePublicDashboard(t *testing.T) {
|
||||
if tt.ExpectedErrResp == nil || tt.mockDeleteStore.StoreRespErr != nil {
|
||||
store.On("Delete", mock.Anything, mock.Anything).Return(tt.mockDeleteStore.AffectedRowsResp, tt.mockDeleteStore.StoreRespErr)
|
||||
}
|
||||
service, _ := newPublicDashboardServiceImpl(t, store, nil, nil)
|
||||
service, _, _ := newPublicDashboardServiceImpl(t, store, nil, nil)
|
||||
|
||||
err := service.Delete(context.Background(), "pubdashUID", "uid")
|
||||
if tt.ExpectedErrResp != nil {
|
||||
@@ -1490,7 +1490,7 @@ func TestPublicDashboardServiceImpl_ListPublicDashboards(t *testing.T) {
|
||||
store := NewFakePublicDashboardStore(t)
|
||||
store.On("FindAllWithPagination", mock.Anything, mock.Anything).
|
||||
Return(tt.mockResponse.PublicDashboardListResponseWithPagination, tt.mockResponse.Err)
|
||||
pd, _ := newPublicDashboardServiceImpl(t, store, nil, nil)
|
||||
pd, _, _ := newPublicDashboardServiceImpl(t, store, nil, nil)
|
||||
pd.ac = ac
|
||||
|
||||
got, err := pd.FindAllWithPagination(tt.args.ctx, tt.args.query)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||
@@ -96,7 +97,7 @@ func TestIntegrationQuotaCommandsAndQueries(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
userService, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
setupEnv(t, sqlStore, b, quotaService)
|
||||
setupEnv(t, sqlStore, sqlStore.Cfg, b, quotaService)
|
||||
|
||||
u, err := userService.Create(context.Background(), &user.CreateUserCommand{
|
||||
Name: "TestUser",
|
||||
@@ -468,29 +469,29 @@ func getQuotaBySrvTargetScope(t *testing.T, quotaService quota.Service, srv quot
|
||||
return quota.QuotaDTO{}, err
|
||||
}
|
||||
|
||||
func setupEnv(t *testing.T, sqlStore *sqlstore.SQLStore, b bus.Bus, quotaService quota.Service) {
|
||||
func setupEnv(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, b bus.Bus, quotaService quota.Service) {
|
||||
tracer := tracing.InitializeTracerForTest()
|
||||
_, err := apikeyimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
||||
_, err := apikeyimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
_, err = authimpl.ProvideUserAuthTokenService(sqlStore, nil, quotaService, sqlStore.Cfg)
|
||||
_, err = authimpl.ProvideUserAuthTokenService(sqlStore, nil, quotaService, cfg)
|
||||
require.NoError(t, err)
|
||||
_, err = dashboardStore.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
_, err = dashboardStore.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
secretsService := secretsmng.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||
secretsStore := secretskvs.NewSQLSecretsKVStore(sqlStore, secretsService, log.New("test.logger"))
|
||||
_, err = dsservice.ProvideService(sqlStore, secretsService, secretsStore, sqlStore.Cfg, featuremgmt.WithFeatures(), acmock.New(), acmock.NewMockedPermissionsService(), quotaService, &pluginstore.FakePluginStore{})
|
||||
_, err = dsservice.ProvideService(sqlStore, secretsService, secretsStore, cfg, featuremgmt.WithFeatures(), acmock.New(), acmock.NewMockedPermissionsService(), quotaService, &pluginstore.FakePluginStore{})
|
||||
require.NoError(t, err)
|
||||
m := metrics.NewNGAlert(prometheus.NewRegistry())
|
||||
|
||||
ac := acimpl.ProvideAccessControl(sqlStore.Cfg)
|
||||
ruleStore, err := ngstore.ProvideDBStore(sqlStore.Cfg, featuremgmt.WithFeatures(), sqlStore, &foldertest.FakeService{}, &dashboards.FakeDashboardService{}, ac)
|
||||
ac := acimpl.ProvideAccessControl(cfg)
|
||||
ruleStore, err := ngstore.ProvideDBStore(cfg, featuremgmt.WithFeatures(), sqlStore, &foldertest.FakeService{}, &dashboards.FakeDashboardService{}, ac)
|
||||
require.NoError(t, err)
|
||||
_, err = ngalert.ProvideService(
|
||||
sqlStore.Cfg, featuremgmt.WithFeatures(), nil, nil, routing.NewRouteRegister(), sqlStore, ngalertfakes.NewFakeKVStore(t), nil, nil, quotaService,
|
||||
cfg, featuremgmt.WithFeatures(), nil, nil, routing.NewRouteRegister(), sqlStore, ngalertfakes.NewFakeKVStore(t), nil, nil, quotaService,
|
||||
secretsService, nil, m, &foldertest.FakeService{}, &acmock.Mock{}, &dashboards.FakeDashboardService{}, nil, b, &acmock.Mock{},
|
||||
annotationstest.NewFakeAnnotationsRepo(), &pluginstore.FakePluginStore{}, tracer, ruleStore,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
_, err = storesrv.ProvideService(sqlStore, featuremgmt.WithFeatures(), sqlStore.Cfg, quotaService, storesrv.ProvideSystemUsersService())
|
||||
_, err = storesrv.ProvideService(sqlStore, featuremgmt.WithFeatures(), cfg, quotaService, storesrv.ProvideSystemUsersService())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgtest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/store"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -98,7 +97,7 @@ func runSearchService(searchService *StandardSearchService) error {
|
||||
}
|
||||
|
||||
// Populates database with dashboards and folders
|
||||
func populateDB(folderCount, dashboardsPerFolder int, sqlStore *sqlstore.SQLStore) error {
|
||||
func populateDB(folderCount, dashboardsPerFolder int, sqlStore db.DB) error {
|
||||
// Insert folders
|
||||
offset := 1
|
||||
if errInsert := actest.ConcurrentBatch(actest.Concurrency, folderCount, actest.BatchSize, func(start, end int) error {
|
||||
|
||||
@@ -438,13 +438,13 @@ func TestIntegration_SecretsService(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
someData := []byte(`some-data`)
|
||||
|
||||
tcs := map[string]func(*testing.T, *sqlstore.SQLStore, *SecretsService){
|
||||
"regular": func(t *testing.T, _ *sqlstore.SQLStore, svc *SecretsService) {
|
||||
tcs := map[string]func(*testing.T, db.DB, *SecretsService){
|
||||
"regular": func(t *testing.T, _ db.DB, svc *SecretsService) {
|
||||
// We encrypt some data normally, no transactions implied.
|
||||
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||
require.NoError(t, err)
|
||||
},
|
||||
"within successful InTransaction": func(t *testing.T, store *sqlstore.SQLStore, svc *SecretsService) {
|
||||
"within successful InTransaction": func(t *testing.T, store db.DB, svc *SecretsService) {
|
||||
require.NoError(t, store.InTransaction(ctx, func(ctx context.Context) error {
|
||||
// We encrypt some data within a transaction that shares the db session.
|
||||
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||
@@ -454,7 +454,7 @@ func TestIntegration_SecretsService(t *testing.T) {
|
||||
return nil
|
||||
}))
|
||||
},
|
||||
"within unsuccessful InTransaction": func(t *testing.T, store *sqlstore.SQLStore, svc *SecretsService) {
|
||||
"within unsuccessful InTransaction": func(t *testing.T, store db.DB, svc *SecretsService) {
|
||||
require.NotNil(t, store.InTransaction(ctx, func(ctx context.Context) error {
|
||||
// We encrypt some data within a transaction that shares the db session.
|
||||
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||
@@ -464,7 +464,7 @@ func TestIntegration_SecretsService(t *testing.T) {
|
||||
return errors.New("error")
|
||||
}))
|
||||
},
|
||||
"within unsuccessful InTransaction (plus forced db fetch)": func(t *testing.T, store *sqlstore.SQLStore, svc *SecretsService) {
|
||||
"within unsuccessful InTransaction (plus forced db fetch)": func(t *testing.T, store db.DB, svc *SecretsService) {
|
||||
require.NotNil(t, store.InTransaction(ctx, func(ctx context.Context) error {
|
||||
// We encrypt some data within a transaction that shares the db session.
|
||||
encrypted, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||
@@ -483,7 +483,7 @@ func TestIntegration_SecretsService(t *testing.T) {
|
||||
return errors.New("error")
|
||||
}))
|
||||
},
|
||||
"within successful WithTransactionalDbSession": func(t *testing.T, store *sqlstore.SQLStore, svc *SecretsService) {
|
||||
"within successful WithTransactionalDbSession": func(t *testing.T, store db.DB, svc *SecretsService) {
|
||||
require.NoError(t, store.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
// We encrypt some data within a transaction that does not share the db session.
|
||||
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||
@@ -493,7 +493,7 @@ func TestIntegration_SecretsService(t *testing.T) {
|
||||
return nil
|
||||
}))
|
||||
},
|
||||
"within unsuccessful WithTransactionalDbSession": func(t *testing.T, store *sqlstore.SQLStore, svc *SecretsService) {
|
||||
"within unsuccessful WithTransactionalDbSession": func(t *testing.T, store db.DB, svc *SecretsService) {
|
||||
require.NotNil(t, store.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
// We encrypt some data within a transaction that does not share the db session.
|
||||
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||
@@ -503,7 +503,7 @@ func TestIntegration_SecretsService(t *testing.T) {
|
||||
return errors.New("error")
|
||||
}))
|
||||
},
|
||||
"within unsuccessful WithTransactionalDbSession (plus forced db fetch)": func(t *testing.T, store *sqlstore.SQLStore, svc *SecretsService) {
|
||||
"within unsuccessful WithTransactionalDbSession (plus forced db fetch)": func(t *testing.T, store db.DB, svc *SecretsService) {
|
||||
require.NotNil(t, store.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
// We encrypt some data within a transaction that does not share the db session.
|
||||
encrypted, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||
|
||||
@@ -16,9 +16,9 @@ import (
|
||||
func TestIntegrationStore_UsageStats(t *testing.T) {
|
||||
saToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
||||
db, store := setupTestDatabase(t)
|
||||
sa := tests.SetupUserServiceAccount(t, db, saToCreate)
|
||||
sa := tests.SetupUserServiceAccount(t, db, store.cfg, saToCreate)
|
||||
|
||||
db.Cfg.SATokenExpirationDayLimit = 4
|
||||
store.cfg.SATokenExpirationDayLimit = 4
|
||||
|
||||
keyName := t.Name()
|
||||
key, err := satokengen.New(keyName)
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/tests"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||
@@ -209,7 +208,7 @@ func TestStore_DeleteServiceAccount(t *testing.T) {
|
||||
for _, c := range cases {
|
||||
t.Run(c.desc, func(t *testing.T) {
|
||||
db, store := setupTestDatabase(t)
|
||||
user := tests.SetupUserServiceAccount(t, db, c.user)
|
||||
user := tests.SetupUserServiceAccount(t, db, store.cfg, c.user)
|
||||
err := store.DeleteServiceAccount(context.Background(), user.OrgID, user.ID)
|
||||
if c.expectedErr != nil {
|
||||
require.ErrorIs(t, err, c.expectedErr)
|
||||
@@ -220,18 +219,19 @@ func TestStore_DeleteServiceAccount(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func setupTestDatabase(t *testing.T) (*sqlstore.SQLStore, *ServiceAccountsStoreImpl) {
|
||||
func setupTestDatabase(t *testing.T) (db.DB, *ServiceAccountsStoreImpl) {
|
||||
t.Helper()
|
||||
db := db.InitTestDB(t)
|
||||
cfg := db.Cfg
|
||||
quotaService := quotatest.New(false, nil)
|
||||
apiKeyService, err := apikeyimpl.ProvideService(db, db.Cfg, quotaService)
|
||||
apiKeyService, err := apikeyimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
kvStore := kvstore.ProvideService(db)
|
||||
orgService, err := orgimpl.ProvideService(db, db.Cfg, quotaService)
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
userSvc, err := userimpl.ProvideService(db, orgService, db.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
userSvc, err := userimpl.ProvideService(db, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
return db, ProvideServiceAccountsStore(db.Cfg, db, apiKeyService, kvStore, userSvc, orgService)
|
||||
return db, ProvideServiceAccountsStore(cfg, db, apiKeyService, kvStore, userSvc, orgService)
|
||||
}
|
||||
|
||||
func TestStore_RetrieveServiceAccount(t *testing.T) {
|
||||
@@ -255,7 +255,7 @@ func TestStore_RetrieveServiceAccount(t *testing.T) {
|
||||
for _, c := range cases {
|
||||
t.Run(c.desc, func(t *testing.T) {
|
||||
db, store := setupTestDatabase(t)
|
||||
user := tests.SetupUserServiceAccount(t, db, c.user)
|
||||
user := tests.SetupUserServiceAccount(t, db, store.cfg, c.user)
|
||||
dto, err := store.RetrieveServiceAccount(context.Background(), user.OrgID, user.ID)
|
||||
if c.expectedErr != nil {
|
||||
require.ErrorIs(t, err, c.expectedErr)
|
||||
@@ -289,7 +289,7 @@ func TestStore_MigrateApiKeys(t *testing.T) {
|
||||
store.cfg.AutoAssignOrgRole = "Viewer"
|
||||
_, err := store.orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "main"})
|
||||
require.NoError(t, err)
|
||||
key := tests.SetupApiKey(t, db, c.key)
|
||||
key := tests.SetupApiKey(t, db, store.cfg, c.key)
|
||||
err = store.MigrateApiKey(context.Background(), key.OrgID, key.ID)
|
||||
if c.expectedErr != nil {
|
||||
require.ErrorIs(t, err, c.expectedErr)
|
||||
@@ -402,7 +402,7 @@ func TestStore_MigrateAllApiKeys(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, key := range c.keys {
|
||||
tests.SetupApiKey(t, db, key)
|
||||
tests.SetupApiKey(t, db, store.cfg, key)
|
||||
}
|
||||
|
||||
results, err := store.MigrateApiKeysToServiceAccounts(context.Background(), c.orgId)
|
||||
@@ -458,7 +458,7 @@ func TestServiceAccountsStoreImpl_SearchOrgServiceAccounts(t *testing.T) {
|
||||
}
|
||||
|
||||
db, store := setupTestDatabase(t)
|
||||
orgID := tests.SetupUsersServiceAccounts(t, db, initUsers)
|
||||
orgID := tests.SetupUsersServiceAccounts(t, db, store.cfg, initUsers)
|
||||
|
||||
userWithPerm := &user.SignedInUser{
|
||||
OrgID: orgID,
|
||||
@@ -582,7 +582,7 @@ func TestServiceAccountsStoreImpl_EnableServiceAccounts(t *testing.T) {
|
||||
}
|
||||
|
||||
db, store := setupTestDatabase(t)
|
||||
orgID := tests.SetupUsersServiceAccounts(t, db, initUsers)
|
||||
orgID := tests.SetupUsersServiceAccounts(t, db, store.cfg, initUsers)
|
||||
|
||||
fetchStates := func() map[int64]bool {
|
||||
sa1, err := store.RetrieveServiceAccount(ctx, orgID, 1)
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
func TestStore_AddServiceAccountToken(t *testing.T) {
|
||||
userToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
||||
db, store := setupTestDatabase(t)
|
||||
user := tests.SetupUserServiceAccount(t, db, userToCreate)
|
||||
user := tests.SetupUserServiceAccount(t, db, store.cfg, userToCreate)
|
||||
|
||||
type testCasesAdd struct {
|
||||
secondsToLive int64
|
||||
@@ -76,7 +76,7 @@ func TestStore_AddServiceAccountToken(t *testing.T) {
|
||||
func TestStore_AddServiceAccountToken_WrongServiceAccount(t *testing.T) {
|
||||
saToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
||||
db, store := setupTestDatabase(t)
|
||||
sa := tests.SetupUserServiceAccount(t, db, saToCreate)
|
||||
sa := tests.SetupUserServiceAccount(t, db, store.cfg, saToCreate)
|
||||
|
||||
keyName := t.Name()
|
||||
key, err := apikeygen.New(sa.OrgID, keyName)
|
||||
@@ -96,7 +96,7 @@ func TestStore_AddServiceAccountToken_WrongServiceAccount(t *testing.T) {
|
||||
func TestStore_RevokeServiceAccountToken(t *testing.T) {
|
||||
userToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
||||
db, store := setupTestDatabase(t)
|
||||
sa := tests.SetupUserServiceAccount(t, db, userToCreate)
|
||||
sa := tests.SetupUserServiceAccount(t, db, store.cfg, userToCreate)
|
||||
|
||||
keyName := t.Name()
|
||||
key, err := apikeygen.New(sa.OrgID, keyName)
|
||||
@@ -136,7 +136,7 @@ func TestStore_RevokeServiceAccountToken(t *testing.T) {
|
||||
func TestStore_DeleteServiceAccountToken(t *testing.T) {
|
||||
userToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
||||
db, store := setupTestDatabase(t)
|
||||
sa := tests.SetupUserServiceAccount(t, db, userToCreate)
|
||||
sa := tests.SetupUserServiceAccount(t, db, store.cfg, userToCreate)
|
||||
|
||||
keyName := t.Name()
|
||||
key, err := apikeygen.New(sa.OrgID, keyName)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/kvstore"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/usagestats"
|
||||
@@ -15,7 +16,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/database"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/secretscan"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
@@ -39,7 +39,7 @@ type ServiceAccountsService struct {
|
||||
func ProvideServiceAccountsService(
|
||||
cfg *setting.Cfg,
|
||||
usageStats usagestats.Service,
|
||||
store *sqlstore.SQLStore,
|
||||
store db.DB,
|
||||
apiKeyService apikey.Service,
|
||||
kvStore kvstore.KVStore,
|
||||
userService user.Service,
|
||||
|
||||
@@ -13,10 +13,10 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
type TestUser struct {
|
||||
@@ -35,16 +35,16 @@ type TestApiKey struct {
|
||||
ServiceAccountID *int64
|
||||
}
|
||||
|
||||
func SetupUserServiceAccount(t *testing.T, sqlStore *sqlstore.SQLStore, testUser TestUser) *user.User {
|
||||
func SetupUserServiceAccount(t *testing.T, db db.DB, cfg *setting.Cfg, testUser TestUser) *user.User {
|
||||
role := string(org.RoleViewer)
|
||||
if testUser.Role != "" {
|
||||
role = testUser.Role
|
||||
}
|
||||
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
||||
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := userimpl.ProvideService(db, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
|
||||
org, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{
|
||||
@@ -63,7 +63,7 @@ func SetupUserServiceAccount(t *testing.T, sqlStore *sqlstore.SQLStore, testUser
|
||||
return u1
|
||||
}
|
||||
|
||||
func SetupApiKey(t *testing.T, sqlStore *sqlstore.SQLStore, testKey TestApiKey) *apikey.APIKey {
|
||||
func SetupApiKey(t *testing.T, store db.DB, cfg *setting.Cfg, testKey TestApiKey) *apikey.APIKey {
|
||||
role := org.RoleViewer
|
||||
if testKey.Role != "" {
|
||||
role = testKey.Role
|
||||
@@ -83,13 +83,13 @@ func SetupApiKey(t *testing.T, sqlStore *sqlstore.SQLStore, testKey TestApiKey)
|
||||
}
|
||||
|
||||
quotaService := quotatest.New(false, nil)
|
||||
apiKeyService, err := apikeyimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
||||
apiKeyService, err := apikeyimpl.ProvideService(store, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
key, err := apiKeyService.AddAPIKey(context.Background(), addKeyCmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
if testKey.IsExpired {
|
||||
err := sqlStore.WithTransactionalDbSession(context.Background(), func(sess *db.Session) error {
|
||||
err := store.WithTransactionalDbSession(context.Background(), func(sess *db.Session) error {
|
||||
// Force setting expires to time before now to make key expired
|
||||
var expires int64 = 1
|
||||
expiringKey := apikey.APIKey{Expires: &expires}
|
||||
@@ -105,13 +105,13 @@ func SetupApiKey(t *testing.T, sqlStore *sqlstore.SQLStore, testKey TestApiKey)
|
||||
|
||||
// SetupUsersServiceAccounts creates in "test org" all users or service accounts passed in parameter
|
||||
// To achieve this, it sets the AutoAssignOrg and AutoAssignOrgId settings.
|
||||
func SetupUsersServiceAccounts(t *testing.T, sqlStore *sqlstore.SQLStore, testUsers []TestUser) (orgID int64) {
|
||||
func SetupUsersServiceAccounts(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, testUsers []TestUser) (orgID int64) {
|
||||
role := string(org.RoleNone)
|
||||
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
||||
quotaService := quotaimpl.ProvideService(sqlStore, cfg)
|
||||
orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
|
||||
org, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{
|
||||
@@ -119,8 +119,8 @@ func SetupUsersServiceAccounts(t *testing.T, sqlStore *sqlstore.SQLStore, testUs
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
sqlStore.Cfg.AutoAssignOrg = true
|
||||
sqlStore.Cfg.AutoAssignOrgId = int(org.ID)
|
||||
cfg.AutoAssignOrg = true
|
||||
cfg.AutoAssignOrgId = int(org.ID)
|
||||
|
||||
for i := range testUsers {
|
||||
_, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{
|
||||
|
||||
@@ -409,13 +409,15 @@ type InitTestDBOpt struct {
|
||||
// EnsureDefaultOrgAndUser flags whether to ensure that default org and user exist.
|
||||
EnsureDefaultOrgAndUser bool
|
||||
FeatureFlags []string
|
||||
Cfg *setting.Cfg
|
||||
}
|
||||
|
||||
// InitTestDBWithMigration initializes the test DB given custom migrations.
|
||||
func InitTestDBWithMigration(t sqlutil.ITestDB, migration registry.DatabaseMigrator, opts ...InitTestDBOpt) *SQLStore {
|
||||
t.Helper()
|
||||
features := getFeaturesForTesting(opts...)
|
||||
store, err := initTestDB(t, setting.NewCfg(), features, migration, opts...)
|
||||
cfg := getCfgForTesting(opts...)
|
||||
store, err := initTestDB(t, cfg, features, migration, opts...)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to initialize sql store: %s", err)
|
||||
}
|
||||
@@ -426,8 +428,9 @@ func InitTestDBWithMigration(t sqlutil.ITestDB, migration registry.DatabaseMigra
|
||||
func InitTestDB(t sqlutil.ITestDB, opts ...InitTestDBOpt) *SQLStore {
|
||||
t.Helper()
|
||||
features := getFeaturesForTesting(opts...)
|
||||
cfg := getCfgForTesting(opts...)
|
||||
|
||||
store, err := initTestDB(t, setting.NewCfg(), features, migrations.ProvideOSSMigrations(features), opts...)
|
||||
store, err := initTestDB(t, cfg, features, migrations.ProvideOSSMigrations(features), opts...)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to initialize sql store: %s", err)
|
||||
}
|
||||
@@ -465,6 +468,16 @@ func CleanupTestDB() {
|
||||
}
|
||||
}
|
||||
|
||||
func getCfgForTesting(opts ...InitTestDBOpt) *setting.Cfg {
|
||||
cfg := setting.NewCfg()
|
||||
for _, opt := range opts {
|
||||
if len(opt.FeatureFlags) > 0 {
|
||||
cfg = opt.Cfg
|
||||
}
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
func getFeaturesForTesting(opts ...InitTestDBOpt) featuremgmt.FeatureToggles {
|
||||
featureKeys := []any{
|
||||
featuremgmt.FlagPanelTitleSearch,
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/ssosettings"
|
||||
"github.com/grafana/grafana/pkg/services/ssosettings/models"
|
||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||
@@ -28,7 +27,7 @@ func TestIntegrationGetSSOSettings(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var sqlStore db.DB
|
||||
var ssoSettingsStore *SSOSettingsStore
|
||||
|
||||
setup := func() {
|
||||
@@ -91,7 +90,7 @@ func TestIntegrationUpsertSSOSettings(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var sqlStore db.DB
|
||||
var ssoSettingsStore *SSOSettingsStore
|
||||
|
||||
setup := func() {
|
||||
@@ -270,7 +269,7 @@ func TestIntegrationListSSOSettings(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var sqlStore db.DB
|
||||
var ssoSettingsStore *SSOSettingsStore
|
||||
|
||||
setup := func() {
|
||||
@@ -336,7 +335,7 @@ func TestIntegrationDeleteSSOSettings(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var sqlStore db.DB
|
||||
var ssoSettingsStore *SSOSettingsStore
|
||||
|
||||
setup := func() {
|
||||
@@ -458,7 +457,7 @@ func TestIntegrationDeleteSSOSettings(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func populateSSOSettings(sqlStore *sqlstore.SQLStore, template models.SSOSettings, providers ...string) error {
|
||||
func populateSSOSettings(sqlStore db.DB, template models.SSOSettings, providers ...string) error {
|
||||
return sqlStore.WithDbSession(context.Background(), func(sess *db.Session) error {
|
||||
for _, provider := range providers {
|
||||
settings := models.SSOSettings{
|
||||
@@ -478,7 +477,7 @@ func populateSSOSettings(sqlStore *sqlstore.SQLStore, template models.SSOSetting
|
||||
})
|
||||
}
|
||||
|
||||
func getSSOSettingsCountByDeleted(sqlStore *sqlstore.SQLStore) (deleted, notDeleted int64, err error) {
|
||||
func getSSOSettingsCountByDeleted(sqlStore db.DB) (deleted, notDeleted int64, err error) {
|
||||
err = sqlStore.WithDbSession(context.Background(), func(sess *db.Session) error {
|
||||
deleted, err = sess.Table("sso_setting").Where("is_deleted = ?", sqlStore.GetDialect().BooleanStr(true)).Count()
|
||||
if err != nil {
|
||||
@@ -491,7 +490,7 @@ func getSSOSettingsCountByDeleted(sqlStore *sqlstore.SQLStore) (deleted, notDele
|
||||
return
|
||||
}
|
||||
|
||||
func getSSOSettingsByProvider(sqlStore *sqlstore.SQLStore, provider string, deleted bool) (*models.SSOSettings, error) {
|
||||
func getSSOSettingsByProvider(sqlStore db.DB, provider string, deleted bool) (*models.SSOSettings, error) {
|
||||
var model models.SSOSettings
|
||||
var err error
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/correlations"
|
||||
"github.com/grafana/grafana/pkg/services/correlations/correlationstest"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
@@ -32,7 +35,7 @@ func TestIntegrationStatsDataAccess(t *testing.T) {
|
||||
}
|
||||
db := sqlstore.InitTestDB(t)
|
||||
statsService := &sqlStatsService{db: db}
|
||||
populateDB(t, db)
|
||||
populateDB(t, db, db.Cfg)
|
||||
|
||||
t.Run("Get system stats should not results in error", func(t *testing.T) {
|
||||
query := stats.GetSystemStatsQuery{}
|
||||
@@ -81,13 +84,14 @@ func TestIntegrationStatsDataAccess(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func populateDB(t *testing.T, sqlStore *sqlstore.SQLStore) {
|
||||
func populateDB(t *testing.T, db db.DB, cfg *setting.Cfg) {
|
||||
t.Helper()
|
||||
|
||||
orgService, _ := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotatest.New(false, nil))
|
||||
userSvc, _ := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||
orgService, _ := orgimpl.ProvideService(db, cfg, quotatest.New(false, nil))
|
||||
userSvc, _ := userimpl.ProvideService(db, orgService, cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||
|
||||
correlationsSvc := correlationstest.New(sqlStore)
|
||||
bus := bus.ProvideBus(tracing.InitializeTracerForTest())
|
||||
correlationsSvc := correlationstest.New(db, cfg, bus)
|
||||
|
||||
c := make([]correlations.Correlation, 2)
|
||||
for i := range c {
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestMain(m *testing.M) {
|
||||
func createServiceAccountAdminToken(t *testing.T, env *server.TestEnv) (string, *user.SignedInUser) {
|
||||
t.Helper()
|
||||
|
||||
account := saTests.SetupUserServiceAccount(t, env.SQLStore, saTests.TestUser{
|
||||
account := saTests.SetupUserServiceAccount(t, env.SQLStore, env.Cfg, saTests.TestUser{
|
||||
Name: "grpc-server-sa",
|
||||
Role: string(org.RoleAdmin),
|
||||
Login: "grpc-server-sa",
|
||||
@@ -38,7 +38,7 @@ func createServiceAccountAdminToken(t *testing.T, env *server.TestEnv) (string,
|
||||
keyGen, err := satokengen.New(saAPI.ServiceID)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = saTests.SetupApiKey(t, env.SQLStore, saTests.TestApiKey{
|
||||
_ = saTests.SetupApiKey(t, env.SQLStore, env.Cfg, saTests.TestApiKey{
|
||||
Name: "grpc-server-test",
|
||||
Role: org.RoleAdmin,
|
||||
OrgId: account.OrgID,
|
||||
@@ -79,7 +79,7 @@ func createTestContext(t *testing.T) testContext {
|
||||
|
||||
authToken, serviceAccountUser := createServiceAccountAdminToken(t, env)
|
||||
|
||||
eDB, err := dbimpl.ProvideEntityDB(env.SQLStore, env.SQLStore.Cfg, env.FeatureToggles)
|
||||
eDB, err := dbimpl.ProvideEntityDB(env.SQLStore, env.Cfg, env.FeatureToggles)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = eDB.Init()
|
||||
|
||||
@@ -16,12 +16,12 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||
"github.com/grafana/grafana/pkg/services/team"
|
||||
"github.com/grafana/grafana/pkg/services/team/sortopts"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||
)
|
||||
|
||||
@@ -526,17 +526,17 @@ func TestIntegrationSQLStore_GetTeamMembers_ACFilter(t *testing.T) {
|
||||
userIds := make([]int64, 4)
|
||||
|
||||
// Seed 2 teams with 2 members
|
||||
setup := func(store *sqlstore.SQLStore) {
|
||||
teamSvc, err := ProvideService(store, store.Cfg)
|
||||
setup := func(store db.DB, cfg *setting.Cfg) {
|
||||
teamSvc, err := ProvideService(store, cfg)
|
||||
require.NoError(t, err)
|
||||
team1, errCreateTeam := teamSvc.CreateTeam("group1 name", "test1@example.org", testOrgID)
|
||||
require.NoError(t, errCreateTeam)
|
||||
team2, errCreateTeam := teamSvc.CreateTeam("group2 name", "test2@example.org", testOrgID)
|
||||
require.NoError(t, errCreateTeam)
|
||||
quotaService := quotaimpl.ProvideService(store, store.Cfg)
|
||||
orgSvc, err := orgimpl.ProvideService(store, store.Cfg, quotaService)
|
||||
quotaService := quotaimpl.ProvideService(store, cfg)
|
||||
orgSvc, err := orgimpl.ProvideService(store, cfg, quotaService)
|
||||
require.NoError(t, err)
|
||||
userSvc, err := userimpl.ProvideService(store, orgSvc, store.Cfg, teamSvc, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
userSvc, err := userimpl.ProvideService(store, orgSvc, cfg, teamSvc, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||
require.NoError(t, err)
|
||||
|
||||
for i := 0; i < 4; i++ {
|
||||
@@ -561,7 +561,7 @@ func TestIntegrationSQLStore_GetTeamMembers_ACFilter(t *testing.T) {
|
||||
}
|
||||
|
||||
store := db.InitTestDB(t, db.InitTestDBOpt{})
|
||||
setup(store)
|
||||
setup(store, store.Cfg)
|
||||
teamSvc, err := ProvideService(store, store.Cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user