mirror of https://github.com/grafana/grafana
Chore: Move folder service into a separate package (#56591)
* Chore: move folder service interface into a separate package * copy implementation into a standalone package * move implementation and tests to the new folder package * remove leftovers from wire * add test doubles for folder service * fix tests in library panels/elements * fix provideservice in ngalertpull/56247/head^2
parent
eb077db2b0
commit
53baecd71f
@ -1,194 +0,0 @@ |
||||
// Code generated by mockery v2.12.1. DO NOT EDIT.
|
||||
|
||||
package dashboards |
||||
|
||||
import ( |
||||
context "context" |
||||
|
||||
models "github.com/grafana/grafana/pkg/models" |
||||
"github.com/grafana/grafana/pkg/services/user" |
||||
mock "github.com/stretchr/testify/mock" |
||||
|
||||
testing "testing" |
||||
) |
||||
|
||||
// FakeFolderService is an autogenerated mock type for the FolderService type
|
||||
type FakeFolderService struct { |
||||
mock.Mock |
||||
} |
||||
|
||||
// CreateFolder provides a mock function with given fields: ctx, user, orgID, title, uid
|
||||
func (_m *FakeFolderService) CreateFolder(ctx context.Context, usr *user.SignedInUser, orgID int64, title string, uid string) (*models.Folder, error) { |
||||
ret := _m.Called(ctx, usr, orgID, title, uid) |
||||
|
||||
var r0 *models.Folder |
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, string, string) *models.Folder); ok { |
||||
r0 = rf(ctx, usr, orgID, title, uid) |
||||
} else { |
||||
if ret.Get(0) != nil { |
||||
r0 = ret.Get(0).(*models.Folder) |
||||
} |
||||
} |
||||
|
||||
var r1 error |
||||
if rf, ok := ret.Get(1).(func(context.Context, *user.SignedInUser, int64, string, string) error); ok { |
||||
r1 = rf(ctx, usr, orgID, title, uid) |
||||
} else { |
||||
r1 = ret.Error(1) |
||||
} |
||||
|
||||
return r0, r1 |
||||
} |
||||
|
||||
// DeleteFolder provides a mock function with given fields: ctx, user, orgID, uid, forceDeleteRules
|
||||
func (_m *FakeFolderService) DeleteFolder(ctx context.Context, usr *user.SignedInUser, orgID int64, uid string, forceDeleteRules bool) (*models.Folder, error) { |
||||
ret := _m.Called(ctx, usr, orgID, uid, forceDeleteRules) |
||||
|
||||
var r0 *models.Folder |
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, string, bool) *models.Folder); ok { |
||||
r0 = rf(ctx, usr, orgID, uid, forceDeleteRules) |
||||
} else { |
||||
if ret.Get(0) != nil { |
||||
r0 = ret.Get(0).(*models.Folder) |
||||
} |
||||
} |
||||
|
||||
var r1 error |
||||
if rf, ok := ret.Get(1).(func(context.Context, *user.SignedInUser, int64, string, bool) error); ok { |
||||
r1 = rf(ctx, usr, orgID, uid, forceDeleteRules) |
||||
} else { |
||||
r1 = ret.Error(1) |
||||
} |
||||
|
||||
return r0, r1 |
||||
} |
||||
|
||||
// GetFolderByID provides a mock function with given fields: ctx, user, id, orgID
|
||||
func (_m *FakeFolderService) GetFolderByID(ctx context.Context, usr *user.SignedInUser, id int64, orgID int64) (*models.Folder, error) { |
||||
ret := _m.Called(ctx, usr, id, orgID) |
||||
|
||||
var r0 *models.Folder |
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, int64) *models.Folder); ok { |
||||
r0 = rf(ctx, usr, id, orgID) |
||||
} else { |
||||
if ret.Get(0) != nil { |
||||
r0 = ret.Get(0).(*models.Folder) |
||||
} |
||||
} |
||||
|
||||
var r1 error |
||||
if rf, ok := ret.Get(1).(func(context.Context, *user.SignedInUser, int64, int64) error); ok { |
||||
r1 = rf(ctx, usr, id, orgID) |
||||
} else { |
||||
r1 = ret.Error(1) |
||||
} |
||||
|
||||
return r0, r1 |
||||
} |
||||
|
||||
// GetFolderByTitle provides a mock function with given fields: ctx, user, orgID, title
|
||||
func (_m *FakeFolderService) GetFolderByTitle(ctx context.Context, usr *user.SignedInUser, orgID int64, title string) (*models.Folder, error) { |
||||
ret := _m.Called(ctx, usr, orgID, title) |
||||
|
||||
var r0 *models.Folder |
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, string) *models.Folder); ok { |
||||
r0 = rf(ctx, usr, orgID, title) |
||||
} else { |
||||
if ret.Get(0) != nil { |
||||
r0 = ret.Get(0).(*models.Folder) |
||||
} |
||||
} |
||||
|
||||
var r1 error |
||||
if rf, ok := ret.Get(1).(func(context.Context, *user.SignedInUser, int64, string) error); ok { |
||||
r1 = rf(ctx, usr, orgID, title) |
||||
} else { |
||||
r1 = ret.Error(1) |
||||
} |
||||
|
||||
return r0, r1 |
||||
} |
||||
|
||||
// GetFolderByUID provides a mock function with given fields: ctx, user, orgID, uid
|
||||
func (_m *FakeFolderService) GetFolderByUID(ctx context.Context, usr *user.SignedInUser, orgID int64, uid string) (*models.Folder, error) { |
||||
ret := _m.Called(ctx, usr, orgID, uid) |
||||
|
||||
var r0 *models.Folder |
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, string) *models.Folder); ok { |
||||
r0 = rf(ctx, usr, orgID, uid) |
||||
} else { |
||||
if ret.Get(0) != nil { |
||||
r0 = ret.Get(0).(*models.Folder) |
||||
} |
||||
} |
||||
|
||||
var r1 error |
||||
if rf, ok := ret.Get(1).(func(context.Context, *user.SignedInUser, int64, string) error); ok { |
||||
r1 = rf(ctx, usr, orgID, uid) |
||||
} else { |
||||
r1 = ret.Error(1) |
||||
} |
||||
|
||||
return r0, r1 |
||||
} |
||||
|
||||
// GetFolders provides a mock function with given fields: ctx, user, orgID, limit, page
|
||||
func (_m *FakeFolderService) GetFolders(ctx context.Context, usr *user.SignedInUser, orgID int64, limit int64, page int64) ([]*models.Folder, error) { |
||||
ret := _m.Called(ctx, usr, orgID, limit, page) |
||||
|
||||
var r0 []*models.Folder |
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, int64, int64) []*models.Folder); ok { |
||||
r0 = rf(ctx, usr, orgID, limit, page) |
||||
} else { |
||||
if ret.Get(0) != nil { |
||||
r0 = ret.Get(0).([]*models.Folder) |
||||
} |
||||
} |
||||
|
||||
var r1 error |
||||
if rf, ok := ret.Get(1).(func(context.Context, *user.SignedInUser, int64, int64, int64) error); ok { |
||||
r1 = rf(ctx, usr, orgID, limit, page) |
||||
} else { |
||||
r1 = ret.Error(1) |
||||
} |
||||
|
||||
return r0, r1 |
||||
} |
||||
|
||||
// MakeUserAdmin provides a mock function with given fields: ctx, orgID, userID, folderID, setViewAndEditPermissions
|
||||
func (_m *FakeFolderService) MakeUserAdmin(ctx context.Context, orgID int64, userID int64, folderID int64, setViewAndEditPermissions bool) error { |
||||
ret := _m.Called(ctx, orgID, userID, folderID, setViewAndEditPermissions) |
||||
|
||||
var r0 error |
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, int64, int64, bool) error); ok { |
||||
r0 = rf(ctx, orgID, userID, folderID, setViewAndEditPermissions) |
||||
} else { |
||||
r0 = ret.Error(0) |
||||
} |
||||
|
||||
return r0 |
||||
} |
||||
|
||||
// UpdateFolder provides a mock function with given fields: ctx, user, orgID, existingUid, cmd
|
||||
func (_m *FakeFolderService) UpdateFolder(ctx context.Context, usr *user.SignedInUser, orgID int64, existingUid string, cmd *models.UpdateFolderCommand) error { |
||||
ret := _m.Called(ctx, usr, orgID, existingUid, cmd) |
||||
|
||||
var r0 error |
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, string, *models.UpdateFolderCommand) error); ok { |
||||
r0 = rf(ctx, usr, orgID, existingUid, cmd) |
||||
} else { |
||||
r0 = ret.Error(0) |
||||
} |
||||
|
||||
return r0 |
||||
} |
||||
|
||||
// NewFakeFolderService creates a new instance of FakeFolderService. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewFakeFolderService(t testing.TB) *FakeFolderService { |
||||
mock := &FakeFolderService{} |
||||
mock.Mock.Test(t) |
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) }) |
||||
|
||||
return mock |
||||
} |
||||
@ -0,0 +1,40 @@ |
||||
package foldertest |
||||
|
||||
import ( |
||||
"context" |
||||
|
||||
"github.com/grafana/grafana/pkg/models" |
||||
"github.com/grafana/grafana/pkg/services/user" |
||||
) |
||||
|
||||
type FakeService struct { |
||||
ExpectedFolders []*models.Folder |
||||
ExpectedFolder *models.Folder |
||||
ExpectedError error |
||||
} |
||||
|
||||
func (s *FakeService) GetFolders(ctx context.Context, user *user.SignedInUser, orgID int64, limit int64, page int64) ([]*models.Folder, error) { |
||||
return s.ExpectedFolders, s.ExpectedError |
||||
} |
||||
func (s *FakeService) GetFolderByID(ctx context.Context, user *user.SignedInUser, id int64, orgID int64) (*models.Folder, error) { |
||||
return s.ExpectedFolder, s.ExpectedError |
||||
} |
||||
func (s *FakeService) GetFolderByUID(ctx context.Context, user *user.SignedInUser, orgID int64, uid string) (*models.Folder, error) { |
||||
return s.ExpectedFolder, s.ExpectedError |
||||
} |
||||
func (s *FakeService) GetFolderByTitle(ctx context.Context, user *user.SignedInUser, orgID int64, title string) (*models.Folder, error) { |
||||
return s.ExpectedFolder, s.ExpectedError |
||||
} |
||||
func (s *FakeService) CreateFolder(ctx context.Context, user *user.SignedInUser, orgID int64, title, uid string) (*models.Folder, error) { |
||||
return s.ExpectedFolder, s.ExpectedError |
||||
} |
||||
func (s *FakeService) UpdateFolder(ctx context.Context, user *user.SignedInUser, orgID int64, existingUid string, cmd *models.UpdateFolderCommand) error { |
||||
cmd.Result = s.ExpectedFolder |
||||
return s.ExpectedError |
||||
} |
||||
func (s *FakeService) DeleteFolder(ctx context.Context, user *user.SignedInUser, orgID int64, uid string, forceDeleteRules bool) (*models.Folder, error) { |
||||
return s.ExpectedFolder, s.ExpectedError |
||||
} |
||||
func (s *FakeService) MakeUserAdmin(ctx context.Context, orgID int64, userID, folderID int64, setViewAndEditPermissions bool) error { |
||||
return s.ExpectedError |
||||
} |
||||
Loading…
Reference in new issue