2023-06-02 09:38:02 -05:00
|
|
|
package testutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-11-13 09:55:15 -06:00
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2023-06-02 09:38:02 -05:00
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
2023-08-01 02:36:37 -05:00
|
|
|
"github.com/grafana/grafana/pkg/infra/db"
|
2024-08-13 05:26:26 -05:00
|
|
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
2023-06-02 09:38:02 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
|
|
|
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards/database"
|
|
|
|
dashboardservice "github.com/grafana/grafana/pkg/services/dashboards/service"
|
|
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
|
|
"github.com/grafana/grafana/pkg/services/folder"
|
|
|
|
"github.com/grafana/grafana/pkg/services/folder/folderimpl"
|
|
|
|
"github.com/grafana/grafana/pkg/services/folder/foldertest"
|
|
|
|
"github.com/grafana/grafana/pkg/services/guardian"
|
|
|
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
2024-02-26 04:27:22 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
2023-06-02 09:38:02 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
|
)
|
|
|
|
|
2024-02-06 16:12:13 -06:00
|
|
|
func SetupFolderService(tb testing.TB, cfg *setting.Cfg, db db.DB, dashboardStore dashboards.Store, folderStore *folderimpl.DashboardFolderStoreImpl, bus *bus.InProcBus, features featuremgmt.FeatureToggles, ac accesscontrol.AccessControl) folder.Service {
|
2023-06-02 09:38:02 -05:00
|
|
|
tb.Helper()
|
2024-08-13 05:26:26 -05:00
|
|
|
return folderimpl.ProvideService(ac, bus, dashboardStore, folderStore, db, features, supportbundlestest.NewFakeBundleService(), nil, tracing.InitializeTracerForTest())
|
2023-06-02 09:38:02 -05:00
|
|
|
}
|
|
|
|
|
2024-09-25 18:21:39 -05:00
|
|
|
func SetupDashboardService(tb testing.TB, sqlStore db.DB, fs *folderimpl.DashboardFolderStoreImpl, cfg *setting.Cfg) (*dashboardservice.DashboardServiceImpl, dashboards.Store) {
|
2023-06-02 09:38:02 -05:00
|
|
|
tb.Helper()
|
|
|
|
|
|
|
|
origNewGuardian := guardian.New
|
|
|
|
guardian.MockDashboardGuardian(&guardian.FakeDashboardGuardian{
|
|
|
|
CanSaveValue: true,
|
|
|
|
CanViewValue: true,
|
|
|
|
CanAdminValue: true,
|
|
|
|
})
|
|
|
|
tb.Cleanup(func() {
|
|
|
|
guardian.New = origNewGuardian
|
|
|
|
})
|
|
|
|
|
|
|
|
ac := acmock.New()
|
|
|
|
dashboardPermissions := acmock.NewMockedPermissionsService()
|
|
|
|
folderPermissions := acmock.NewMockedPermissionsService()
|
|
|
|
folderPermissions.On("SetPermissions", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]accesscontrol.ResourcePermission{}, nil)
|
|
|
|
|
|
|
|
features := featuremgmt.WithFeatures()
|
|
|
|
quotaService := quotatest.New(false, nil)
|
|
|
|
|
2024-09-25 18:21:39 -05:00
|
|
|
dashboardStore, err := database.ProvideDashboardStore(sqlStore, cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
|
2023-06-02 09:38:02 -05:00
|
|
|
require.NoError(tb, err)
|
|
|
|
|
|
|
|
dashboardService, err := dashboardservice.ProvideDashboardServiceImpl(
|
2024-03-14 09:36:35 -05:00
|
|
|
cfg, dashboardStore, fs,
|
2023-06-02 09:38:02 -05:00
|
|
|
features, folderPermissions, dashboardPermissions, ac,
|
|
|
|
foldertest.NewFakeService(),
|
2023-12-05 09:13:31 -06:00
|
|
|
nil,
|
2023-06-02 09:38:02 -05:00
|
|
|
)
|
|
|
|
require.NoError(tb, err)
|
|
|
|
|
|
|
|
return dashboardService, dashboardStore
|
|
|
|
}
|