From 6b7c004d0b4d20c6ac02ae813aa1c8dc3cb3f5d3 Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Wed, 21 May 2025 13:51:51 +0200 Subject: [PATCH] fix(tests): fix nil pointer errors caused by the introduction of cs3 metadata storage --- services/graph/.mockery.yaml | 5 + services/graph/mocks/storage.go | 732 ++++++++++++++++++ .../users_user_profile_photo_provider.go | 16 +- services/graph/pkg/server/http/server.go | 13 + .../graph/pkg/service/v0/application_test.go | 19 +- .../pkg/service/v0/approleassignments_test.go | 21 +- .../graph/pkg/service/v0/driveitems_test.go | 8 +- .../pkg/service/v0/educationclasses_test.go | 29 +- .../pkg/service/v0/educationschools_test.go | 12 +- .../pkg/service/v0/educationuser_test.go | 23 +- services/graph/pkg/service/v0/graph_test.go | 11 +- services/graph/pkg/service/v0/groups_test.go | 28 +- services/graph/pkg/service/v0/option.go | 16 +- .../graph/pkg/service/v0/password_test.go | 29 +- services/graph/pkg/service/v0/service.go | 14 +- .../graph/pkg/service/v0/sharedbyme_test.go | 26 +- .../graph/pkg/service/v0/sharedwithme_test.go | 12 +- services/graph/pkg/service/v0/users_test.go | 26 +- 18 files changed, 948 insertions(+), 92 deletions(-) create mode 100644 services/graph/mocks/storage.go diff --git a/services/graph/.mockery.yaml b/services/graph/.mockery.yaml index 551e991a83..fcfd8a989b 100644 --- a/services/graph/.mockery.yaml +++ b/services/graph/.mockery.yaml @@ -22,6 +22,11 @@ packages: dir: "mocks" interfaces: Publisher: + github.com/opencloud-eu/reva/v2/pkg/storage/utils/metadata: + config: + dir: "mocks" + interfaces: + Storage: github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool: config: dir: "mocks" diff --git a/services/graph/mocks/storage.go b/services/graph/mocks/storage.go new file mode 100644 index 0000000000..62fdc1fcae --- /dev/null +++ b/services/graph/mocks/storage.go @@ -0,0 +1,732 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import ( + context "context" + + metadata "github.com/opencloud-eu/reva/v2/pkg/storage/utils/metadata" + mock "github.com/stretchr/testify/mock" + + providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" +) + +// Storage is an autogenerated mock type for the Storage type +type Storage struct { + mock.Mock +} + +type Storage_Expecter struct { + mock *mock.Mock +} + +func (_m *Storage) EXPECT() *Storage_Expecter { + return &Storage_Expecter{mock: &_m.Mock} +} + +// Backend provides a mock function with no fields +func (_m *Storage) Backend() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Backend") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Storage_Backend_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Backend' +type Storage_Backend_Call struct { + *mock.Call +} + +// Backend is a helper method to define mock.On call +func (_e *Storage_Expecter) Backend() *Storage_Backend_Call { + return &Storage_Backend_Call{Call: _e.mock.On("Backend")} +} + +func (_c *Storage_Backend_Call) Run(run func()) *Storage_Backend_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Storage_Backend_Call) Return(_a0 string) *Storage_Backend_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Storage_Backend_Call) RunAndReturn(run func() string) *Storage_Backend_Call { + _c.Call.Return(run) + return _c +} + +// CreateSymlink provides a mock function with given fields: ctx, oldname, newname +func (_m *Storage) CreateSymlink(ctx context.Context, oldname string, newname string) error { + ret := _m.Called(ctx, oldname, newname) + + if len(ret) == 0 { + panic("no return value specified for CreateSymlink") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { + r0 = rf(ctx, oldname, newname) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Storage_CreateSymlink_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateSymlink' +type Storage_CreateSymlink_Call struct { + *mock.Call +} + +// CreateSymlink is a helper method to define mock.On call +// - ctx context.Context +// - oldname string +// - newname string +func (_e *Storage_Expecter) CreateSymlink(ctx interface{}, oldname interface{}, newname interface{}) *Storage_CreateSymlink_Call { + return &Storage_CreateSymlink_Call{Call: _e.mock.On("CreateSymlink", ctx, oldname, newname)} +} + +func (_c *Storage_CreateSymlink_Call) Run(run func(ctx context.Context, oldname string, newname string)) *Storage_CreateSymlink_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *Storage_CreateSymlink_Call) Return(_a0 error) *Storage_CreateSymlink_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Storage_CreateSymlink_Call) RunAndReturn(run func(context.Context, string, string) error) *Storage_CreateSymlink_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, path +func (_m *Storage) Delete(ctx context.Context, path string) error { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, path) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Storage_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type Storage_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *Storage_Expecter) Delete(ctx interface{}, path interface{}) *Storage_Delete_Call { + return &Storage_Delete_Call{Call: _e.mock.On("Delete", ctx, path)} +} + +func (_c *Storage_Delete_Call) Run(run func(ctx context.Context, path string)) *Storage_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Storage_Delete_Call) Return(_a0 error) *Storage_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Storage_Delete_Call) RunAndReturn(run func(context.Context, string) error) *Storage_Delete_Call { + _c.Call.Return(run) + return _c +} + +// Download provides a mock function with given fields: ctx, req +func (_m *Storage) Download(ctx context.Context, req metadata.DownloadRequest) (*metadata.DownloadResponse, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Download") + } + + var r0 *metadata.DownloadResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, metadata.DownloadRequest) (*metadata.DownloadResponse, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, metadata.DownloadRequest) *metadata.DownloadResponse); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*metadata.DownloadResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, metadata.DownloadRequest) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Storage_Download_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Download' +type Storage_Download_Call struct { + *mock.Call +} + +// Download is a helper method to define mock.On call +// - ctx context.Context +// - req metadata.DownloadRequest +func (_e *Storage_Expecter) Download(ctx interface{}, req interface{}) *Storage_Download_Call { + return &Storage_Download_Call{Call: _e.mock.On("Download", ctx, req)} +} + +func (_c *Storage_Download_Call) Run(run func(ctx context.Context, req metadata.DownloadRequest)) *Storage_Download_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(metadata.DownloadRequest)) + }) + return _c +} + +func (_c *Storage_Download_Call) Return(_a0 *metadata.DownloadResponse, _a1 error) *Storage_Download_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Storage_Download_Call) RunAndReturn(run func(context.Context, metadata.DownloadRequest) (*metadata.DownloadResponse, error)) *Storage_Download_Call { + _c.Call.Return(run) + return _c +} + +// Init provides a mock function with given fields: ctx, name +func (_m *Storage) Init(ctx context.Context, name string) error { + ret := _m.Called(ctx, name) + + if len(ret) == 0 { + panic("no return value specified for Init") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, name) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Storage_Init_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Init' +type Storage_Init_Call struct { + *mock.Call +} + +// Init is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *Storage_Expecter) Init(ctx interface{}, name interface{}) *Storage_Init_Call { + return &Storage_Init_Call{Call: _e.mock.On("Init", ctx, name)} +} + +func (_c *Storage_Init_Call) Run(run func(ctx context.Context, name string)) *Storage_Init_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Storage_Init_Call) Return(err error) *Storage_Init_Call { + _c.Call.Return(err) + return _c +} + +func (_c *Storage_Init_Call) RunAndReturn(run func(context.Context, string) error) *Storage_Init_Call { + _c.Call.Return(run) + return _c +} + +// ListDir provides a mock function with given fields: ctx, path +func (_m *Storage) ListDir(ctx context.Context, path string) ([]*providerv1beta1.ResourceInfo, error) { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for ListDir") + } + + var r0 []*providerv1beta1.ResourceInfo + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) ([]*providerv1beta1.ResourceInfo, error)); ok { + return rf(ctx, path) + } + if rf, ok := ret.Get(0).(func(context.Context, string) []*providerv1beta1.ResourceInfo); ok { + r0 = rf(ctx, path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*providerv1beta1.ResourceInfo) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Storage_ListDir_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListDir' +type Storage_ListDir_Call struct { + *mock.Call +} + +// ListDir is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *Storage_Expecter) ListDir(ctx interface{}, path interface{}) *Storage_ListDir_Call { + return &Storage_ListDir_Call{Call: _e.mock.On("ListDir", ctx, path)} +} + +func (_c *Storage_ListDir_Call) Run(run func(ctx context.Context, path string)) *Storage_ListDir_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Storage_ListDir_Call) Return(_a0 []*providerv1beta1.ResourceInfo, _a1 error) *Storage_ListDir_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Storage_ListDir_Call) RunAndReturn(run func(context.Context, string) ([]*providerv1beta1.ResourceInfo, error)) *Storage_ListDir_Call { + _c.Call.Return(run) + return _c +} + +// MakeDirIfNotExist provides a mock function with given fields: ctx, name +func (_m *Storage) MakeDirIfNotExist(ctx context.Context, name string) error { + ret := _m.Called(ctx, name) + + if len(ret) == 0 { + panic("no return value specified for MakeDirIfNotExist") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, name) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Storage_MakeDirIfNotExist_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MakeDirIfNotExist' +type Storage_MakeDirIfNotExist_Call struct { + *mock.Call +} + +// MakeDirIfNotExist is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *Storage_Expecter) MakeDirIfNotExist(ctx interface{}, name interface{}) *Storage_MakeDirIfNotExist_Call { + return &Storage_MakeDirIfNotExist_Call{Call: _e.mock.On("MakeDirIfNotExist", ctx, name)} +} + +func (_c *Storage_MakeDirIfNotExist_Call) Run(run func(ctx context.Context, name string)) *Storage_MakeDirIfNotExist_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Storage_MakeDirIfNotExist_Call) Return(_a0 error) *Storage_MakeDirIfNotExist_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Storage_MakeDirIfNotExist_Call) RunAndReturn(run func(context.Context, string) error) *Storage_MakeDirIfNotExist_Call { + _c.Call.Return(run) + return _c +} + +// ReadDir provides a mock function with given fields: ctx, path +func (_m *Storage) ReadDir(ctx context.Context, path string) ([]string, error) { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for ReadDir") + } + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) ([]string, error)); ok { + return rf(ctx, path) + } + if rf, ok := ret.Get(0).(func(context.Context, string) []string); ok { + r0 = rf(ctx, path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Storage_ReadDir_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadDir' +type Storage_ReadDir_Call struct { + *mock.Call +} + +// ReadDir is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *Storage_Expecter) ReadDir(ctx interface{}, path interface{}) *Storage_ReadDir_Call { + return &Storage_ReadDir_Call{Call: _e.mock.On("ReadDir", ctx, path)} +} + +func (_c *Storage_ReadDir_Call) Run(run func(ctx context.Context, path string)) *Storage_ReadDir_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Storage_ReadDir_Call) Return(_a0 []string, _a1 error) *Storage_ReadDir_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Storage_ReadDir_Call) RunAndReturn(run func(context.Context, string) ([]string, error)) *Storage_ReadDir_Call { + _c.Call.Return(run) + return _c +} + +// ResolveSymlink provides a mock function with given fields: ctx, name +func (_m *Storage) ResolveSymlink(ctx context.Context, name string) (string, error) { + ret := _m.Called(ctx, name) + + if len(ret) == 0 { + panic("no return value specified for ResolveSymlink") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (string, error)); ok { + return rf(ctx, name) + } + if rf, ok := ret.Get(0).(func(context.Context, string) string); ok { + r0 = rf(ctx, name) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Storage_ResolveSymlink_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ResolveSymlink' +type Storage_ResolveSymlink_Call struct { + *mock.Call +} + +// ResolveSymlink is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *Storage_Expecter) ResolveSymlink(ctx interface{}, name interface{}) *Storage_ResolveSymlink_Call { + return &Storage_ResolveSymlink_Call{Call: _e.mock.On("ResolveSymlink", ctx, name)} +} + +func (_c *Storage_ResolveSymlink_Call) Run(run func(ctx context.Context, name string)) *Storage_ResolveSymlink_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Storage_ResolveSymlink_Call) Return(_a0 string, _a1 error) *Storage_ResolveSymlink_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Storage_ResolveSymlink_Call) RunAndReturn(run func(context.Context, string) (string, error)) *Storage_ResolveSymlink_Call { + _c.Call.Return(run) + return _c +} + +// SimpleDownload provides a mock function with given fields: ctx, path +func (_m *Storage) SimpleDownload(ctx context.Context, path string) ([]byte, error) { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for SimpleDownload") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) ([]byte, error)); ok { + return rf(ctx, path) + } + if rf, ok := ret.Get(0).(func(context.Context, string) []byte); ok { + r0 = rf(ctx, path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Storage_SimpleDownload_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SimpleDownload' +type Storage_SimpleDownload_Call struct { + *mock.Call +} + +// SimpleDownload is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *Storage_Expecter) SimpleDownload(ctx interface{}, path interface{}) *Storage_SimpleDownload_Call { + return &Storage_SimpleDownload_Call{Call: _e.mock.On("SimpleDownload", ctx, path)} +} + +func (_c *Storage_SimpleDownload_Call) Run(run func(ctx context.Context, path string)) *Storage_SimpleDownload_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Storage_SimpleDownload_Call) Return(_a0 []byte, _a1 error) *Storage_SimpleDownload_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Storage_SimpleDownload_Call) RunAndReturn(run func(context.Context, string) ([]byte, error)) *Storage_SimpleDownload_Call { + _c.Call.Return(run) + return _c +} + +// SimpleUpload provides a mock function with given fields: ctx, uploadpath, content +func (_m *Storage) SimpleUpload(ctx context.Context, uploadpath string, content []byte) error { + ret := _m.Called(ctx, uploadpath, content) + + if len(ret) == 0 { + panic("no return value specified for SimpleUpload") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, []byte) error); ok { + r0 = rf(ctx, uploadpath, content) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Storage_SimpleUpload_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SimpleUpload' +type Storage_SimpleUpload_Call struct { + *mock.Call +} + +// SimpleUpload is a helper method to define mock.On call +// - ctx context.Context +// - uploadpath string +// - content []byte +func (_e *Storage_Expecter) SimpleUpload(ctx interface{}, uploadpath interface{}, content interface{}) *Storage_SimpleUpload_Call { + return &Storage_SimpleUpload_Call{Call: _e.mock.On("SimpleUpload", ctx, uploadpath, content)} +} + +func (_c *Storage_SimpleUpload_Call) Run(run func(ctx context.Context, uploadpath string, content []byte)) *Storage_SimpleUpload_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].([]byte)) + }) + return _c +} + +func (_c *Storage_SimpleUpload_Call) Return(_a0 error) *Storage_SimpleUpload_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Storage_SimpleUpload_Call) RunAndReturn(run func(context.Context, string, []byte) error) *Storage_SimpleUpload_Call { + _c.Call.Return(run) + return _c +} + +// Stat provides a mock function with given fields: ctx, path +func (_m *Storage) Stat(ctx context.Context, path string) (*providerv1beta1.ResourceInfo, error) { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for Stat") + } + + var r0 *providerv1beta1.ResourceInfo + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*providerv1beta1.ResourceInfo, error)); ok { + return rf(ctx, path) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *providerv1beta1.ResourceInfo); ok { + r0 = rf(ctx, path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*providerv1beta1.ResourceInfo) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Storage_Stat_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Stat' +type Storage_Stat_Call struct { + *mock.Call +} + +// Stat is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *Storage_Expecter) Stat(ctx interface{}, path interface{}) *Storage_Stat_Call { + return &Storage_Stat_Call{Call: _e.mock.On("Stat", ctx, path)} +} + +func (_c *Storage_Stat_Call) Run(run func(ctx context.Context, path string)) *Storage_Stat_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *Storage_Stat_Call) Return(_a0 *providerv1beta1.ResourceInfo, _a1 error) *Storage_Stat_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Storage_Stat_Call) RunAndReturn(run func(context.Context, string) (*providerv1beta1.ResourceInfo, error)) *Storage_Stat_Call { + _c.Call.Return(run) + return _c +} + +// Upload provides a mock function with given fields: ctx, req +func (_m *Storage) Upload(ctx context.Context, req metadata.UploadRequest) (*metadata.UploadResponse, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Upload") + } + + var r0 *metadata.UploadResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, metadata.UploadRequest) (*metadata.UploadResponse, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, metadata.UploadRequest) *metadata.UploadResponse); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*metadata.UploadResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, metadata.UploadRequest) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Storage_Upload_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Upload' +type Storage_Upload_Call struct { + *mock.Call +} + +// Upload is a helper method to define mock.On call +// - ctx context.Context +// - req metadata.UploadRequest +func (_e *Storage_Expecter) Upload(ctx interface{}, req interface{}) *Storage_Upload_Call { + return &Storage_Upload_Call{Call: _e.mock.On("Upload", ctx, req)} +} + +func (_c *Storage_Upload_Call) Run(run func(ctx context.Context, req metadata.UploadRequest)) *Storage_Upload_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(metadata.UploadRequest)) + }) + return _c +} + +func (_c *Storage_Upload_Call) Return(_a0 *metadata.UploadResponse, _a1 error) *Storage_Upload_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Storage_Upload_Call) RunAndReturn(run func(context.Context, metadata.UploadRequest) (*metadata.UploadResponse, error)) *Storage_Upload_Call { + _c.Call.Return(run) + return _c +} + +// NewStorage creates a new instance of Storage. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewStorage(t interface { + mock.TestingT + Cleanup(func()) +}) *Storage { + mock := &Storage{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/services/graph/mocks/users_user_profile_photo_provider.go b/services/graph/mocks/users_user_profile_photo_provider.go index 89c17e305b..faeb8f1a8d 100644 --- a/services/graph/mocks/users_user_profile_photo_provider.go +++ b/services/graph/mocks/users_user_profile_photo_provider.go @@ -128,9 +128,9 @@ func (_c *UsersUserProfilePhotoProvider_GetPhoto_Call) RunAndReturn(run func(con return _c } -// UpdatePhoto provides a mock function with given fields: ctx, id, rc -func (_m *UsersUserProfilePhotoProvider) UpdatePhoto(ctx context.Context, id string, rc io.Reader) error { - ret := _m.Called(ctx, id, rc) +// UpdatePhoto provides a mock function with given fields: ctx, id, r +func (_m *UsersUserProfilePhotoProvider) UpdatePhoto(ctx context.Context, id string, r io.Reader) error { + ret := _m.Called(ctx, id, r) if len(ret) == 0 { panic("no return value specified for UpdatePhoto") @@ -138,7 +138,7 @@ func (_m *UsersUserProfilePhotoProvider) UpdatePhoto(ctx context.Context, id str var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, io.Reader) error); ok { - r0 = rf(ctx, id, rc) + r0 = rf(ctx, id, r) } else { r0 = ret.Error(0) } @@ -154,12 +154,12 @@ type UsersUserProfilePhotoProvider_UpdatePhoto_Call struct { // UpdatePhoto is a helper method to define mock.On call // - ctx context.Context // - id string -// - rc io.Reader -func (_e *UsersUserProfilePhotoProvider_Expecter) UpdatePhoto(ctx interface{}, id interface{}, rc interface{}) *UsersUserProfilePhotoProvider_UpdatePhoto_Call { - return &UsersUserProfilePhotoProvider_UpdatePhoto_Call{Call: _e.mock.On("UpdatePhoto", ctx, id, rc)} +// - r io.Reader +func (_e *UsersUserProfilePhotoProvider_Expecter) UpdatePhoto(ctx interface{}, id interface{}, r interface{}) *UsersUserProfilePhotoProvider_UpdatePhoto_Call { + return &UsersUserProfilePhotoProvider_UpdatePhoto_Call{Call: _e.mock.On("UpdatePhoto", ctx, id, r)} } -func (_c *UsersUserProfilePhotoProvider_UpdatePhoto_Call) Run(run func(ctx context.Context, id string, rc io.Reader)) *UsersUserProfilePhotoProvider_UpdatePhoto_Call { +func (_c *UsersUserProfilePhotoProvider_UpdatePhoto_Call) Run(run func(ctx context.Context, id string, r io.Reader)) *UsersUserProfilePhotoProvider_UpdatePhoto_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(string), args[2].(io.Reader)) }) diff --git a/services/graph/pkg/server/http/server.go b/services/graph/pkg/server/http/server.go index 91ca248088..98fb696bf2 100644 --- a/services/graph/pkg/server/http/server.go +++ b/services/graph/pkg/server/http/server.go @@ -8,6 +8,7 @@ import ( chimiddleware "github.com/go-chi/chi/v5/middleware" "github.com/opencloud-eu/reva/v2/pkg/events/stream" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" + "github.com/opencloud-eu/reva/v2/pkg/storage/utils/metadata" "github.com/pkg/errors" "go-micro.dev/v4" "go-micro.dev/v4/events" @@ -128,9 +129,21 @@ func Server(opts ...Option) (http.Service, error) { hClient := ehsvc.NewEventHistoryService("eu.opencloud.api.eventhistory", grpcClient) + storage, err := metadata.NewCS3Storage( + options.Config.Metadata.GatewayAddress, + options.Config.Metadata.StorageAddress, + options.Config.Metadata.SystemUserID, + options.Config.Metadata.SystemUserIDP, + options.Config.Metadata.SystemUserAPIKey, + ) + if err != nil { + return http.Service{}, fmt.Errorf("could not initialize metadata storage: %w", err) + } + var handle svc.Service handle, err = svc.NewService( svc.Context(options.Context), + svc.MetadataStorage(storage), svc.Logger(options.Logger), svc.Config(options.Config), svc.Middleware(middlewares...), diff --git a/services/graph/pkg/service/v0/application_test.go b/services/graph/pkg/service/v0/application_test.go index 0e53238fc4..47acb9f93d 100644 --- a/services/graph/pkg/service/v0/application_test.go +++ b/services/graph/pkg/service/v0/application_test.go @@ -11,6 +11,12 @@ import ( "github.com/go-chi/chi/v5" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + libregraph "github.com/opencloud-eu/libre-graph-api-go" + "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" + cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" + "github.com/stretchr/testify/mock" + "google.golang.org/grpc" + "github.com/opencloud-eu/opencloud/pkg/shared" settingsmsg "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/messages/settings/v0" settings "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/settings/v0" @@ -19,11 +25,6 @@ import ( "github.com/opencloud-eu/opencloud/services/graph/pkg/config/defaults" identitymocks "github.com/opencloud-eu/opencloud/services/graph/pkg/identity/mocks" service "github.com/opencloud-eu/opencloud/services/graph/pkg/service/v0" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" - libregraph "github.com/opencloud-eu/libre-graph-api-go" - "github.com/stretchr/testify/mock" - "google.golang.org/grpc" ) type applicationList struct { @@ -70,13 +71,19 @@ var _ = Describe("Applications", func() { cfg.GRPCClientTLS = &shared.GRPCClientTLS{} cfg.Application.ID = "some-application-ID" - svc, _ = service.NewService( + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + var err error + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.EventsPublisher(&eventsPublisher), service.WithIdentityBackend(identityBackend), service.WithRoleService(roleService), ) + Expect(err).ToNot(HaveOccurred()) }) Describe("ListApplications", func() { diff --git a/services/graph/pkg/service/v0/approleassignments_test.go b/services/graph/pkg/service/v0/approleassignments_test.go index 4bcefe63b5..29c94b2abb 100644 --- a/services/graph/pkg/service/v0/approleassignments_test.go +++ b/services/graph/pkg/service/v0/approleassignments_test.go @@ -14,6 +14,13 @@ import ( "github.com/golang/protobuf/ptypes/empty" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + libregraph "github.com/opencloud-eu/libre-graph-api-go" + revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" + "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" + cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" + "github.com/stretchr/testify/mock" + "google.golang.org/grpc" + "github.com/opencloud-eu/opencloud/pkg/shared" settingsmsg "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/messages/settings/v0" settings "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/settings/v0" @@ -22,12 +29,6 @@ import ( "github.com/opencloud-eu/opencloud/services/graph/pkg/config/defaults" identitymocks "github.com/opencloud-eu/opencloud/services/graph/pkg/identity/mocks" service "github.com/opencloud-eu/opencloud/services/graph/pkg/service/v0" - revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" - libregraph "github.com/opencloud-eu/libre-graph-api-go" - "github.com/stretchr/testify/mock" - "google.golang.org/grpc" ) type assignmentList struct { @@ -80,13 +81,19 @@ var _ = Describe("AppRoleAssignments", func() { cfg.GRPCClientTLS = &shared.GRPCClientTLS{} cfg.Application.ID = "some-application-ID" - svc, _ = service.NewService( + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + var err error + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.EventsPublisher(&eventsPublisher), service.WithIdentityBackend(identityBackend), service.WithRoleService(roleService), ) + Expect(err).ToNot(HaveOccurred()) }) Describe("ListAppRoleAssignments", func() { diff --git a/services/graph/pkg/service/v0/driveitems_test.go b/services/graph/pkg/service/v0/driveitems_test.go index 88280ef9dd..c692fd8855 100644 --- a/services/graph/pkg/service/v0/driveitems_test.go +++ b/services/graph/pkg/service/v0/driveitems_test.go @@ -85,12 +85,18 @@ var _ = Describe("Driveitems", func() { cfg.Commons = &shared.Commons{} cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - svc, _ = service.NewService( + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + var err error + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.EventsPublisher(&eventsPublisher), service.WithIdentityBackend(identityBackend), ) + Expect(err).ToNot(HaveOccurred()) }) Describe("GetRootDriveChildren", func() { diff --git a/services/graph/pkg/service/v0/educationclasses_test.go b/services/graph/pkg/service/v0/educationclasses_test.go index ecb5e7f02b..9ce013e2a3 100644 --- a/services/graph/pkg/service/v0/educationclasses_test.go +++ b/services/graph/pkg/service/v0/educationclasses_test.go @@ -14,6 +14,13 @@ import ( "github.com/go-chi/chi/v5" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + libregraph "github.com/opencloud-eu/libre-graph-api-go" + revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" + "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" + cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" + "github.com/stretchr/testify/mock" + "google.golang.org/grpc" + "github.com/opencloud-eu/opencloud/pkg/shared" "github.com/opencloud-eu/opencloud/services/graph/mocks" "github.com/opencloud-eu/opencloud/services/graph/pkg/config" @@ -21,12 +28,6 @@ import ( "github.com/opencloud-eu/opencloud/services/graph/pkg/errorcode" identitymocks "github.com/opencloud-eu/opencloud/services/graph/pkg/identity/mocks" service "github.com/opencloud-eu/opencloud/services/graph/pkg/service/v0" - revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" - libregraph "github.com/opencloud-eu/libre-graph-api-go" - "github.com/stretchr/testify/mock" - "google.golang.org/grpc" ) var _ = Describe("EducationClass", func() { @@ -78,13 +79,19 @@ var _ = Describe("EducationClass", func() { cfg.Commons = &shared.Commons{} cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - svc, _ = service.NewService( + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + var err error + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.EventsPublisher(&eventsPublisher), service.WithIdentityBackend(identityBackend), service.WithIdentityEducationBackend(identityEducationBackend), ) + Expect(err).ToNot(HaveOccurred()) }) Describe("GetEducationClasses", func() { @@ -326,13 +333,19 @@ var _ = Describe("EducationClass", func() { Expect(err).ToNot(HaveOccurred()) cfg.API.GroupMembersPatchLimit = 21 - svc, _ = service.NewService( + + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.EventsPublisher(&eventsPublisher), service.WithIdentityBackend(identityBackend), service.WithIdentityEducationBackend(identityEducationBackend), ) + Expect(err).ToNot(HaveOccurred()) r := httptest.NewRequest(http.MethodPatch, "/graph/v1.0/education/classes", bytes.NewBuffer(updatedClassJson)) rctx := chi.NewRouteContext() diff --git a/services/graph/pkg/service/v0/educationschools_test.go b/services/graph/pkg/service/v0/educationschools_test.go index 61cf06d6dd..b00573f0e8 100644 --- a/services/graph/pkg/service/v0/educationschools_test.go +++ b/services/graph/pkg/service/v0/educationschools_test.go @@ -21,13 +21,15 @@ import ( "github.com/stretchr/testify/mock" "google.golang.org/grpc" + libregraph "github.com/opencloud-eu/libre-graph-api-go" + "github.com/opencloud-eu/opencloud/pkg/shared" + "github.com/opencloud-eu/opencloud/services/graph/mocks" "github.com/opencloud-eu/opencloud/services/graph/pkg/config" "github.com/opencloud-eu/opencloud/services/graph/pkg/config/defaults" "github.com/opencloud-eu/opencloud/services/graph/pkg/errorcode" identitymocks "github.com/opencloud-eu/opencloud/services/graph/pkg/identity/mocks" service "github.com/opencloud-eu/opencloud/services/graph/pkg/service/v0" - libregraph "github.com/opencloud-eu/libre-graph-api-go" ) type schoolList struct { @@ -78,11 +80,17 @@ var _ = Describe("Schools", func() { cfg.Commons = &shared.Commons{} cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - svc, _ = service.NewService( + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + var err error + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.WithIdentityEducationBackend(identityEducationBackend), ) + Expect(err).ToNot(HaveOccurred()) }) Describe("GetEducationSchools", func() { diff --git a/services/graph/pkg/service/v0/educationuser_test.go b/services/graph/pkg/service/v0/educationuser_test.go index 1c8ab547c9..a1d5404dee 100644 --- a/services/graph/pkg/service/v0/educationuser_test.go +++ b/services/graph/pkg/service/v0/educationuser_test.go @@ -15,6 +15,14 @@ import ( "github.com/go-chi/chi/v5" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + libregraph "github.com/opencloud-eu/libre-graph-api-go" + revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" + "github.com/opencloud-eu/reva/v2/pkg/rgrpc/status" + "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" + cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" + "github.com/stretchr/testify/mock" + "google.golang.org/grpc" + "github.com/opencloud-eu/opencloud/pkg/shared" settingssvc "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/settings/v0" "github.com/opencloud-eu/opencloud/services/graph/mocks" @@ -22,13 +30,6 @@ import ( "github.com/opencloud-eu/opencloud/services/graph/pkg/config/defaults" identitymocks "github.com/opencloud-eu/opencloud/services/graph/pkg/identity/mocks" service "github.com/opencloud-eu/opencloud/services/graph/pkg/service/v0" - revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/status" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" - libregraph "github.com/opencloud-eu/libre-graph-api-go" - "github.com/stretchr/testify/mock" - "google.golang.org/grpc" ) type educationUserList struct { @@ -80,13 +81,19 @@ var _ = Describe("EducationUsers", func() { cfg.Commons = &shared.Commons{} cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - svc, _ = service.NewService( + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + var err error + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.EventsPublisher(&eventsPublisher), service.WithIdentityEducationBackend(identityEducationBackend), service.WithRoleService(roleService), ) + Expect(err).ToNot(HaveOccurred()) }) Describe("GetEducationUsers", func() { diff --git a/services/graph/pkg/service/v0/graph_test.go b/services/graph/pkg/service/v0/graph_test.go index cb423db2b0..2d7e002e63 100644 --- a/services/graph/pkg/service/v0/graph_test.go +++ b/services/graph/pkg/service/v0/graph_test.go @@ -17,13 +17,13 @@ import ( "github.com/go-chi/chi/v5" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + libregraph "github.com/opencloud-eu/libre-graph-api-go" "github.com/opencloud-eu/reva/v2/pkg/conversions" revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/status" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" "github.com/opencloud-eu/reva/v2/pkg/utils" cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" - libregraph "github.com/opencloud-eu/libre-graph-api-go" "github.com/pkg/errors" "github.com/stretchr/testify/mock" "github.com/tidwall/gjson" @@ -80,12 +80,19 @@ var _ = Describe("Graph", func() { eventsPublisher = mocks.Publisher{} permissionService = mocks.Permissions{} - svc, _ = service.NewService( + + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + var err error + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.EventsPublisher(&eventsPublisher), service.PermissionService(&permissionService), ) + Expect(err).ToNot(HaveOccurred()) }) Describe("NewService", func() { diff --git a/services/graph/pkg/service/v0/groups_test.go b/services/graph/pkg/service/v0/groups_test.go index 94dc9ebb80..4c241a8f76 100644 --- a/services/graph/pkg/service/v0/groups_test.go +++ b/services/graph/pkg/service/v0/groups_test.go @@ -14,6 +14,13 @@ import ( "github.com/go-chi/chi/v5" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + libregraph "github.com/opencloud-eu/libre-graph-api-go" + revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" + "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" + cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" + "github.com/stretchr/testify/mock" + "google.golang.org/grpc" + "github.com/opencloud-eu/opencloud/pkg/shared" settingsmsg "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/messages/settings/v0" settings "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/settings/v0" @@ -23,12 +30,6 @@ import ( "github.com/opencloud-eu/opencloud/services/graph/pkg/errorcode" identitymocks "github.com/opencloud-eu/opencloud/services/graph/pkg/identity/mocks" service "github.com/opencloud-eu/opencloud/services/graph/pkg/service/v0" - revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" - libregraph "github.com/opencloud-eu/libre-graph-api-go" - "github.com/stretchr/testify/mock" - "google.golang.org/grpc" ) type groupList struct { @@ -84,13 +85,19 @@ var _ = Describe("Groups", func() { cfg.Commons = &shared.Commons{} cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - svc, _ = service.NewService( + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + var err error + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.EventsPublisher(&eventsPublisher), service.WithIdentityBackend(identityBackend), service.PermissionService(permissionService), ) + Expect(err).ToNot(HaveOccurred()) }) Describe("GetGroups", func() { @@ -410,13 +417,18 @@ var _ = Describe("Groups", func() { updatedGroupJson, err := json.Marshal(updatedGroup) Expect(err).ToNot(HaveOccurred()) + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + cfg.API.GroupMembersPatchLimit = 21 - svc, _ = service.NewService( + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.EventsPublisher(&eventsPublisher), service.WithIdentityBackend(identityBackend), ) + Expect(err).ToNot(HaveOccurred()) r := httptest.NewRequest(http.MethodPatch, "/graph/v1.0/groups", bytes.NewBuffer(updatedGroupJson)) rctx := chi.NewRouteContext() diff --git a/services/graph/pkg/service/v0/option.go b/services/graph/pkg/service/v0/option.go index 6ed1f13740..ee85e32d9d 100644 --- a/services/graph/pkg/service/v0/option.go +++ b/services/graph/pkg/service/v0/option.go @@ -5,6 +5,11 @@ import ( "net/http" gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" + "github.com/opencloud-eu/reva/v2/pkg/events" + "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" + "github.com/opencloud-eu/reva/v2/pkg/storage/utils/metadata" + "go.opentelemetry.io/otel/trace" + "github.com/opencloud-eu/opencloud/pkg/keycloak" "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/pkg/roles" @@ -13,9 +18,6 @@ import ( settingssvc "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/settings/v0" "github.com/opencloud-eu/opencloud/services/graph/pkg/config" "github.com/opencloud-eu/opencloud/services/graph/pkg/identity" - "github.com/opencloud-eu/reva/v2/pkg/events" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - "go.opentelemetry.io/otel/trace" ) // Option defines a single option function. @@ -41,6 +43,7 @@ type Options struct { KeycloakClient keycloak.Client EventHistoryClient ehsvc.EventHistoryService TraceProvider trace.TracerProvider + Storage metadata.Storage } // newOptions initializes the available default options. @@ -179,3 +182,10 @@ func TraceProvider(val trace.TracerProvider) Option { o.TraceProvider = val } } + +// MetadataStorage provides a function to set the MetadataStorage option. +func MetadataStorage(ms metadata.Storage) Option { + return func(o *Options) { + o.Storage = ms + } +} diff --git a/services/graph/pkg/service/v0/password_test.go b/services/graph/pkg/service/v0/password_test.go index 47d287614f..0ca80c4906 100644 --- a/services/graph/pkg/service/v0/password_test.go +++ b/services/graph/pkg/service/v0/password_test.go @@ -13,6 +13,14 @@ import ( "github.com/go-ldap/ldap/v3" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + libregraph "github.com/opencloud-eu/libre-graph-api-go" + revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" + "github.com/opencloud-eu/reva/v2/pkg/rgrpc/status" + "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" + cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" + "github.com/stretchr/testify/mock" + "google.golang.org/grpc" + "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/pkg/shared" "github.com/opencloud-eu/opencloud/services/graph/mocks" @@ -21,13 +29,6 @@ import ( "github.com/opencloud-eu/opencloud/services/graph/pkg/identity" identitymocks "github.com/opencloud-eu/opencloud/services/graph/pkg/identity/mocks" service "github.com/opencloud-eu/opencloud/services/graph/pkg/service/v0" - revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/status" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" - libregraph "github.com/opencloud-eu/libre-graph-api-go" - "github.com/stretchr/testify/mock" - "google.golang.org/grpc" ) var _ = Describe("Users changing their own password", func() { @@ -74,17 +75,25 @@ var _ = Describe("Users changing their own password", func() { GroupIDAttribute: "openCloudUUID", GroupSearchScope: "sub", } - loggger := log.NewLogger() - identityBackend, err = identity.NewLDAPBackend(ldapClient, ldapConfig, &loggger) + logger := log.NewLogger() + identityBackend, err = identity.NewLDAPBackend(ldapClient, ldapConfig, &logger) Expect(err).To(BeNil()) eventsPublisher = mocks.Publisher{} - svc, _ = service.NewService( + + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + var err error + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.WithIdentityBackend(identityBackend), service.EventsPublisher(&eventsPublisher), ) + Expect(err).ToNot(HaveOccurred()) + user = &userv1beta1.User{ Id: &userv1beta1.UserId{ OpaqueId: "user", diff --git a/services/graph/pkg/service/v0/service.go b/services/graph/pkg/service/v0/service.go index 7236c98b9d..4840f0a4c0 100644 --- a/services/graph/pkg/service/v0/service.go +++ b/services/graph/pkg/service/v0/service.go @@ -19,7 +19,6 @@ import ( "github.com/opencloud-eu/reva/v2/pkg/events" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - "github.com/opencloud-eu/reva/v2/pkg/storage/utils/metadata" "github.com/opencloud-eu/reva/v2/pkg/store" "github.com/opencloud-eu/reva/v2/pkg/utils" @@ -144,17 +143,6 @@ func NewService(opts ...Option) (Graph, error) { //nolint:maintidx identity.IdentityCacheWithGroupsTTL(time.Duration(options.Config.Spaces.GroupsCacheTTL)), ) - storage, err := metadata.NewCS3Storage( - options.Config.Metadata.GatewayAddress, - options.Config.Metadata.StorageAddress, - options.Config.Metadata.SystemUserID, - options.Config.Metadata.SystemUserIDP, - options.Config.Metadata.SystemUserAPIKey, - ) - if err != nil { - return Graph{}, err - } - baseGraphService := BaseGraphService{ logger: &options.Logger, identityCache: identityCache, @@ -183,7 +171,7 @@ func NewService(opts ...Option) (Graph, error) { //nolint:maintidx return Graph{}, err } - usersUserProfilePhotoService, err := NewUsersUserProfilePhotoService(storage) + usersUserProfilePhotoService, err := NewUsersUserProfilePhotoService(options.Storage) if err != nil { return Graph{}, err } diff --git a/services/graph/pkg/service/v0/sharedbyme_test.go b/services/graph/pkg/service/v0/sharedbyme_test.go index c980e12e09..2c58105a53 100644 --- a/services/graph/pkg/service/v0/sharedbyme_test.go +++ b/services/graph/pkg/service/v0/sharedbyme_test.go @@ -17,6 +17,16 @@ import ( provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + libregraph "github.com/opencloud-eu/libre-graph-api-go" + "github.com/opencloud-eu/reva/v2/pkg/conversions" + "github.com/opencloud-eu/reva/v2/pkg/rgrpc/status" + "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" + "github.com/opencloud-eu/reva/v2/pkg/storagespace" + "github.com/opencloud-eu/reva/v2/pkg/utils" + cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" + "github.com/stretchr/testify/mock" + "google.golang.org/grpc" + "github.com/opencloud-eu/opencloud/pkg/shared" "github.com/opencloud-eu/opencloud/services/graph/mocks" "github.com/opencloud-eu/opencloud/services/graph/pkg/config" @@ -25,15 +35,6 @@ import ( "github.com/opencloud-eu/opencloud/services/graph/pkg/linktype" service "github.com/opencloud-eu/opencloud/services/graph/pkg/service/v0" "github.com/opencloud-eu/opencloud/services/graph/pkg/unifiedrole" - "github.com/opencloud-eu/reva/v2/pkg/conversions" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/status" - "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" - "github.com/opencloud-eu/reva/v2/pkg/storagespace" - "github.com/opencloud-eu/reva/v2/pkg/utils" - cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" - libregraph "github.com/opencloud-eu/libre-graph-api-go" - "github.com/stretchr/testify/mock" - "google.golang.org/grpc" ) var _ = Describe("sharedbyme", func() { @@ -245,12 +246,17 @@ var _ = Describe("sharedbyme", func() { cfg.Commons = &shared.Commons{} cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - svc, _ = service.NewService( + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.EventsPublisher(&eventsPublisher), service.WithIdentityBackend(identityBackend), ) + Expect(err).ToNot(HaveOccurred()) }) emptyListPublicSharesMock := func() { diff --git a/services/graph/pkg/service/v0/sharedwithme_test.go b/services/graph/pkg/service/v0/sharedwithme_test.go index 4a3a8c5bf4..08dc95952f 100644 --- a/services/graph/pkg/service/v0/sharedwithme_test.go +++ b/services/graph/pkg/service/v0/sharedwithme_test.go @@ -26,13 +26,15 @@ import ( "google.golang.org/grpc" "google.golang.org/protobuf/proto" + libregraph "github.com/opencloud-eu/libre-graph-api-go" + "github.com/opencloud-eu/opencloud/pkg/shared" + "github.com/opencloud-eu/opencloud/services/graph/mocks" "github.com/opencloud-eu/opencloud/services/graph/pkg/config" "github.com/opencloud-eu/opencloud/services/graph/pkg/config/defaults" "github.com/opencloud-eu/opencloud/services/graph/pkg/errorcode" identitymocks "github.com/opencloud-eu/opencloud/services/graph/pkg/identity/mocks" service "github.com/opencloud-eu/opencloud/services/graph/pkg/service/v0" - libregraph "github.com/opencloud-eu/libre-graph-api-go" // "github.com/opencloud-eu/opencloud/services/graph/pkg/unifiedrole" ) @@ -69,11 +71,17 @@ var _ = Describe("SharedWithMe", func() { cfg.Commons = &shared.Commons{} cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - svc, _ = service.NewService( + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + var err error + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.WithIdentityBackend(identityBackend), ) + Expect(err).ToNot(HaveOccurred()) }) Describe("ListSharedWithMe", func() { diff --git a/services/graph/pkg/service/v0/users_test.go b/services/graph/pkg/service/v0/users_test.go index 7fd8a34ce1..46a0a68e17 100644 --- a/services/graph/pkg/service/v0/users_test.go +++ b/services/graph/pkg/service/v0/users_test.go @@ -17,11 +17,11 @@ import ( "github.com/go-chi/chi/v5" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + libregraph "github.com/opencloud-eu/libre-graph-api-go" revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/status" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks" - libregraph "github.com/opencloud-eu/libre-graph-api-go" "github.com/stretchr/testify/mock" "go-micro.dev/v4/client" "google.golang.org/grpc" @@ -95,8 +95,13 @@ var _ = Describe("Users", func() { When("OCM is disabled", func() { BeforeEach(func() { - svc, _ = service.NewService( + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + var err error + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.EventsPublisher(&eventsPublisher), service.WithIdentityBackend(identityBackend), @@ -104,6 +109,7 @@ var _ = Describe("Users", func() { service.WithValueService(valueService), service.PermissionService(permissionService), ) + Expect(err).ToNot(HaveOccurred()) }) Describe("GetMe", func() { @@ -901,13 +907,18 @@ var _ = Describe("Users", func() { localCfg.API.UsernameMatch = usernameMatch - localSvc, _ := service.NewService( + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + localSvc, err := service.NewService( service.Config(localCfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.EventsPublisher(&eventsPublisher), service.WithIdentityBackend(identityBackend), service.WithRoleService(roleService), ) + Expect(err).ToNot(HaveOccurred()) return localSvc } @@ -1121,8 +1132,14 @@ var _ = Describe("Users", func() { When("OCM is enabled", func() { BeforeEach(func() { cfg.IncludeOCMSharees = true - svc, _ = service.NewService( + + mds := mocks.NewStorage(GinkgoT()) + mds.EXPECT().Init(mock.Anything, mock.Anything).Return(nil) + + var err error + svc, err = service.NewService( service.Config(cfg), + service.MetadataStorage(mds), service.WithGatewaySelector(gatewaySelector), service.EventsPublisher(&eventsPublisher), service.WithIdentityBackend(identityBackend), @@ -1130,6 +1147,7 @@ var _ = Describe("Users", func() { service.WithValueService(valueService), service.PermissionService(permissionService), ) + Expect(err).ToNot(HaveOccurred()) }) Describe("GetUsers", func() { It("does not list the federated users without a filter", func() {