From 45af473464c902960c7c556a47d38c3e820d3f8a Mon Sep 17 00:00:00 2001 From: "yiling.ji" Date: Mon, 23 Dec 2024 05:50:30 +0000 Subject: [PATCH] Merge branch 'feature/handler_tests' into 'main' Add model/user/git-http handler tests See merge request product/starhub/starhub-server!751 --- .mockery.yaml | 3 + .../component/mock_GitHTTPComponent.go | 647 +++++++++ .../component/mock_ModelComponent.go | 1108 ++++++++++++++ .../component/mock_UserComponent.go | 1277 +++++++++++++++++ api/handler/git_http.go | 36 +- api/handler/git_http_test.go | 315 ++++ api/handler/helper_test.go | 26 +- api/handler/model.go | 58 +- api/handler/model_test.go | 561 ++++++++ api/handler/user.go | 52 +- api/handler/user_test.go | 439 ++++++ common/types/user.go | 8 +- component/user.go | 12 +- component/user_test.go | 32 +- 14 files changed, 4470 insertions(+), 104 deletions(-) create mode 100644 _mocks/opencsg.com/csghub-server/component/mock_GitHTTPComponent.go create mode 100644 _mocks/opencsg.com/csghub-server/component/mock_ModelComponent.go create mode 100644 _mocks/opencsg.com/csghub-server/component/mock_UserComponent.go create mode 100644 api/handler/git_http_test.go create mode 100644 api/handler/model_test.go create mode 100644 api/handler/user_test.go diff --git a/.mockery.yaml b/.mockery.yaml index 64fb75b7..04274577 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -19,6 +19,9 @@ packages: SensitiveComponent: CodeComponent: PromptComponent: + ModelComponent: + UserComponent: + GitHTTPComponent: opencsg.com/csghub-server/user/component: config: interfaces: diff --git a/_mocks/opencsg.com/csghub-server/component/mock_GitHTTPComponent.go b/_mocks/opencsg.com/csghub-server/component/mock_GitHTTPComponent.go new file mode 100644 index 00000000..1b10efa4 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/component/mock_GitHTTPComponent.go @@ -0,0 +1,647 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package component + +import ( + context "context" + io "io" + + database "opencsg.com/csghub-server/builder/store/database" + + mock "github.com/stretchr/testify/mock" + + types "opencsg.com/csghub-server/common/types" + + url "net/url" +) + +// MockGitHTTPComponent is an autogenerated mock type for the GitHTTPComponent type +type MockGitHTTPComponent struct { + mock.Mock +} + +type MockGitHTTPComponent_Expecter struct { + mock *mock.Mock +} + +func (_m *MockGitHTTPComponent) EXPECT() *MockGitHTTPComponent_Expecter { + return &MockGitHTTPComponent_Expecter{mock: &_m.Mock} +} + +// BuildObjectResponse provides a mock function with given fields: ctx, req, isUpload +func (_m *MockGitHTTPComponent) BuildObjectResponse(ctx context.Context, req types.BatchRequest, isUpload bool) (*types.BatchResponse, error) { + ret := _m.Called(ctx, req, isUpload) + + if len(ret) == 0 { + panic("no return value specified for BuildObjectResponse") + } + + var r0 *types.BatchResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.BatchRequest, bool) (*types.BatchResponse, error)); ok { + return rf(ctx, req, isUpload) + } + if rf, ok := ret.Get(0).(func(context.Context, types.BatchRequest, bool) *types.BatchResponse); ok { + r0 = rf(ctx, req, isUpload) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.BatchResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.BatchRequest, bool) error); ok { + r1 = rf(ctx, req, isUpload) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitHTTPComponent_BuildObjectResponse_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BuildObjectResponse' +type MockGitHTTPComponent_BuildObjectResponse_Call struct { + *mock.Call +} + +// BuildObjectResponse is a helper method to define mock.On call +// - ctx context.Context +// - req types.BatchRequest +// - isUpload bool +func (_e *MockGitHTTPComponent_Expecter) BuildObjectResponse(ctx interface{}, req interface{}, isUpload interface{}) *MockGitHTTPComponent_BuildObjectResponse_Call { + return &MockGitHTTPComponent_BuildObjectResponse_Call{Call: _e.mock.On("BuildObjectResponse", ctx, req, isUpload)} +} + +func (_c *MockGitHTTPComponent_BuildObjectResponse_Call) Run(run func(ctx context.Context, req types.BatchRequest, isUpload bool)) *MockGitHTTPComponent_BuildObjectResponse_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.BatchRequest), args[2].(bool)) + }) + return _c +} + +func (_c *MockGitHTTPComponent_BuildObjectResponse_Call) Return(_a0 *types.BatchResponse, _a1 error) *MockGitHTTPComponent_BuildObjectResponse_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitHTTPComponent_BuildObjectResponse_Call) RunAndReturn(run func(context.Context, types.BatchRequest, bool) (*types.BatchResponse, error)) *MockGitHTTPComponent_BuildObjectResponse_Call { + _c.Call.Return(run) + return _c +} + +// CreateLock provides a mock function with given fields: ctx, req +func (_m *MockGitHTTPComponent) CreateLock(ctx context.Context, req types.LfsLockReq) (*database.LfsLock, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for CreateLock") + } + + var r0 *database.LfsLock + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.LfsLockReq) (*database.LfsLock, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.LfsLockReq) *database.LfsLock); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.LfsLock) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.LfsLockReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitHTTPComponent_CreateLock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateLock' +type MockGitHTTPComponent_CreateLock_Call struct { + *mock.Call +} + +// CreateLock is a helper method to define mock.On call +// - ctx context.Context +// - req types.LfsLockReq +func (_e *MockGitHTTPComponent_Expecter) CreateLock(ctx interface{}, req interface{}) *MockGitHTTPComponent_CreateLock_Call { + return &MockGitHTTPComponent_CreateLock_Call{Call: _e.mock.On("CreateLock", ctx, req)} +} + +func (_c *MockGitHTTPComponent_CreateLock_Call) Run(run func(ctx context.Context, req types.LfsLockReq)) *MockGitHTTPComponent_CreateLock_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.LfsLockReq)) + }) + return _c +} + +func (_c *MockGitHTTPComponent_CreateLock_Call) Return(_a0 *database.LfsLock, _a1 error) *MockGitHTTPComponent_CreateLock_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitHTTPComponent_CreateLock_Call) RunAndReturn(run func(context.Context, types.LfsLockReq) (*database.LfsLock, error)) *MockGitHTTPComponent_CreateLock_Call { + _c.Call.Return(run) + return _c +} + +// GitReceivePack provides a mock function with given fields: ctx, req +func (_m *MockGitHTTPComponent) GitReceivePack(ctx context.Context, req types.GitReceivePackReq) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GitReceivePack") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.GitReceivePackReq) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitHTTPComponent_GitReceivePack_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GitReceivePack' +type MockGitHTTPComponent_GitReceivePack_Call struct { + *mock.Call +} + +// GitReceivePack is a helper method to define mock.On call +// - ctx context.Context +// - req types.GitReceivePackReq +func (_e *MockGitHTTPComponent_Expecter) GitReceivePack(ctx interface{}, req interface{}) *MockGitHTTPComponent_GitReceivePack_Call { + return &MockGitHTTPComponent_GitReceivePack_Call{Call: _e.mock.On("GitReceivePack", ctx, req)} +} + +func (_c *MockGitHTTPComponent_GitReceivePack_Call) Run(run func(ctx context.Context, req types.GitReceivePackReq)) *MockGitHTTPComponent_GitReceivePack_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.GitReceivePackReq)) + }) + return _c +} + +func (_c *MockGitHTTPComponent_GitReceivePack_Call) Return(_a0 error) *MockGitHTTPComponent_GitReceivePack_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitHTTPComponent_GitReceivePack_Call) RunAndReturn(run func(context.Context, types.GitReceivePackReq) error) *MockGitHTTPComponent_GitReceivePack_Call { + _c.Call.Return(run) + return _c +} + +// GitUploadPack provides a mock function with given fields: ctx, req +func (_m *MockGitHTTPComponent) GitUploadPack(ctx context.Context, req types.GitUploadPackReq) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GitUploadPack") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.GitUploadPackReq) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitHTTPComponent_GitUploadPack_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GitUploadPack' +type MockGitHTTPComponent_GitUploadPack_Call struct { + *mock.Call +} + +// GitUploadPack is a helper method to define mock.On call +// - ctx context.Context +// - req types.GitUploadPackReq +func (_e *MockGitHTTPComponent_Expecter) GitUploadPack(ctx interface{}, req interface{}) *MockGitHTTPComponent_GitUploadPack_Call { + return &MockGitHTTPComponent_GitUploadPack_Call{Call: _e.mock.On("GitUploadPack", ctx, req)} +} + +func (_c *MockGitHTTPComponent_GitUploadPack_Call) Run(run func(ctx context.Context, req types.GitUploadPackReq)) *MockGitHTTPComponent_GitUploadPack_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.GitUploadPackReq)) + }) + return _c +} + +func (_c *MockGitHTTPComponent_GitUploadPack_Call) Return(_a0 error) *MockGitHTTPComponent_GitUploadPack_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitHTTPComponent_GitUploadPack_Call) RunAndReturn(run func(context.Context, types.GitUploadPackReq) error) *MockGitHTTPComponent_GitUploadPack_Call { + _c.Call.Return(run) + return _c +} + +// InfoRefs provides a mock function with given fields: ctx, req +func (_m *MockGitHTTPComponent) InfoRefs(ctx context.Context, req types.InfoRefsReq) (io.Reader, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for InfoRefs") + } + + var r0 io.Reader + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.InfoRefsReq) (io.Reader, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.InfoRefsReq) io.Reader); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(io.Reader) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.InfoRefsReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitHTTPComponent_InfoRefs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'InfoRefs' +type MockGitHTTPComponent_InfoRefs_Call struct { + *mock.Call +} + +// InfoRefs is a helper method to define mock.On call +// - ctx context.Context +// - req types.InfoRefsReq +func (_e *MockGitHTTPComponent_Expecter) InfoRefs(ctx interface{}, req interface{}) *MockGitHTTPComponent_InfoRefs_Call { + return &MockGitHTTPComponent_InfoRefs_Call{Call: _e.mock.On("InfoRefs", ctx, req)} +} + +func (_c *MockGitHTTPComponent_InfoRefs_Call) Run(run func(ctx context.Context, req types.InfoRefsReq)) *MockGitHTTPComponent_InfoRefs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.InfoRefsReq)) + }) + return _c +} + +func (_c *MockGitHTTPComponent_InfoRefs_Call) Return(_a0 io.Reader, _a1 error) *MockGitHTTPComponent_InfoRefs_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitHTTPComponent_InfoRefs_Call) RunAndReturn(run func(context.Context, types.InfoRefsReq) (io.Reader, error)) *MockGitHTTPComponent_InfoRefs_Call { + _c.Call.Return(run) + return _c +} + +// LfsDownload provides a mock function with given fields: ctx, req +func (_m *MockGitHTTPComponent) LfsDownload(ctx context.Context, req types.DownloadRequest) (*url.URL, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for LfsDownload") + } + + var r0 *url.URL + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.DownloadRequest) (*url.URL, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DownloadRequest) *url.URL); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*url.URL) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DownloadRequest) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitHTTPComponent_LfsDownload_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LfsDownload' +type MockGitHTTPComponent_LfsDownload_Call struct { + *mock.Call +} + +// LfsDownload is a helper method to define mock.On call +// - ctx context.Context +// - req types.DownloadRequest +func (_e *MockGitHTTPComponent_Expecter) LfsDownload(ctx interface{}, req interface{}) *MockGitHTTPComponent_LfsDownload_Call { + return &MockGitHTTPComponent_LfsDownload_Call{Call: _e.mock.On("LfsDownload", ctx, req)} +} + +func (_c *MockGitHTTPComponent_LfsDownload_Call) Run(run func(ctx context.Context, req types.DownloadRequest)) *MockGitHTTPComponent_LfsDownload_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DownloadRequest)) + }) + return _c +} + +func (_c *MockGitHTTPComponent_LfsDownload_Call) Return(_a0 *url.URL, _a1 error) *MockGitHTTPComponent_LfsDownload_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitHTTPComponent_LfsDownload_Call) RunAndReturn(run func(context.Context, types.DownloadRequest) (*url.URL, error)) *MockGitHTTPComponent_LfsDownload_Call { + _c.Call.Return(run) + return _c +} + +// LfsUpload provides a mock function with given fields: ctx, body, req +func (_m *MockGitHTTPComponent) LfsUpload(ctx context.Context, body io.ReadCloser, req types.UploadRequest) error { + ret := _m.Called(ctx, body, req) + + if len(ret) == 0 { + panic("no return value specified for LfsUpload") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, io.ReadCloser, types.UploadRequest) error); ok { + r0 = rf(ctx, body, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitHTTPComponent_LfsUpload_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LfsUpload' +type MockGitHTTPComponent_LfsUpload_Call struct { + *mock.Call +} + +// LfsUpload is a helper method to define mock.On call +// - ctx context.Context +// - body io.ReadCloser +// - req types.UploadRequest +func (_e *MockGitHTTPComponent_Expecter) LfsUpload(ctx interface{}, body interface{}, req interface{}) *MockGitHTTPComponent_LfsUpload_Call { + return &MockGitHTTPComponent_LfsUpload_Call{Call: _e.mock.On("LfsUpload", ctx, body, req)} +} + +func (_c *MockGitHTTPComponent_LfsUpload_Call) Run(run func(ctx context.Context, body io.ReadCloser, req types.UploadRequest)) *MockGitHTTPComponent_LfsUpload_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(io.ReadCloser), args[2].(types.UploadRequest)) + }) + return _c +} + +func (_c *MockGitHTTPComponent_LfsUpload_Call) Return(_a0 error) *MockGitHTTPComponent_LfsUpload_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitHTTPComponent_LfsUpload_Call) RunAndReturn(run func(context.Context, io.ReadCloser, types.UploadRequest) error) *MockGitHTTPComponent_LfsUpload_Call { + _c.Call.Return(run) + return _c +} + +// LfsVerify provides a mock function with given fields: ctx, req, p +func (_m *MockGitHTTPComponent) LfsVerify(ctx context.Context, req types.VerifyRequest, p types.Pointer) error { + ret := _m.Called(ctx, req, p) + + if len(ret) == 0 { + panic("no return value specified for LfsVerify") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.VerifyRequest, types.Pointer) error); ok { + r0 = rf(ctx, req, p) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitHTTPComponent_LfsVerify_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LfsVerify' +type MockGitHTTPComponent_LfsVerify_Call struct { + *mock.Call +} + +// LfsVerify is a helper method to define mock.On call +// - ctx context.Context +// - req types.VerifyRequest +// - p types.Pointer +func (_e *MockGitHTTPComponent_Expecter) LfsVerify(ctx interface{}, req interface{}, p interface{}) *MockGitHTTPComponent_LfsVerify_Call { + return &MockGitHTTPComponent_LfsVerify_Call{Call: _e.mock.On("LfsVerify", ctx, req, p)} +} + +func (_c *MockGitHTTPComponent_LfsVerify_Call) Run(run func(ctx context.Context, req types.VerifyRequest, p types.Pointer)) *MockGitHTTPComponent_LfsVerify_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.VerifyRequest), args[2].(types.Pointer)) + }) + return _c +} + +func (_c *MockGitHTTPComponent_LfsVerify_Call) Return(_a0 error) *MockGitHTTPComponent_LfsVerify_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitHTTPComponent_LfsVerify_Call) RunAndReturn(run func(context.Context, types.VerifyRequest, types.Pointer) error) *MockGitHTTPComponent_LfsVerify_Call { + _c.Call.Return(run) + return _c +} + +// ListLocks provides a mock function with given fields: ctx, req +func (_m *MockGitHTTPComponent) ListLocks(ctx context.Context, req types.ListLFSLockReq) (*types.LFSLockList, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for ListLocks") + } + + var r0 *types.LFSLockList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.ListLFSLockReq) (*types.LFSLockList, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.ListLFSLockReq) *types.LFSLockList); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.LFSLockList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.ListLFSLockReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitHTTPComponent_ListLocks_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListLocks' +type MockGitHTTPComponent_ListLocks_Call struct { + *mock.Call +} + +// ListLocks is a helper method to define mock.On call +// - ctx context.Context +// - req types.ListLFSLockReq +func (_e *MockGitHTTPComponent_Expecter) ListLocks(ctx interface{}, req interface{}) *MockGitHTTPComponent_ListLocks_Call { + return &MockGitHTTPComponent_ListLocks_Call{Call: _e.mock.On("ListLocks", ctx, req)} +} + +func (_c *MockGitHTTPComponent_ListLocks_Call) Run(run func(ctx context.Context, req types.ListLFSLockReq)) *MockGitHTTPComponent_ListLocks_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.ListLFSLockReq)) + }) + return _c +} + +func (_c *MockGitHTTPComponent_ListLocks_Call) Return(_a0 *types.LFSLockList, _a1 error) *MockGitHTTPComponent_ListLocks_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitHTTPComponent_ListLocks_Call) RunAndReturn(run func(context.Context, types.ListLFSLockReq) (*types.LFSLockList, error)) *MockGitHTTPComponent_ListLocks_Call { + _c.Call.Return(run) + return _c +} + +// UnLock provides a mock function with given fields: ctx, req +func (_m *MockGitHTTPComponent) UnLock(ctx context.Context, req types.UnlockLFSReq) (*database.LfsLock, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for UnLock") + } + + var r0 *database.LfsLock + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.UnlockLFSReq) (*database.LfsLock, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.UnlockLFSReq) *database.LfsLock); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.LfsLock) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.UnlockLFSReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitHTTPComponent_UnLock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UnLock' +type MockGitHTTPComponent_UnLock_Call struct { + *mock.Call +} + +// UnLock is a helper method to define mock.On call +// - ctx context.Context +// - req types.UnlockLFSReq +func (_e *MockGitHTTPComponent_Expecter) UnLock(ctx interface{}, req interface{}) *MockGitHTTPComponent_UnLock_Call { + return &MockGitHTTPComponent_UnLock_Call{Call: _e.mock.On("UnLock", ctx, req)} +} + +func (_c *MockGitHTTPComponent_UnLock_Call) Run(run func(ctx context.Context, req types.UnlockLFSReq)) *MockGitHTTPComponent_UnLock_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.UnlockLFSReq)) + }) + return _c +} + +func (_c *MockGitHTTPComponent_UnLock_Call) Return(_a0 *database.LfsLock, _a1 error) *MockGitHTTPComponent_UnLock_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitHTTPComponent_UnLock_Call) RunAndReturn(run func(context.Context, types.UnlockLFSReq) (*database.LfsLock, error)) *MockGitHTTPComponent_UnLock_Call { + _c.Call.Return(run) + return _c +} + +// VerifyLock provides a mock function with given fields: ctx, req +func (_m *MockGitHTTPComponent) VerifyLock(ctx context.Context, req types.VerifyLFSLockReq) (*types.LFSLockListVerify, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for VerifyLock") + } + + var r0 *types.LFSLockListVerify + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.VerifyLFSLockReq) (*types.LFSLockListVerify, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.VerifyLFSLockReq) *types.LFSLockListVerify); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.LFSLockListVerify) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.VerifyLFSLockReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitHTTPComponent_VerifyLock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'VerifyLock' +type MockGitHTTPComponent_VerifyLock_Call struct { + *mock.Call +} + +// VerifyLock is a helper method to define mock.On call +// - ctx context.Context +// - req types.VerifyLFSLockReq +func (_e *MockGitHTTPComponent_Expecter) VerifyLock(ctx interface{}, req interface{}) *MockGitHTTPComponent_VerifyLock_Call { + return &MockGitHTTPComponent_VerifyLock_Call{Call: _e.mock.On("VerifyLock", ctx, req)} +} + +func (_c *MockGitHTTPComponent_VerifyLock_Call) Run(run func(ctx context.Context, req types.VerifyLFSLockReq)) *MockGitHTTPComponent_VerifyLock_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.VerifyLFSLockReq)) + }) + return _c +} + +func (_c *MockGitHTTPComponent_VerifyLock_Call) Return(_a0 *types.LFSLockListVerify, _a1 error) *MockGitHTTPComponent_VerifyLock_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitHTTPComponent_VerifyLock_Call) RunAndReturn(run func(context.Context, types.VerifyLFSLockReq) (*types.LFSLockListVerify, error)) *MockGitHTTPComponent_VerifyLock_Call { + _c.Call.Return(run) + return _c +} + +// NewMockGitHTTPComponent creates a new instance of MockGitHTTPComponent. 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 NewMockGitHTTPComponent(t interface { + mock.TestingT + Cleanup(func()) +}) *MockGitHTTPComponent { + mock := &MockGitHTTPComponent{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/component/mock_ModelComponent.go b/_mocks/opencsg.com/csghub-server/component/mock_ModelComponent.go new file mode 100644 index 00000000..fc5bc4d2 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/component/mock_ModelComponent.go @@ -0,0 +1,1108 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package component + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" + + types "opencsg.com/csghub-server/common/types" +) + +// MockModelComponent is an autogenerated mock type for the ModelComponent type +type MockModelComponent struct { + mock.Mock +} + +type MockModelComponent_Expecter struct { + mock *mock.Mock +} + +func (_m *MockModelComponent) EXPECT() *MockModelComponent_Expecter { + return &MockModelComponent_Expecter{mock: &_m.Mock} +} + +// AddRelationDataset provides a mock function with given fields: ctx, req +func (_m *MockModelComponent) AddRelationDataset(ctx context.Context, req types.RelationDataset) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for AddRelationDataset") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.RelationDataset) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockModelComponent_AddRelationDataset_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddRelationDataset' +type MockModelComponent_AddRelationDataset_Call struct { + *mock.Call +} + +// AddRelationDataset is a helper method to define mock.On call +// - ctx context.Context +// - req types.RelationDataset +func (_e *MockModelComponent_Expecter) AddRelationDataset(ctx interface{}, req interface{}) *MockModelComponent_AddRelationDataset_Call { + return &MockModelComponent_AddRelationDataset_Call{Call: _e.mock.On("AddRelationDataset", ctx, req)} +} + +func (_c *MockModelComponent_AddRelationDataset_Call) Run(run func(ctx context.Context, req types.RelationDataset)) *MockModelComponent_AddRelationDataset_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RelationDataset)) + }) + return _c +} + +func (_c *MockModelComponent_AddRelationDataset_Call) Return(_a0 error) *MockModelComponent_AddRelationDataset_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockModelComponent_AddRelationDataset_Call) RunAndReturn(run func(context.Context, types.RelationDataset) error) *MockModelComponent_AddRelationDataset_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, req +func (_m *MockModelComponent) Create(ctx context.Context, req *types.CreateModelReq) (*types.Model, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *types.Model + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.CreateModelReq) (*types.Model, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.CreateModelReq) *types.Model); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.CreateModelReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelComponent_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockModelComponent_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - req *types.CreateModelReq +func (_e *MockModelComponent_Expecter) Create(ctx interface{}, req interface{}) *MockModelComponent_Create_Call { + return &MockModelComponent_Create_Call{Call: _e.mock.On("Create", ctx, req)} +} + +func (_c *MockModelComponent_Create_Call) Run(run func(ctx context.Context, req *types.CreateModelReq)) *MockModelComponent_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.CreateModelReq)) + }) + return _c +} + +func (_c *MockModelComponent_Create_Call) Return(_a0 *types.Model, _a1 error) *MockModelComponent_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelComponent_Create_Call) RunAndReturn(run func(context.Context, *types.CreateModelReq) (*types.Model, error)) *MockModelComponent_Create_Call { + _c.Call.Return(run) + return _c +} + +// DelRelationDataset provides a mock function with given fields: ctx, req +func (_m *MockModelComponent) DelRelationDataset(ctx context.Context, req types.RelationDataset) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for DelRelationDataset") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.RelationDataset) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockModelComponent_DelRelationDataset_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DelRelationDataset' +type MockModelComponent_DelRelationDataset_Call struct { + *mock.Call +} + +// DelRelationDataset is a helper method to define mock.On call +// - ctx context.Context +// - req types.RelationDataset +func (_e *MockModelComponent_Expecter) DelRelationDataset(ctx interface{}, req interface{}) *MockModelComponent_DelRelationDataset_Call { + return &MockModelComponent_DelRelationDataset_Call{Call: _e.mock.On("DelRelationDataset", ctx, req)} +} + +func (_c *MockModelComponent_DelRelationDataset_Call) Run(run func(ctx context.Context, req types.RelationDataset)) *MockModelComponent_DelRelationDataset_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RelationDataset)) + }) + return _c +} + +func (_c *MockModelComponent_DelRelationDataset_Call) Return(_a0 error) *MockModelComponent_DelRelationDataset_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockModelComponent_DelRelationDataset_Call) RunAndReturn(run func(context.Context, types.RelationDataset) error) *MockModelComponent_DelRelationDataset_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, namespace, name, currentUser +func (_m *MockModelComponent) Delete(ctx context.Context, namespace string, name string, currentUser string) error { + ret := _m.Called(ctx, namespace, name, currentUser) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) error); ok { + r0 = rf(ctx, namespace, name, currentUser) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockModelComponent_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockModelComponent_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +// - currentUser string +func (_e *MockModelComponent_Expecter) Delete(ctx interface{}, namespace interface{}, name interface{}, currentUser interface{}) *MockModelComponent_Delete_Call { + return &MockModelComponent_Delete_Call{Call: _e.mock.On("Delete", ctx, namespace, name, currentUser)} +} + +func (_c *MockModelComponent_Delete_Call) Run(run func(ctx context.Context, namespace string, name string, currentUser string)) *MockModelComponent_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockModelComponent_Delete_Call) Return(_a0 error) *MockModelComponent_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockModelComponent_Delete_Call) RunAndReturn(run func(context.Context, string, string, string) error) *MockModelComponent_Delete_Call { + _c.Call.Return(run) + return _c +} + +// DeleteRuntimeFrameworkModes provides a mock function with given fields: ctx, deployType, id, paths +func (_m *MockModelComponent) DeleteRuntimeFrameworkModes(ctx context.Context, deployType int, id int64, paths []string) ([]string, error) { + ret := _m.Called(ctx, deployType, id, paths) + + if len(ret) == 0 { + panic("no return value specified for DeleteRuntimeFrameworkModes") + } + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int, int64, []string) ([]string, error)); ok { + return rf(ctx, deployType, id, paths) + } + if rf, ok := ret.Get(0).(func(context.Context, int, int64, []string) []string); ok { + r0 = rf(ctx, deployType, id, paths) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int, int64, []string) error); ok { + r1 = rf(ctx, deployType, id, paths) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelComponent_DeleteRuntimeFrameworkModes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteRuntimeFrameworkModes' +type MockModelComponent_DeleteRuntimeFrameworkModes_Call struct { + *mock.Call +} + +// DeleteRuntimeFrameworkModes is a helper method to define mock.On call +// - ctx context.Context +// - deployType int +// - id int64 +// - paths []string +func (_e *MockModelComponent_Expecter) DeleteRuntimeFrameworkModes(ctx interface{}, deployType interface{}, id interface{}, paths interface{}) *MockModelComponent_DeleteRuntimeFrameworkModes_Call { + return &MockModelComponent_DeleteRuntimeFrameworkModes_Call{Call: _e.mock.On("DeleteRuntimeFrameworkModes", ctx, deployType, id, paths)} +} + +func (_c *MockModelComponent_DeleteRuntimeFrameworkModes_Call) Run(run func(ctx context.Context, deployType int, id int64, paths []string)) *MockModelComponent_DeleteRuntimeFrameworkModes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int), args[2].(int64), args[3].([]string)) + }) + return _c +} + +func (_c *MockModelComponent_DeleteRuntimeFrameworkModes_Call) Return(_a0 []string, _a1 error) *MockModelComponent_DeleteRuntimeFrameworkModes_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelComponent_DeleteRuntimeFrameworkModes_Call) RunAndReturn(run func(context.Context, int, int64, []string) ([]string, error)) *MockModelComponent_DeleteRuntimeFrameworkModes_Call { + _c.Call.Return(run) + return _c +} + +// Deploy provides a mock function with given fields: ctx, deployReq, req +func (_m *MockModelComponent) Deploy(ctx context.Context, deployReq types.DeployActReq, req types.ModelRunReq) (int64, error) { + ret := _m.Called(ctx, deployReq, req) + + if len(ret) == 0 { + panic("no return value specified for Deploy") + } + + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployActReq, types.ModelRunReq) (int64, error)); ok { + return rf(ctx, deployReq, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DeployActReq, types.ModelRunReq) int64); ok { + r0 = rf(ctx, deployReq, req) + } else { + r0 = ret.Get(0).(int64) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DeployActReq, types.ModelRunReq) error); ok { + r1 = rf(ctx, deployReq, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelComponent_Deploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Deploy' +type MockModelComponent_Deploy_Call struct { + *mock.Call +} + +// Deploy is a helper method to define mock.On call +// - ctx context.Context +// - deployReq types.DeployActReq +// - req types.ModelRunReq +func (_e *MockModelComponent_Expecter) Deploy(ctx interface{}, deployReq interface{}, req interface{}) *MockModelComponent_Deploy_Call { + return &MockModelComponent_Deploy_Call{Call: _e.mock.On("Deploy", ctx, deployReq, req)} +} + +func (_c *MockModelComponent_Deploy_Call) Run(run func(ctx context.Context, deployReq types.DeployActReq, req types.ModelRunReq)) *MockModelComponent_Deploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployActReq), args[2].(types.ModelRunReq)) + }) + return _c +} + +func (_c *MockModelComponent_Deploy_Call) Return(_a0 int64, _a1 error) *MockModelComponent_Deploy_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelComponent_Deploy_Call) RunAndReturn(run func(context.Context, types.DeployActReq, types.ModelRunReq) (int64, error)) *MockModelComponent_Deploy_Call { + _c.Call.Return(run) + return _c +} + +// GetServerless provides a mock function with given fields: ctx, namespace, name, currentUser +func (_m *MockModelComponent) GetServerless(ctx context.Context, namespace string, name string, currentUser string) (*types.DeployRepo, error) { + ret := _m.Called(ctx, namespace, name, currentUser) + + if len(ret) == 0 { + panic("no return value specified for GetServerless") + } + + var r0 *types.DeployRepo + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) (*types.DeployRepo, error)); ok { + return rf(ctx, namespace, name, currentUser) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *types.DeployRepo); ok { + r0 = rf(ctx, namespace, name, currentUser) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.DeployRepo) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok { + r1 = rf(ctx, namespace, name, currentUser) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelComponent_GetServerless_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetServerless' +type MockModelComponent_GetServerless_Call struct { + *mock.Call +} + +// GetServerless is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +// - currentUser string +func (_e *MockModelComponent_Expecter) GetServerless(ctx interface{}, namespace interface{}, name interface{}, currentUser interface{}) *MockModelComponent_GetServerless_Call { + return &MockModelComponent_GetServerless_Call{Call: _e.mock.On("GetServerless", ctx, namespace, name, currentUser)} +} + +func (_c *MockModelComponent_GetServerless_Call) Run(run func(ctx context.Context, namespace string, name string, currentUser string)) *MockModelComponent_GetServerless_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockModelComponent_GetServerless_Call) Return(_a0 *types.DeployRepo, _a1 error) *MockModelComponent_GetServerless_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelComponent_GetServerless_Call) RunAndReturn(run func(context.Context, string, string, string) (*types.DeployRepo, error)) *MockModelComponent_GetServerless_Call { + _c.Call.Return(run) + return _c +} + +// Index provides a mock function with given fields: ctx, filter, per, page, needOpWeight +func (_m *MockModelComponent) Index(ctx context.Context, filter *types.RepoFilter, per int, page int, needOpWeight bool) ([]*types.Model, int, error) { + ret := _m.Called(ctx, filter, per, page, needOpWeight) + + if len(ret) == 0 { + panic("no return value specified for Index") + } + + var r0 []*types.Model + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.RepoFilter, int, int, bool) ([]*types.Model, int, error)); ok { + return rf(ctx, filter, per, page, needOpWeight) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.RepoFilter, int, int, bool) []*types.Model); ok { + r0 = rf(ctx, filter, per, page, needOpWeight) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*types.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.RepoFilter, int, int, bool) int); ok { + r1 = rf(ctx, filter, per, page, needOpWeight) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.RepoFilter, int, int, bool) error); ok { + r2 = rf(ctx, filter, per, page, needOpWeight) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockModelComponent_Index_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Index' +type MockModelComponent_Index_Call struct { + *mock.Call +} + +// Index is a helper method to define mock.On call +// - ctx context.Context +// - filter *types.RepoFilter +// - per int +// - page int +// - needOpWeight bool +func (_e *MockModelComponent_Expecter) Index(ctx interface{}, filter interface{}, per interface{}, page interface{}, needOpWeight interface{}) *MockModelComponent_Index_Call { + return &MockModelComponent_Index_Call{Call: _e.mock.On("Index", ctx, filter, per, page, needOpWeight)} +} + +func (_c *MockModelComponent_Index_Call) Run(run func(ctx context.Context, filter *types.RepoFilter, per int, page int, needOpWeight bool)) *MockModelComponent_Index_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.RepoFilter), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockModelComponent_Index_Call) Return(_a0 []*types.Model, _a1 int, _a2 error) *MockModelComponent_Index_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockModelComponent_Index_Call) RunAndReturn(run func(context.Context, *types.RepoFilter, int, int, bool) ([]*types.Model, int, error)) *MockModelComponent_Index_Call { + _c.Call.Return(run) + return _c +} + +// ListAllByRuntimeFramework provides a mock function with given fields: ctx, currentUser +func (_m *MockModelComponent) ListAllByRuntimeFramework(ctx context.Context, currentUser string) ([]database.RuntimeFramework, error) { + ret := _m.Called(ctx, currentUser) + + if len(ret) == 0 { + panic("no return value specified for ListAllByRuntimeFramework") + } + + var r0 []database.RuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) ([]database.RuntimeFramework, error)); ok { + return rf(ctx, currentUser) + } + if rf, ok := ret.Get(0).(func(context.Context, string) []database.RuntimeFramework); ok { + r0 = rf(ctx, currentUser) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, currentUser) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelComponent_ListAllByRuntimeFramework_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListAllByRuntimeFramework' +type MockModelComponent_ListAllByRuntimeFramework_Call struct { + *mock.Call +} + +// ListAllByRuntimeFramework is a helper method to define mock.On call +// - ctx context.Context +// - currentUser string +func (_e *MockModelComponent_Expecter) ListAllByRuntimeFramework(ctx interface{}, currentUser interface{}) *MockModelComponent_ListAllByRuntimeFramework_Call { + return &MockModelComponent_ListAllByRuntimeFramework_Call{Call: _e.mock.On("ListAllByRuntimeFramework", ctx, currentUser)} +} + +func (_c *MockModelComponent_ListAllByRuntimeFramework_Call) Run(run func(ctx context.Context, currentUser string)) *MockModelComponent_ListAllByRuntimeFramework_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockModelComponent_ListAllByRuntimeFramework_Call) Return(_a0 []database.RuntimeFramework, _a1 error) *MockModelComponent_ListAllByRuntimeFramework_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelComponent_ListAllByRuntimeFramework_Call) RunAndReturn(run func(context.Context, string) ([]database.RuntimeFramework, error)) *MockModelComponent_ListAllByRuntimeFramework_Call { + _c.Call.Return(run) + return _c +} + +// ListModelsByRuntimeFrameworkID provides a mock function with given fields: ctx, currentUser, per, page, id, deployType +func (_m *MockModelComponent) ListModelsByRuntimeFrameworkID(ctx context.Context, currentUser string, per int, page int, id int64, deployType int) ([]types.Model, int, error) { + ret := _m.Called(ctx, currentUser, per, page, id, deployType) + + if len(ret) == 0 { + panic("no return value specified for ListModelsByRuntimeFrameworkID") + } + + var r0 []types.Model + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, int64, int) ([]types.Model, int, error)); ok { + return rf(ctx, currentUser, per, page, id, deployType) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, int64, int) []types.Model); ok { + r0 = rf(ctx, currentUser, per, page, id, deployType) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int, int64, int) int); ok { + r1 = rf(ctx, currentUser, per, page, id, deployType) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int, int64, int) error); ok { + r2 = rf(ctx, currentUser, per, page, id, deployType) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockModelComponent_ListModelsByRuntimeFrameworkID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListModelsByRuntimeFrameworkID' +type MockModelComponent_ListModelsByRuntimeFrameworkID_Call struct { + *mock.Call +} + +// ListModelsByRuntimeFrameworkID is a helper method to define mock.On call +// - ctx context.Context +// - currentUser string +// - per int +// - page int +// - id int64 +// - deployType int +func (_e *MockModelComponent_Expecter) ListModelsByRuntimeFrameworkID(ctx interface{}, currentUser interface{}, per interface{}, page interface{}, id interface{}, deployType interface{}) *MockModelComponent_ListModelsByRuntimeFrameworkID_Call { + return &MockModelComponent_ListModelsByRuntimeFrameworkID_Call{Call: _e.mock.On("ListModelsByRuntimeFrameworkID", ctx, currentUser, per, page, id, deployType)} +} + +func (_c *MockModelComponent_ListModelsByRuntimeFrameworkID_Call) Run(run func(ctx context.Context, currentUser string, per int, page int, id int64, deployType int)) *MockModelComponent_ListModelsByRuntimeFrameworkID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int), args[4].(int64), args[5].(int)) + }) + return _c +} + +func (_c *MockModelComponent_ListModelsByRuntimeFrameworkID_Call) Return(_a0 []types.Model, _a1 int, _a2 error) *MockModelComponent_ListModelsByRuntimeFrameworkID_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockModelComponent_ListModelsByRuntimeFrameworkID_Call) RunAndReturn(run func(context.Context, string, int, int, int64, int) ([]types.Model, int, error)) *MockModelComponent_ListModelsByRuntimeFrameworkID_Call { + _c.Call.Return(run) + return _c +} + +// ListModelsOfRuntimeFrameworks provides a mock function with given fields: ctx, currentUser, search, sort, per, page, deployType +func (_m *MockModelComponent) ListModelsOfRuntimeFrameworks(ctx context.Context, currentUser string, search string, sort string, per int, page int, deployType int) ([]types.Model, int, error) { + ret := _m.Called(ctx, currentUser, search, sort, per, page, deployType) + + if len(ret) == 0 { + panic("no return value specified for ListModelsOfRuntimeFrameworks") + } + + var r0 []types.Model + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, int, int, int) ([]types.Model, int, error)); ok { + return rf(ctx, currentUser, search, sort, per, page, deployType) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, int, int, int) []types.Model); ok { + r0 = rf(ctx, currentUser, search, sort, per, page, deployType) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, string, int, int, int) int); ok { + r1 = rf(ctx, currentUser, search, sort, per, page, deployType) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, string, string, int, int, int) error); ok { + r2 = rf(ctx, currentUser, search, sort, per, page, deployType) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockModelComponent_ListModelsOfRuntimeFrameworks_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListModelsOfRuntimeFrameworks' +type MockModelComponent_ListModelsOfRuntimeFrameworks_Call struct { + *mock.Call +} + +// ListModelsOfRuntimeFrameworks is a helper method to define mock.On call +// - ctx context.Context +// - currentUser string +// - search string +// - sort string +// - per int +// - page int +// - deployType int +func (_e *MockModelComponent_Expecter) ListModelsOfRuntimeFrameworks(ctx interface{}, currentUser interface{}, search interface{}, sort interface{}, per interface{}, page interface{}, deployType interface{}) *MockModelComponent_ListModelsOfRuntimeFrameworks_Call { + return &MockModelComponent_ListModelsOfRuntimeFrameworks_Call{Call: _e.mock.On("ListModelsOfRuntimeFrameworks", ctx, currentUser, search, sort, per, page, deployType)} +} + +func (_c *MockModelComponent_ListModelsOfRuntimeFrameworks_Call) Run(run func(ctx context.Context, currentUser string, search string, sort string, per int, page int, deployType int)) *MockModelComponent_ListModelsOfRuntimeFrameworks_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string), args[4].(int), args[5].(int), args[6].(int)) + }) + return _c +} + +func (_c *MockModelComponent_ListModelsOfRuntimeFrameworks_Call) Return(_a0 []types.Model, _a1 int, _a2 error) *MockModelComponent_ListModelsOfRuntimeFrameworks_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockModelComponent_ListModelsOfRuntimeFrameworks_Call) RunAndReturn(run func(context.Context, string, string, string, int, int, int) ([]types.Model, int, error)) *MockModelComponent_ListModelsOfRuntimeFrameworks_Call { + _c.Call.Return(run) + return _c +} + +// OrgModels provides a mock function with given fields: ctx, req +func (_m *MockModelComponent) OrgModels(ctx context.Context, req *types.OrgModelsReq) ([]types.Model, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for OrgModels") + } + + var r0 []types.Model + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.OrgModelsReq) ([]types.Model, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.OrgModelsReq) []types.Model); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.OrgModelsReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.OrgModelsReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockModelComponent_OrgModels_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OrgModels' +type MockModelComponent_OrgModels_Call struct { + *mock.Call +} + +// OrgModels is a helper method to define mock.On call +// - ctx context.Context +// - req *types.OrgModelsReq +func (_e *MockModelComponent_Expecter) OrgModels(ctx interface{}, req interface{}) *MockModelComponent_OrgModels_Call { + return &MockModelComponent_OrgModels_Call{Call: _e.mock.On("OrgModels", ctx, req)} +} + +func (_c *MockModelComponent_OrgModels_Call) Run(run func(ctx context.Context, req *types.OrgModelsReq)) *MockModelComponent_OrgModels_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.OrgModelsReq)) + }) + return _c +} + +func (_c *MockModelComponent_OrgModels_Call) Return(_a0 []types.Model, _a1 int, _a2 error) *MockModelComponent_OrgModels_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockModelComponent_OrgModels_Call) RunAndReturn(run func(context.Context, *types.OrgModelsReq) ([]types.Model, int, error)) *MockModelComponent_OrgModels_Call { + _c.Call.Return(run) + return _c +} + +// Relations provides a mock function with given fields: ctx, namespace, name, currentUser +func (_m *MockModelComponent) Relations(ctx context.Context, namespace string, name string, currentUser string) (*types.Relations, error) { + ret := _m.Called(ctx, namespace, name, currentUser) + + if len(ret) == 0 { + panic("no return value specified for Relations") + } + + var r0 *types.Relations + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) (*types.Relations, error)); ok { + return rf(ctx, namespace, name, currentUser) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *types.Relations); ok { + r0 = rf(ctx, namespace, name, currentUser) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Relations) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok { + r1 = rf(ctx, namespace, name, currentUser) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelComponent_Relations_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Relations' +type MockModelComponent_Relations_Call struct { + *mock.Call +} + +// Relations is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +// - currentUser string +func (_e *MockModelComponent_Expecter) Relations(ctx interface{}, namespace interface{}, name interface{}, currentUser interface{}) *MockModelComponent_Relations_Call { + return &MockModelComponent_Relations_Call{Call: _e.mock.On("Relations", ctx, namespace, name, currentUser)} +} + +func (_c *MockModelComponent_Relations_Call) Run(run func(ctx context.Context, namespace string, name string, currentUser string)) *MockModelComponent_Relations_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockModelComponent_Relations_Call) Return(_a0 *types.Relations, _a1 error) *MockModelComponent_Relations_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelComponent_Relations_Call) RunAndReturn(run func(context.Context, string, string, string) (*types.Relations, error)) *MockModelComponent_Relations_Call { + _c.Call.Return(run) + return _c +} + +// SDKModelInfo provides a mock function with given fields: ctx, namespace, name, ref, currentUser +func (_m *MockModelComponent) SDKModelInfo(ctx context.Context, namespace string, name string, ref string, currentUser string) (*types.SDKModelInfo, error) { + ret := _m.Called(ctx, namespace, name, ref, currentUser) + + if len(ret) == 0 { + panic("no return value specified for SDKModelInfo") + } + + var r0 *types.SDKModelInfo + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string) (*types.SDKModelInfo, error)); ok { + return rf(ctx, namespace, name, ref, currentUser) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string) *types.SDKModelInfo); ok { + r0 = rf(ctx, namespace, name, ref, currentUser) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.SDKModelInfo) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, string, string) error); ok { + r1 = rf(ctx, namespace, name, ref, currentUser) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelComponent_SDKModelInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SDKModelInfo' +type MockModelComponent_SDKModelInfo_Call struct { + *mock.Call +} + +// SDKModelInfo is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +// - ref string +// - currentUser string +func (_e *MockModelComponent_Expecter) SDKModelInfo(ctx interface{}, namespace interface{}, name interface{}, ref interface{}, currentUser interface{}) *MockModelComponent_SDKModelInfo_Call { + return &MockModelComponent_SDKModelInfo_Call{Call: _e.mock.On("SDKModelInfo", ctx, namespace, name, ref, currentUser)} +} + +func (_c *MockModelComponent_SDKModelInfo_Call) Run(run func(ctx context.Context, namespace string, name string, ref string, currentUser string)) *MockModelComponent_SDKModelInfo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string), args[4].(string)) + }) + return _c +} + +func (_c *MockModelComponent_SDKModelInfo_Call) Return(_a0 *types.SDKModelInfo, _a1 error) *MockModelComponent_SDKModelInfo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelComponent_SDKModelInfo_Call) RunAndReturn(run func(context.Context, string, string, string, string) (*types.SDKModelInfo, error)) *MockModelComponent_SDKModelInfo_Call { + _c.Call.Return(run) + return _c +} + +// SetRelationDatasets provides a mock function with given fields: ctx, req +func (_m *MockModelComponent) SetRelationDatasets(ctx context.Context, req types.RelationDatasets) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for SetRelationDatasets") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.RelationDatasets) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockModelComponent_SetRelationDatasets_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetRelationDatasets' +type MockModelComponent_SetRelationDatasets_Call struct { + *mock.Call +} + +// SetRelationDatasets is a helper method to define mock.On call +// - ctx context.Context +// - req types.RelationDatasets +func (_e *MockModelComponent_Expecter) SetRelationDatasets(ctx interface{}, req interface{}) *MockModelComponent_SetRelationDatasets_Call { + return &MockModelComponent_SetRelationDatasets_Call{Call: _e.mock.On("SetRelationDatasets", ctx, req)} +} + +func (_c *MockModelComponent_SetRelationDatasets_Call) Run(run func(ctx context.Context, req types.RelationDatasets)) *MockModelComponent_SetRelationDatasets_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RelationDatasets)) + }) + return _c +} + +func (_c *MockModelComponent_SetRelationDatasets_Call) Return(_a0 error) *MockModelComponent_SetRelationDatasets_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockModelComponent_SetRelationDatasets_Call) RunAndReturn(run func(context.Context, types.RelationDatasets) error) *MockModelComponent_SetRelationDatasets_Call { + _c.Call.Return(run) + return _c +} + +// SetRuntimeFrameworkModes provides a mock function with given fields: ctx, deployType, id, paths +func (_m *MockModelComponent) SetRuntimeFrameworkModes(ctx context.Context, deployType int, id int64, paths []string) ([]string, error) { + ret := _m.Called(ctx, deployType, id, paths) + + if len(ret) == 0 { + panic("no return value specified for SetRuntimeFrameworkModes") + } + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int, int64, []string) ([]string, error)); ok { + return rf(ctx, deployType, id, paths) + } + if rf, ok := ret.Get(0).(func(context.Context, int, int64, []string) []string); ok { + r0 = rf(ctx, deployType, id, paths) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int, int64, []string) error); ok { + r1 = rf(ctx, deployType, id, paths) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelComponent_SetRuntimeFrameworkModes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetRuntimeFrameworkModes' +type MockModelComponent_SetRuntimeFrameworkModes_Call struct { + *mock.Call +} + +// SetRuntimeFrameworkModes is a helper method to define mock.On call +// - ctx context.Context +// - deployType int +// - id int64 +// - paths []string +func (_e *MockModelComponent_Expecter) SetRuntimeFrameworkModes(ctx interface{}, deployType interface{}, id interface{}, paths interface{}) *MockModelComponent_SetRuntimeFrameworkModes_Call { + return &MockModelComponent_SetRuntimeFrameworkModes_Call{Call: _e.mock.On("SetRuntimeFrameworkModes", ctx, deployType, id, paths)} +} + +func (_c *MockModelComponent_SetRuntimeFrameworkModes_Call) Run(run func(ctx context.Context, deployType int, id int64, paths []string)) *MockModelComponent_SetRuntimeFrameworkModes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int), args[2].(int64), args[3].([]string)) + }) + return _c +} + +func (_c *MockModelComponent_SetRuntimeFrameworkModes_Call) Return(_a0 []string, _a1 error) *MockModelComponent_SetRuntimeFrameworkModes_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelComponent_SetRuntimeFrameworkModes_Call) RunAndReturn(run func(context.Context, int, int64, []string) ([]string, error)) *MockModelComponent_SetRuntimeFrameworkModes_Call { + _c.Call.Return(run) + return _c +} + +// Show provides a mock function with given fields: ctx, namespace, name, currentUser, needOpWeight +func (_m *MockModelComponent) Show(ctx context.Context, namespace string, name string, currentUser string, needOpWeight bool) (*types.Model, error) { + ret := _m.Called(ctx, namespace, name, currentUser, needOpWeight) + + if len(ret) == 0 { + panic("no return value specified for Show") + } + + var r0 *types.Model + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, bool) (*types.Model, error)); ok { + return rf(ctx, namespace, name, currentUser, needOpWeight) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, bool) *types.Model); ok { + r0 = rf(ctx, namespace, name, currentUser, needOpWeight) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, string, bool) error); ok { + r1 = rf(ctx, namespace, name, currentUser, needOpWeight) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelComponent_Show_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Show' +type MockModelComponent_Show_Call struct { + *mock.Call +} + +// Show is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +// - currentUser string +// - needOpWeight bool +func (_e *MockModelComponent_Expecter) Show(ctx interface{}, namespace interface{}, name interface{}, currentUser interface{}, needOpWeight interface{}) *MockModelComponent_Show_Call { + return &MockModelComponent_Show_Call{Call: _e.mock.On("Show", ctx, namespace, name, currentUser, needOpWeight)} +} + +func (_c *MockModelComponent_Show_Call) Run(run func(ctx context.Context, namespace string, name string, currentUser string, needOpWeight bool)) *MockModelComponent_Show_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string), args[4].(bool)) + }) + return _c +} + +func (_c *MockModelComponent_Show_Call) Return(_a0 *types.Model, _a1 error) *MockModelComponent_Show_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelComponent_Show_Call) RunAndReturn(run func(context.Context, string, string, string, bool) (*types.Model, error)) *MockModelComponent_Show_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, req +func (_m *MockModelComponent) Update(ctx context.Context, req *types.UpdateModelReq) (*types.Model, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 *types.Model + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UpdateModelReq) (*types.Model, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UpdateModelReq) *types.Model); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UpdateModelReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelComponent_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockModelComponent_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UpdateModelReq +func (_e *MockModelComponent_Expecter) Update(ctx interface{}, req interface{}) *MockModelComponent_Update_Call { + return &MockModelComponent_Update_Call{Call: _e.mock.On("Update", ctx, req)} +} + +func (_c *MockModelComponent_Update_Call) Run(run func(ctx context.Context, req *types.UpdateModelReq)) *MockModelComponent_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UpdateModelReq)) + }) + return _c +} + +func (_c *MockModelComponent_Update_Call) Return(_a0 *types.Model, _a1 error) *MockModelComponent_Update_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelComponent_Update_Call) RunAndReturn(run func(context.Context, *types.UpdateModelReq) (*types.Model, error)) *MockModelComponent_Update_Call { + _c.Call.Return(run) + return _c +} + +// NewMockModelComponent creates a new instance of MockModelComponent. 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 NewMockModelComponent(t interface { + mock.TestingT + Cleanup(func()) +}) *MockModelComponent { + mock := &MockModelComponent{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/component/mock_UserComponent.go b/_mocks/opencsg.com/csghub-server/component/mock_UserComponent.go new file mode 100644 index 00000000..69e029e0 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/component/mock_UserComponent.go @@ -0,0 +1,1277 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package component + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" + + types "opencsg.com/csghub-server/common/types" +) + +// MockUserComponent is an autogenerated mock type for the UserComponent type +type MockUserComponent struct { + mock.Mock +} + +type MockUserComponent_Expecter struct { + mock *mock.Mock +} + +func (_m *MockUserComponent) EXPECT() *MockUserComponent_Expecter { + return &MockUserComponent_Expecter{mock: &_m.Mock} +} + +// AddLikes provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) AddLikes(ctx context.Context, req *types.UserLikesRequest) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for AddLikes") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserLikesRequest) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockUserComponent_AddLikes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddLikes' +type MockUserComponent_AddLikes_Call struct { + *mock.Call +} + +// AddLikes is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserLikesRequest +func (_e *MockUserComponent_Expecter) AddLikes(ctx interface{}, req interface{}) *MockUserComponent_AddLikes_Call { + return &MockUserComponent_AddLikes_Call{Call: _e.mock.On("AddLikes", ctx, req)} +} + +func (_c *MockUserComponent_AddLikes_Call) Run(run func(ctx context.Context, req *types.UserLikesRequest)) *MockUserComponent_AddLikes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserLikesRequest)) + }) + return _c +} + +func (_c *MockUserComponent_AddLikes_Call) Return(_a0 error) *MockUserComponent_AddLikes_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockUserComponent_AddLikes_Call) RunAndReturn(run func(context.Context, *types.UserLikesRequest) error) *MockUserComponent_AddLikes_Call { + _c.Call.Return(run) + return _c +} + +// Codes provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) Codes(ctx context.Context, req *types.UserModelsReq) ([]types.Code, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Codes") + } + + var r0 []types.Code + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserModelsReq) ([]types.Code, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserModelsReq) []types.Code); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Code) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserModelsReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserModelsReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_Codes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Codes' +type MockUserComponent_Codes_Call struct { + *mock.Call +} + +// Codes is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserModelsReq +func (_e *MockUserComponent_Expecter) Codes(ctx interface{}, req interface{}) *MockUserComponent_Codes_Call { + return &MockUserComponent_Codes_Call{Call: _e.mock.On("Codes", ctx, req)} +} + +func (_c *MockUserComponent_Codes_Call) Run(run func(ctx context.Context, req *types.UserModelsReq)) *MockUserComponent_Codes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserModelsReq)) + }) + return _c +} + +func (_c *MockUserComponent_Codes_Call) Return(_a0 []types.Code, _a1 int, _a2 error) *MockUserComponent_Codes_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_Codes_Call) RunAndReturn(run func(context.Context, *types.UserModelsReq) ([]types.Code, int, error)) *MockUserComponent_Codes_Call { + _c.Call.Return(run) + return _c +} + +// Collections provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) Collections(ctx context.Context, req *types.UserCollectionReq) ([]types.Collection, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Collections") + } + + var r0 []types.Collection + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserCollectionReq) ([]types.Collection, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserCollectionReq) []types.Collection); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Collection) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserCollectionReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserCollectionReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_Collections_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Collections' +type MockUserComponent_Collections_Call struct { + *mock.Call +} + +// Collections is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserCollectionReq +func (_e *MockUserComponent_Expecter) Collections(ctx interface{}, req interface{}) *MockUserComponent_Collections_Call { + return &MockUserComponent_Collections_Call{Call: _e.mock.On("Collections", ctx, req)} +} + +func (_c *MockUserComponent_Collections_Call) Run(run func(ctx context.Context, req *types.UserCollectionReq)) *MockUserComponent_Collections_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserCollectionReq)) + }) + return _c +} + +func (_c *MockUserComponent_Collections_Call) Return(_a0 []types.Collection, _a1 int, _a2 error) *MockUserComponent_Collections_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_Collections_Call) RunAndReturn(run func(context.Context, *types.UserCollectionReq) ([]types.Collection, int, error)) *MockUserComponent_Collections_Call { + _c.Call.Return(run) + return _c +} + +// Datasets provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) Datasets(ctx context.Context, req *types.UserDatasetsReq) ([]types.Dataset, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Datasets") + } + + var r0 []types.Dataset + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserDatasetsReq) ([]types.Dataset, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserDatasetsReq) []types.Dataset); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Dataset) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserDatasetsReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserDatasetsReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_Datasets_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Datasets' +type MockUserComponent_Datasets_Call struct { + *mock.Call +} + +// Datasets is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserDatasetsReq +func (_e *MockUserComponent_Expecter) Datasets(ctx interface{}, req interface{}) *MockUserComponent_Datasets_Call { + return &MockUserComponent_Datasets_Call{Call: _e.mock.On("Datasets", ctx, req)} +} + +func (_c *MockUserComponent_Datasets_Call) Run(run func(ctx context.Context, req *types.UserDatasetsReq)) *MockUserComponent_Datasets_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserDatasetsReq)) + }) + return _c +} + +func (_c *MockUserComponent_Datasets_Call) Return(_a0 []types.Dataset, _a1 int, _a2 error) *MockUserComponent_Datasets_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_Datasets_Call) RunAndReturn(run func(context.Context, *types.UserDatasetsReq) ([]types.Dataset, int, error)) *MockUserComponent_Datasets_Call { + _c.Call.Return(run) + return _c +} + +// DeleteLikes provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) DeleteLikes(ctx context.Context, req *types.UserLikesRequest) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for DeleteLikes") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserLikesRequest) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockUserComponent_DeleteLikes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteLikes' +type MockUserComponent_DeleteLikes_Call struct { + *mock.Call +} + +// DeleteLikes is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserLikesRequest +func (_e *MockUserComponent_Expecter) DeleteLikes(ctx interface{}, req interface{}) *MockUserComponent_DeleteLikes_Call { + return &MockUserComponent_DeleteLikes_Call{Call: _e.mock.On("DeleteLikes", ctx, req)} +} + +func (_c *MockUserComponent_DeleteLikes_Call) Run(run func(ctx context.Context, req *types.UserLikesRequest)) *MockUserComponent_DeleteLikes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserLikesRequest)) + }) + return _c +} + +func (_c *MockUserComponent_DeleteLikes_Call) Return(_a0 error) *MockUserComponent_DeleteLikes_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockUserComponent_DeleteLikes_Call) RunAndReturn(run func(context.Context, *types.UserLikesRequest) error) *MockUserComponent_DeleteLikes_Call { + _c.Call.Return(run) + return _c +} + +// Evaluations provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) Evaluations(ctx context.Context, req *types.UserEvaluationReq) ([]types.ArgoWorkFlowRes, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Evaluations") + } + + var r0 []types.ArgoWorkFlowRes + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserEvaluationReq) ([]types.ArgoWorkFlowRes, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserEvaluationReq) []types.ArgoWorkFlowRes); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.ArgoWorkFlowRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserEvaluationReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserEvaluationReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_Evaluations_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Evaluations' +type MockUserComponent_Evaluations_Call struct { + *mock.Call +} + +// Evaluations is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserEvaluationReq +func (_e *MockUserComponent_Expecter) Evaluations(ctx interface{}, req interface{}) *MockUserComponent_Evaluations_Call { + return &MockUserComponent_Evaluations_Call{Call: _e.mock.On("Evaluations", ctx, req)} +} + +func (_c *MockUserComponent_Evaluations_Call) Run(run func(ctx context.Context, req *types.UserEvaluationReq)) *MockUserComponent_Evaluations_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserEvaluationReq)) + }) + return _c +} + +func (_c *MockUserComponent_Evaluations_Call) Return(_a0 []types.ArgoWorkFlowRes, _a1 int, _a2 error) *MockUserComponent_Evaluations_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_Evaluations_Call) RunAndReturn(run func(context.Context, *types.UserEvaluationReq) ([]types.ArgoWorkFlowRes, int, error)) *MockUserComponent_Evaluations_Call { + _c.Call.Return(run) + return _c +} + +// GetUserByName provides a mock function with given fields: ctx, userName +func (_m *MockUserComponent) GetUserByName(ctx context.Context, userName string) (*database.User, error) { + ret := _m.Called(ctx, userName) + + if len(ret) == 0 { + panic("no return value specified for GetUserByName") + } + + var r0 *database.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.User, error)); ok { + return rf(ctx, userName) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.User); ok { + r0 = rf(ctx, userName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.User) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, userName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserComponent_GetUserByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserByName' +type MockUserComponent_GetUserByName_Call struct { + *mock.Call +} + +// GetUserByName is a helper method to define mock.On call +// - ctx context.Context +// - userName string +func (_e *MockUserComponent_Expecter) GetUserByName(ctx interface{}, userName interface{}) *MockUserComponent_GetUserByName_Call { + return &MockUserComponent_GetUserByName_Call{Call: _e.mock.On("GetUserByName", ctx, userName)} +} + +func (_c *MockUserComponent_GetUserByName_Call) Run(run func(ctx context.Context, userName string)) *MockUserComponent_GetUserByName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockUserComponent_GetUserByName_Call) Return(_a0 *database.User, _a1 error) *MockUserComponent_GetUserByName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockUserComponent_GetUserByName_Call) RunAndReturn(run func(context.Context, string) (*database.User, error)) *MockUserComponent_GetUserByName_Call { + _c.Call.Return(run) + return _c +} + +// LikeCollection provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) LikeCollection(ctx context.Context, req *types.UserLikesRequest) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for LikeCollection") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserLikesRequest) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockUserComponent_LikeCollection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LikeCollection' +type MockUserComponent_LikeCollection_Call struct { + *mock.Call +} + +// LikeCollection is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserLikesRequest +func (_e *MockUserComponent_Expecter) LikeCollection(ctx interface{}, req interface{}) *MockUserComponent_LikeCollection_Call { + return &MockUserComponent_LikeCollection_Call{Call: _e.mock.On("LikeCollection", ctx, req)} +} + +func (_c *MockUserComponent_LikeCollection_Call) Run(run func(ctx context.Context, req *types.UserLikesRequest)) *MockUserComponent_LikeCollection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserLikesRequest)) + }) + return _c +} + +func (_c *MockUserComponent_LikeCollection_Call) Return(_a0 error) *MockUserComponent_LikeCollection_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockUserComponent_LikeCollection_Call) RunAndReturn(run func(context.Context, *types.UserLikesRequest) error) *MockUserComponent_LikeCollection_Call { + _c.Call.Return(run) + return _c +} + +// LikesCodes provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) LikesCodes(ctx context.Context, req *types.UserModelsReq) ([]types.Code, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for LikesCodes") + } + + var r0 []types.Code + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserModelsReq) ([]types.Code, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserModelsReq) []types.Code); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Code) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserModelsReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserModelsReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_LikesCodes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LikesCodes' +type MockUserComponent_LikesCodes_Call struct { + *mock.Call +} + +// LikesCodes is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserModelsReq +func (_e *MockUserComponent_Expecter) LikesCodes(ctx interface{}, req interface{}) *MockUserComponent_LikesCodes_Call { + return &MockUserComponent_LikesCodes_Call{Call: _e.mock.On("LikesCodes", ctx, req)} +} + +func (_c *MockUserComponent_LikesCodes_Call) Run(run func(ctx context.Context, req *types.UserModelsReq)) *MockUserComponent_LikesCodes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserModelsReq)) + }) + return _c +} + +func (_c *MockUserComponent_LikesCodes_Call) Return(_a0 []types.Code, _a1 int, _a2 error) *MockUserComponent_LikesCodes_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_LikesCodes_Call) RunAndReturn(run func(context.Context, *types.UserModelsReq) ([]types.Code, int, error)) *MockUserComponent_LikesCodes_Call { + _c.Call.Return(run) + return _c +} + +// LikesCollection provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) LikesCollection(ctx context.Context, req *types.UserSpacesReq) ([]types.Collection, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for LikesCollection") + } + + var r0 []types.Collection + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserSpacesReq) ([]types.Collection, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserSpacesReq) []types.Collection); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Collection) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserSpacesReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserSpacesReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_LikesCollection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LikesCollection' +type MockUserComponent_LikesCollection_Call struct { + *mock.Call +} + +// LikesCollection is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserSpacesReq +func (_e *MockUserComponent_Expecter) LikesCollection(ctx interface{}, req interface{}) *MockUserComponent_LikesCollection_Call { + return &MockUserComponent_LikesCollection_Call{Call: _e.mock.On("LikesCollection", ctx, req)} +} + +func (_c *MockUserComponent_LikesCollection_Call) Run(run func(ctx context.Context, req *types.UserSpacesReq)) *MockUserComponent_LikesCollection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserSpacesReq)) + }) + return _c +} + +func (_c *MockUserComponent_LikesCollection_Call) Return(_a0 []types.Collection, _a1 int, _a2 error) *MockUserComponent_LikesCollection_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_LikesCollection_Call) RunAndReturn(run func(context.Context, *types.UserSpacesReq) ([]types.Collection, int, error)) *MockUserComponent_LikesCollection_Call { + _c.Call.Return(run) + return _c +} + +// LikesDatasets provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) LikesDatasets(ctx context.Context, req *types.UserDatasetsReq) ([]types.Dataset, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for LikesDatasets") + } + + var r0 []types.Dataset + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserDatasetsReq) ([]types.Dataset, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserDatasetsReq) []types.Dataset); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Dataset) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserDatasetsReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserDatasetsReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_LikesDatasets_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LikesDatasets' +type MockUserComponent_LikesDatasets_Call struct { + *mock.Call +} + +// LikesDatasets is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserDatasetsReq +func (_e *MockUserComponent_Expecter) LikesDatasets(ctx interface{}, req interface{}) *MockUserComponent_LikesDatasets_Call { + return &MockUserComponent_LikesDatasets_Call{Call: _e.mock.On("LikesDatasets", ctx, req)} +} + +func (_c *MockUserComponent_LikesDatasets_Call) Run(run func(ctx context.Context, req *types.UserDatasetsReq)) *MockUserComponent_LikesDatasets_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserDatasetsReq)) + }) + return _c +} + +func (_c *MockUserComponent_LikesDatasets_Call) Return(_a0 []types.Dataset, _a1 int, _a2 error) *MockUserComponent_LikesDatasets_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_LikesDatasets_Call) RunAndReturn(run func(context.Context, *types.UserDatasetsReq) ([]types.Dataset, int, error)) *MockUserComponent_LikesDatasets_Call { + _c.Call.Return(run) + return _c +} + +// LikesModels provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) LikesModels(ctx context.Context, req *types.UserModelsReq) ([]types.Model, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for LikesModels") + } + + var r0 []types.Model + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserModelsReq) ([]types.Model, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserModelsReq) []types.Model); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserModelsReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserModelsReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_LikesModels_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LikesModels' +type MockUserComponent_LikesModels_Call struct { + *mock.Call +} + +// LikesModels is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserModelsReq +func (_e *MockUserComponent_Expecter) LikesModels(ctx interface{}, req interface{}) *MockUserComponent_LikesModels_Call { + return &MockUserComponent_LikesModels_Call{Call: _e.mock.On("LikesModels", ctx, req)} +} + +func (_c *MockUserComponent_LikesModels_Call) Run(run func(ctx context.Context, req *types.UserModelsReq)) *MockUserComponent_LikesModels_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserModelsReq)) + }) + return _c +} + +func (_c *MockUserComponent_LikesModels_Call) Return(_a0 []types.Model, _a1 int, _a2 error) *MockUserComponent_LikesModels_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_LikesModels_Call) RunAndReturn(run func(context.Context, *types.UserModelsReq) ([]types.Model, int, error)) *MockUserComponent_LikesModels_Call { + _c.Call.Return(run) + return _c +} + +// LikesSpaces provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) LikesSpaces(ctx context.Context, req *types.UserSpacesReq) ([]types.Space, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for LikesSpaces") + } + + var r0 []types.Space + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserSpacesReq) ([]types.Space, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserSpacesReq) []types.Space); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserSpacesReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserSpacesReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_LikesSpaces_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LikesSpaces' +type MockUserComponent_LikesSpaces_Call struct { + *mock.Call +} + +// LikesSpaces is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserSpacesReq +func (_e *MockUserComponent_Expecter) LikesSpaces(ctx interface{}, req interface{}) *MockUserComponent_LikesSpaces_Call { + return &MockUserComponent_LikesSpaces_Call{Call: _e.mock.On("LikesSpaces", ctx, req)} +} + +func (_c *MockUserComponent_LikesSpaces_Call) Run(run func(ctx context.Context, req *types.UserSpacesReq)) *MockUserComponent_LikesSpaces_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserSpacesReq)) + }) + return _c +} + +func (_c *MockUserComponent_LikesSpaces_Call) Return(_a0 []types.Space, _a1 int, _a2 error) *MockUserComponent_LikesSpaces_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_LikesSpaces_Call) RunAndReturn(run func(context.Context, *types.UserSpacesReq) ([]types.Space, int, error)) *MockUserComponent_LikesSpaces_Call { + _c.Call.Return(run) + return _c +} + +// ListDeploys provides a mock function with given fields: ctx, repoType, req +func (_m *MockUserComponent) ListDeploys(ctx context.Context, repoType types.RepositoryType, req *types.DeployReq) ([]types.DeployRepo, int, error) { + ret := _m.Called(ctx, repoType, req) + + if len(ret) == 0 { + panic("no return value specified for ListDeploys") + } + + var r0 []types.DeployRepo + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, *types.DeployReq) ([]types.DeployRepo, int, error)); ok { + return rf(ctx, repoType, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, *types.DeployReq) []types.DeployRepo); ok { + r0 = rf(ctx, repoType, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.DeployRepo) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, *types.DeployReq) int); ok { + r1 = rf(ctx, repoType, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, types.RepositoryType, *types.DeployReq) error); ok { + r2 = rf(ctx, repoType, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_ListDeploys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListDeploys' +type MockUserComponent_ListDeploys_Call struct { + *mock.Call +} + +// ListDeploys is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - req *types.DeployReq +func (_e *MockUserComponent_Expecter) ListDeploys(ctx interface{}, repoType interface{}, req interface{}) *MockUserComponent_ListDeploys_Call { + return &MockUserComponent_ListDeploys_Call{Call: _e.mock.On("ListDeploys", ctx, repoType, req)} +} + +func (_c *MockUserComponent_ListDeploys_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, req *types.DeployReq)) *MockUserComponent_ListDeploys_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(*types.DeployReq)) + }) + return _c +} + +func (_c *MockUserComponent_ListDeploys_Call) Return(_a0 []types.DeployRepo, _a1 int, _a2 error) *MockUserComponent_ListDeploys_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_ListDeploys_Call) RunAndReturn(run func(context.Context, types.RepositoryType, *types.DeployReq) ([]types.DeployRepo, int, error)) *MockUserComponent_ListDeploys_Call { + _c.Call.Return(run) + return _c +} + +// ListInstances provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) ListInstances(ctx context.Context, req *types.UserRepoReq) ([]types.DeployRepo, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for ListInstances") + } + + var r0 []types.DeployRepo + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserRepoReq) ([]types.DeployRepo, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserRepoReq) []types.DeployRepo); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.DeployRepo) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserRepoReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserRepoReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_ListInstances_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListInstances' +type MockUserComponent_ListInstances_Call struct { + *mock.Call +} + +// ListInstances is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserRepoReq +func (_e *MockUserComponent_Expecter) ListInstances(ctx interface{}, req interface{}) *MockUserComponent_ListInstances_Call { + return &MockUserComponent_ListInstances_Call{Call: _e.mock.On("ListInstances", ctx, req)} +} + +func (_c *MockUserComponent_ListInstances_Call) Run(run func(ctx context.Context, req *types.UserRepoReq)) *MockUserComponent_ListInstances_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserRepoReq)) + }) + return _c +} + +func (_c *MockUserComponent_ListInstances_Call) Return(_a0 []types.DeployRepo, _a1 int, _a2 error) *MockUserComponent_ListInstances_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_ListInstances_Call) RunAndReturn(run func(context.Context, *types.UserRepoReq) ([]types.DeployRepo, int, error)) *MockUserComponent_ListInstances_Call { + _c.Call.Return(run) + return _c +} + +// ListServerless provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) ListServerless(ctx context.Context, req types.DeployReq) ([]types.DeployRepo, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for ListServerless") + } + + var r0 []types.DeployRepo + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployReq) ([]types.DeployRepo, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DeployReq) []types.DeployRepo); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.DeployRepo) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DeployReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, types.DeployReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_ListServerless_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListServerless' +type MockUserComponent_ListServerless_Call struct { + *mock.Call +} + +// ListServerless is a helper method to define mock.On call +// - ctx context.Context +// - req types.DeployReq +func (_e *MockUserComponent_Expecter) ListServerless(ctx interface{}, req interface{}) *MockUserComponent_ListServerless_Call { + return &MockUserComponent_ListServerless_Call{Call: _e.mock.On("ListServerless", ctx, req)} +} + +func (_c *MockUserComponent_ListServerless_Call) Run(run func(ctx context.Context, req types.DeployReq)) *MockUserComponent_ListServerless_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployReq)) + }) + return _c +} + +func (_c *MockUserComponent_ListServerless_Call) Return(_a0 []types.DeployRepo, _a1 int, _a2 error) *MockUserComponent_ListServerless_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_ListServerless_Call) RunAndReturn(run func(context.Context, types.DeployReq) ([]types.DeployRepo, int, error)) *MockUserComponent_ListServerless_Call { + _c.Call.Return(run) + return _c +} + +// Models provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) Models(ctx context.Context, req *types.UserModelsReq) ([]types.Model, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Models") + } + + var r0 []types.Model + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserModelsReq) ([]types.Model, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserModelsReq) []types.Model); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserModelsReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserModelsReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_Models_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Models' +type MockUserComponent_Models_Call struct { + *mock.Call +} + +// Models is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserModelsReq +func (_e *MockUserComponent_Expecter) Models(ctx interface{}, req interface{}) *MockUserComponent_Models_Call { + return &MockUserComponent_Models_Call{Call: _e.mock.On("Models", ctx, req)} +} + +func (_c *MockUserComponent_Models_Call) Run(run func(ctx context.Context, req *types.UserModelsReq)) *MockUserComponent_Models_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserModelsReq)) + }) + return _c +} + +func (_c *MockUserComponent_Models_Call) Return(_a0 []types.Model, _a1 int, _a2 error) *MockUserComponent_Models_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_Models_Call) RunAndReturn(run func(context.Context, *types.UserModelsReq) ([]types.Model, int, error)) *MockUserComponent_Models_Call { + _c.Call.Return(run) + return _c +} + +// Prompts provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) Prompts(ctx context.Context, req *types.UserPromptsReq) ([]types.PromptRes, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Prompts") + } + + var r0 []types.PromptRes + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserPromptsReq) ([]types.PromptRes, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserPromptsReq) []types.PromptRes); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.PromptRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserPromptsReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserPromptsReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_Prompts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Prompts' +type MockUserComponent_Prompts_Call struct { + *mock.Call +} + +// Prompts is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserPromptsReq +func (_e *MockUserComponent_Expecter) Prompts(ctx interface{}, req interface{}) *MockUserComponent_Prompts_Call { + return &MockUserComponent_Prompts_Call{Call: _e.mock.On("Prompts", ctx, req)} +} + +func (_c *MockUserComponent_Prompts_Call) Run(run func(ctx context.Context, req *types.UserPromptsReq)) *MockUserComponent_Prompts_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserPromptsReq)) + }) + return _c +} + +func (_c *MockUserComponent_Prompts_Call) Return(_a0 []types.PromptRes, _a1 int, _a2 error) *MockUserComponent_Prompts_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_Prompts_Call) RunAndReturn(run func(context.Context, *types.UserPromptsReq) ([]types.PromptRes, int, error)) *MockUserComponent_Prompts_Call { + _c.Call.Return(run) + return _c +} + +// Spaces provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) Spaces(ctx context.Context, req *types.UserSpacesReq) ([]types.Space, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Spaces") + } + + var r0 []types.Space + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserSpacesReq) ([]types.Space, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserSpacesReq) []types.Space); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserSpacesReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserSpacesReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserComponent_Spaces_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Spaces' +type MockUserComponent_Spaces_Call struct { + *mock.Call +} + +// Spaces is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserSpacesReq +func (_e *MockUserComponent_Expecter) Spaces(ctx interface{}, req interface{}) *MockUserComponent_Spaces_Call { + return &MockUserComponent_Spaces_Call{Call: _e.mock.On("Spaces", ctx, req)} +} + +func (_c *MockUserComponent_Spaces_Call) Run(run func(ctx context.Context, req *types.UserSpacesReq)) *MockUserComponent_Spaces_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserSpacesReq)) + }) + return _c +} + +func (_c *MockUserComponent_Spaces_Call) Return(_a0 []types.Space, _a1 int, _a2 error) *MockUserComponent_Spaces_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockUserComponent_Spaces_Call) RunAndReturn(run func(context.Context, *types.UserSpacesReq) ([]types.Space, int, error)) *MockUserComponent_Spaces_Call { + _c.Call.Return(run) + return _c +} + +// UnLikeCollection provides a mock function with given fields: ctx, req +func (_m *MockUserComponent) UnLikeCollection(ctx context.Context, req *types.UserLikesRequest) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for UnLikeCollection") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserLikesRequest) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockUserComponent_UnLikeCollection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UnLikeCollection' +type MockUserComponent_UnLikeCollection_Call struct { + *mock.Call +} + +// UnLikeCollection is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserLikesRequest +func (_e *MockUserComponent_Expecter) UnLikeCollection(ctx interface{}, req interface{}) *MockUserComponent_UnLikeCollection_Call { + return &MockUserComponent_UnLikeCollection_Call{Call: _e.mock.On("UnLikeCollection", ctx, req)} +} + +func (_c *MockUserComponent_UnLikeCollection_Call) Run(run func(ctx context.Context, req *types.UserLikesRequest)) *MockUserComponent_UnLikeCollection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserLikesRequest)) + }) + return _c +} + +func (_c *MockUserComponent_UnLikeCollection_Call) Return(_a0 error) *MockUserComponent_UnLikeCollection_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockUserComponent_UnLikeCollection_Call) RunAndReturn(run func(context.Context, *types.UserLikesRequest) error) *MockUserComponent_UnLikeCollection_Call { + _c.Call.Return(run) + return _c +} + +// NewMockUserComponent creates a new instance of MockUserComponent. 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 NewMockUserComponent(t interface { + mock.TestingT + Cleanup(func()) +}) *MockUserComponent { + mock := &MockUserComponent{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/api/handler/git_http.go b/api/handler/git_http.go index 5047cea1..a9bcb86b 100644 --- a/api/handler/git_http.go +++ b/api/handler/git_http.go @@ -25,12 +25,12 @@ func NewGitHTTPHandler(config *config.Config) (*GitHTTPHandler, error) { return nil, err } return &GitHTTPHandler{ - c: uc, + gitHttp: uc, }, nil } type GitHTTPHandler struct { - c component.GitHTTPComponent + gitHttp component.GitHTTPComponent } func (h *GitHTTPHandler) InfoRefs(ctx *gin.Context) { @@ -53,7 +53,7 @@ func (h *GitHTTPHandler) InfoRefs(ctx *gin.Context) { GitProtocol: gitProtocol, CurrentUser: httpbase.GetCurrentUser(ctx), } - reader, err := h.c.InfoRefs(ctx, req) + reader, err := h.gitHttp.InfoRefs(ctx, req) if err != nil { if err == component.ErrUnauthorized { ctx.Header("WWW-Authenticate", "Basic realm=opencsg-git") @@ -109,7 +109,7 @@ func (h *GitHTTPHandler) GitUploadPack(ctx *gin.Context) { ctx.Header("Content-Type", fmt.Sprintf("application/x-%s-result", action)) ctx.Header("Cache-Control", "no-cache") - err := h.c.GitUploadPack(ctx, req) + err := h.gitHttp.GitUploadPack(ctx, req) if err != nil { httpbase.ServerError(ctx, err) return @@ -132,7 +132,7 @@ func (h *GitHTTPHandler) GitReceivePack(ctx *gin.Context) { ctx.Header("Content-Type", fmt.Sprintf("application/x-%s-result", action)) ctx.Header("Cache-Control", "no-cache") - err := h.c.GitReceivePack(ctx, req) + err := h.gitHttp.GitReceivePack(ctx, req) if err != nil { if err == component.ErrUnauthorized { ctx.Header("WWW-Authenticate", "Basic realm=opencsg-git") @@ -175,12 +175,7 @@ func (h *GitHTTPHandler) LfsBatch(ctx *gin.Context) { return } - s3Internal := ctx.GetHeader("X-OPENCSG-S3-Internal") - if s3Internal == "true" { - ctx.Set("X-OPENCSG-S3-Internal", true) - } - - objectResponse, err := h.c.BuildObjectResponse(ctx, batchRequest, isUpload) + objectResponse, err := h.gitHttp.BuildObjectResponse(ctx, batchRequest, isUpload) if err != nil { if errors.Is(err, component.ErrUnauthorized) { ctx.Header("WWW-Authenticate", "Basic realm=opencsg-git") @@ -216,7 +211,7 @@ func (h *GitHTTPHandler) LfsUpload(ctx *gin.Context) { uploadRequest.RepoType = types.RepositoryType(ctx.GetString("repo_type")) uploadRequest.CurrentUser = httpbase.GetCurrentUser(ctx) - err = h.c.LfsUpload(ctx, ctx.Request.Body, uploadRequest) + err = h.gitHttp.LfsUpload(ctx, ctx.Request.Body, uploadRequest) if err != nil { httpbase.ServerError(ctx, err) return @@ -240,12 +235,7 @@ func (h *GitHTTPHandler) LfsDownload(ctx *gin.Context) { downloadRequest.CurrentUser = httpbase.GetCurrentUser(ctx) downloadRequest.SaveAs = ctx.Query("save_as") - s3Internal := ctx.GetHeader("X-OPENCSG-S3-Internal") - if s3Internal == "true" { - ctx.Set("X-OPENCSG-S3-Internal", true) - } - - url, err := h.c.LfsDownload(ctx, downloadRequest) + url, err := h.gitHttp.LfsDownload(ctx, downloadRequest) if err != nil { httpbase.ServerError(ctx, err) return @@ -269,7 +259,7 @@ func (h *GitHTTPHandler) LfsVerify(ctx *gin.Context) { verifyRequest.RepoType = types.RepositoryType(ctx.GetString("repo_type")) verifyRequest.CurrentUser = httpbase.GetCurrentUser(ctx) - err := h.c.LfsVerify(ctx, verifyRequest, pointer) + err := h.gitHttp.LfsVerify(ctx, verifyRequest, pointer) if err != nil { slog.Error("Bad request format", "error", err) httpbase.BadRequest(ctx, err.Error()) @@ -312,7 +302,7 @@ func (h *GitHTTPHandler) ListLocks(ctx *gin.Context) { } req.Limit = limit - res, err := h.c.ListLocks(ctx, req) + res, err := h.gitHttp.ListLocks(ctx, req) if err != nil { if errors.Is(err, component.ErrUnauthorized) { ctx.Header("WWW-Authenticate", "Basic realm=opencsg-git") @@ -344,7 +334,7 @@ func (h *GitHTTPHandler) CreateLock(ctx *gin.Context) { req.RepoType = types.RepositoryType(ctx.GetString("repo_type")) req.CurrentUser = httpbase.GetCurrentUser(ctx) - lock, err := h.c.CreateLock(ctx, req) + lock, err := h.gitHttp.CreateLock(ctx, req) if err != nil { if errors.Is(err, component.ErrAlreadyExists) { ctx.PureJSON(http.StatusConflict, types.LFSLockError{ @@ -413,7 +403,7 @@ func (h *GitHTTPHandler) VerifyLock(ctx *gin.Context) { } req.Limit = limit - res, err := h.c.VerifyLock(ctx, req) + res, err := h.gitHttp.VerifyLock(ctx, req) if err != nil { slog.Error("Bad request format", "error", err) ctx.PureJSON(http.StatusInternalServerError, types.LFSLockError{ @@ -452,7 +442,7 @@ func (h *GitHTTPHandler) UnLock(ctx *gin.Context) { req.RepoType = types.RepositoryType(ctx.GetString("repo_type")) req.CurrentUser = httpbase.GetCurrentUser(ctx) - lock, err = h.c.UnLock(ctx, req) + lock, err = h.gitHttp.UnLock(ctx, req) if err != nil { if errors.Is(err, component.ErrUnauthorized) { ctx.Header("WWW-Authenticate", "Basic realm=opencsg-git") diff --git a/api/handler/git_http_test.go b/api/handler/git_http_test.go new file mode 100644 index 00000000..e1d844fa --- /dev/null +++ b/api/handler/git_http_test.go @@ -0,0 +1,315 @@ +package handler + +import ( + "bytes" + "compress/gzip" + "io" + "net/url" + "testing" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/require" + mockcomponent "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/component" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/types" +) + +type GitHTTPTester struct { + *GinTester + handler *GitHTTPHandler + mocks struct { + gitHttp *mockcomponent.MockGitHTTPComponent + } +} + +func NewGitHTTPTester(t *testing.T) *GitHTTPTester { + tester := &GitHTTPTester{GinTester: NewGinTester()} + tester.mocks.gitHttp = mockcomponent.NewMockGitHTTPComponent(t) + + tester.handler = &GitHTTPHandler{ + gitHttp: tester.mocks.gitHttp, + } + tester.WithParam("repo", "testRepo") + tester.WithParam("branch", "testBranch") + return tester +} + +func (t *GitHTTPTester) WithHandleFunc(fn func(h *GitHTTPHandler) gin.HandlerFunc) *GitHTTPTester { + t.ginHandler = fn(t.handler) + return t +} + +func TestGitHTTPHandler_InfoRefs(t *testing.T) { + tester := NewGitHTTPTester(t).WithHandleFunc(func(h *GitHTTPHandler) gin.HandlerFunc { + return h.InfoRefs + }) + + reader := io.NopCloser(bytes.NewBuffer([]byte("foo"))) + tester.mocks.gitHttp.EXPECT().InfoRefs(tester.ctx, types.InfoRefsReq{ + Namespace: "u", + Name: "r", + RepoType: types.ModelRepo, + Rpc: "git-upload-pack", + GitProtocol: "ssh", + CurrentUser: "u", + }).Return(reader, nil) + tester.WithQuery("service", "git-upload-pack").WithHeader("Git-Protocol", "ssh") + tester.WithKV("namespace", "u").WithKV("name", "r") + tester.WithKV("repo_type", "model").WithUser().WithHeader("Accept-Encoding", "gzip").Execute() + + require.Equal(t, 200, tester.response.Code) + var b bytes.Buffer + gz := gzip.NewWriter(&b) + _, err := gz.Write([]byte("foo")) + require.NoError(t, err) + err = gz.Close() + require.NoError(t, err) + require.Equal(t, b.String(), tester.response.Body.String()) + headers := tester.response.Header() + require.Equal(t, "application/x-git-upload-pack-advertisement", headers.Get("Content-Type")) + require.Equal(t, "no-cache", headers.Get("Cache-Control")) +} + +func TestGitHTTPHandler_GitUploadPack(t *testing.T) { + tester := NewGitHTTPTester(t).WithHandleFunc(func(h *GitHTTPHandler) gin.HandlerFunc { + return h.GitUploadPack + }) + + tester.mocks.gitHttp.EXPECT().GitUploadPack(tester.ctx, types.GitUploadPackReq{ + Namespace: "u", + Name: "r", + RepoType: types.ModelRepo, + GitProtocol: "ssh", + Request: tester.ctx.Request, + Writer: tester.ctx.Writer, + CurrentUser: "u", + }).Return(nil) + tester.SetPath("git").WithQuery("service", "git-upload-pack").WithHeader("Git-Protocol", "ssh") + tester.WithKV("namespace", "u").WithKV("name", "r") + tester.WithKV("repo_type", "model").WithUser().WithHeader("Accept-Encoding", "gzip").Execute() + + require.Equal(t, 200, tester.response.Code) + headers := tester.response.Header() + require.Equal(t, "application/x-git-result", headers.Get("Content-Type")) + require.Equal(t, "no-cache", headers.Get("Cache-Control")) +} + +func TestGitHTTPHandler_GitReceivePack(t *testing.T) { + tester := NewGitHTTPTester(t).WithHandleFunc(func(h *GitHTTPHandler) gin.HandlerFunc { + return h.GitReceivePack + }) + + tester.mocks.gitHttp.EXPECT().GitReceivePack(tester.ctx, types.GitUploadPackReq{ + Namespace: "u", + Name: "r", + RepoType: types.ModelRepo, + GitProtocol: "ssh", + Request: tester.ctx.Request, + Writer: tester.ctx.Writer, + CurrentUser: "u", + }).Return(nil) + tester.SetPath("git").WithQuery("service", "git-upload-pack").WithHeader("Git-Protocol", "ssh") + tester.WithKV("namespace", "u").WithKV("name", "r") + tester.WithKV("repo_type", "model").WithUser().WithHeader("Accept-Encoding", "gzip").Execute() + + require.Equal(t, 200, tester.response.Code) + headers := tester.response.Header() + require.Equal(t, "application/x-git-result", headers.Get("Content-Type")) + require.Equal(t, "no-cache", headers.Get("Cache-Control")) +} + +func TestGitHTTPHandler_LfsBatch(t *testing.T) { + + for _, c := range []string{"upload", "download"} { + t.Run("c", func(t *testing.T) { + + tester := NewGitHTTPTester(t).WithHandleFunc(func(h *GitHTTPHandler) gin.HandlerFunc { + return h.LfsBatch + }) + + tester.mocks.gitHttp.EXPECT().BuildObjectResponse(tester.ctx, types.BatchRequest{ + Namespace: "u", + Name: "r", + RepoType: types.ModelRepo, + CurrentUser: "u", + Authorization: "auth", + Operation: c, + }, c == "upload").Return(&types.BatchResponse{Transfer: "t"}, nil) + tester.SetPath("git").WithQuery("service", "git-upload-pack").WithHeader("Git-Protocol", "ssh") + tester.WithKV("namespace", "u").WithKV("name", "r").WithHeader("Authorization", "auth") + tester.WithBody(t, &types.BatchRequest{Operation: c}) + tester.WithKV("repo_type", "model").WithUser().WithHeader("Accept-Encoding", "gzip").Execute() + + tester.ResponseEqSimple(t, 200, &types.BatchResponse{Transfer: "t"}) + headers := tester.response.Header() + require.Equal(t, types.LfsMediaType, headers.Get("Content-Type")) + }) + } +} + +func TestGitHTTPHandler_LfsUpload(t *testing.T) { + tester := NewGitHTTPTester(t).WithHandleFunc(func(h *GitHTTPHandler) gin.HandlerFunc { + return h.LfsUpload + }) + + tester.mocks.gitHttp.EXPECT().LfsUpload(tester.ctx, tester.ctx.Request.Body, types.UploadRequest{ + Namespace: "u", + Name: "r", + RepoType: types.ModelRepo, + CurrentUser: "u", + Oid: "o", + Size: 100, + }).Return(nil) + tester.SetPath("git").WithParam("oid", "o").WithParam("size", "100") + tester.WithKV("namespace", "u").WithKV("name", "r").WithHeader("Authorization", "auth") + tester.WithKV("repo_type", "model").WithUser().Execute() + + require.Equal(t, 200, tester.response.Code) + headers := tester.response.Header() + require.Equal(t, types.LfsMediaType, headers.Get("Content-Type")) +} + +func TestGitHTTPHandler_LfsDownload(t *testing.T) { + tester := NewGitHTTPTester(t).WithHandleFunc(func(h *GitHTTPHandler) gin.HandlerFunc { + return h.LfsDownload + }) + + tester.mocks.gitHttp.EXPECT().LfsDownload(tester.ctx, types.DownloadRequest{ + Namespace: "u", + Name: "r", + RepoType: types.ModelRepo, + CurrentUser: "u", + Oid: "o", + Size: 100, + }).Return(&url.URL{Path: "url"}, nil) + tester.SetPath("git").WithParam("oid", "o").WithParam("size", "100") + tester.WithKV("namespace", "u").WithKV("name", "r").WithHeader("Authorization", "auth") + tester.WithKV("repo_type", "model").WithUser().Execute() + + require.Equal(t, 200, tester.response.Code) + resp := tester.response.Result() + defer resp.Body.Close() + lc, err := resp.Location() + require.NoError(t, err) + require.Equal(t, "url", lc.String()) +} + +func TestGitHTTPHandler_LfsVerify(t *testing.T) { + tester := NewGitHTTPTester(t).WithHandleFunc(func(h *GitHTTPHandler) gin.HandlerFunc { + return h.LfsVerify + }) + + tester.mocks.gitHttp.EXPECT().LfsVerify(tester.ctx, types.VerifyRequest{ + Namespace: "u", + Name: "r", + RepoType: types.ModelRepo, + CurrentUser: "u", + }, types.Pointer{Oid: "o"}).Return(nil) + tester.WithKV("namespace", "u").WithKV("name", "r").WithHeader("Authorization", "auth") + tester.WithKV("repo_type", "model").WithUser().WithBody(t, &types.Pointer{ + Oid: "o", + }).Execute() + + tester.ResponseEqSimple(t, 200, nil) +} + +func TestGitHTTPHandler_ListLocks(t *testing.T) { + tester := NewGitHTTPTester(t).WithHandleFunc(func(h *GitHTTPHandler) gin.HandlerFunc { + return h.ListLocks + }) + + tester.mocks.gitHttp.EXPECT().ListLocks(tester.ctx, types.ListLFSLockReq{ + ID: 1, + Namespace: "u", + Name: "r", + RepoType: types.ModelRepo, + CurrentUser: "u", + Cursor: 12, + Path: "p", + Limit: 5, + }).Return(&types.LFSLockList{Next: "n"}, nil) + tester.WithKV("namespace", "u").WithKV("name", "r").WithQuery("path", "p").WithQuery("id", "1") + tester.WithKV("repo_type", "model").WithUser().WithQuery("cursor", "12").WithQuery("limit", "5").Execute() + + tester.ResponseEqSimple(t, 200, &types.LFSLockList{Next: "n"}) +} + +func TestGitHTTPHandler_CreateLock(t *testing.T) { + tester := NewGitHTTPTester(t).WithHandleFunc(func(h *GitHTTPHandler) gin.HandlerFunc { + return h.CreateLock + }) + + tester.mocks.gitHttp.EXPECT().CreateLock(tester.ctx, types.LfsLockReq{ + Namespace: "u", + Name: "r", + RepoType: types.ModelRepo, + CurrentUser: "u", + }).Return(&database.LfsLock{ + ID: 1, + Path: "p", + User: database.User{Username: "u"}, + }, nil) + tester.WithKV("namespace", "u").WithKV("name", "r") + tester.WithKV("repo_type", "model").WithUser().WithBody(t, types.LfsLockReq{}).Execute() + + tester.ResponseEqSimple(t, 200, &types.LFSLockResponse{ + Lock: &types.LFSLock{ + ID: "1", + Path: "p", + Owner: &types.LFSLockOwner{ + Name: "u", + }, + }, + }) +} + +func TestGitHTTPHandler_VerifyLock(t *testing.T) { + tester := NewGitHTTPTester(t).WithHandleFunc(func(h *GitHTTPHandler) gin.HandlerFunc { + return h.VerifyLock + }) + + tester.mocks.gitHttp.EXPECT().VerifyLock(tester.ctx, types.VerifyLFSLockReq{ + Namespace: "u", + Name: "r", + RepoType: types.ModelRepo, + CurrentUser: "u", + }).Return(&types.LFSLockListVerify{ + Next: "n", + }, nil) + tester.WithKV("namespace", "u").WithKV("name", "r") + tester.WithKV("repo_type", "model").WithUser().WithBody(t, types.VerifyLFSLockReq{}).Execute() + + tester.ResponseEqSimple(t, 200, &types.LFSLockListVerify{ + Next: "n", + }) +} + +func TestGitHTTPHandler_UnLock(t *testing.T) { + tester := NewGitHTTPTester(t).WithHandleFunc(func(h *GitHTTPHandler) gin.HandlerFunc { + return h.UnLock + }) + + tester.mocks.gitHttp.EXPECT().UnLock(tester.ctx, types.UnlockLFSReq{ + ID: 1, + Namespace: "u", + Name: "r", + RepoType: types.ModelRepo, + CurrentUser: "u", + }).Return(&database.LfsLock{ + ID: 1, + Path: "p", + User: database.User{Username: "u"}, + }, nil) + tester.WithKV("namespace", "u").WithKV("name", "r").WithParam("lid", "1") + tester.WithKV("repo_type", "model").WithUser().WithBody(t, types.UnlockLFSReq{}).Execute() + + tester.ResponseEqSimple(t, 200, &types.LFSLockResponse{ + Lock: &types.LFSLock{ + ID: "1", + Path: "p", + Owner: &types.LFSLockOwner{ + Name: "u", + }, + }, + }) +} diff --git a/api/handler/helper_test.go b/api/handler/helper_test.go index 4c62d995..7b9bdc38 100644 --- a/api/handler/helper_test.go +++ b/api/handler/helper_test.go @@ -22,6 +22,7 @@ type GinTester struct { ctx *gin.Context response *httptest.ResponseRecorder OKText string // text of httpbase.OK + _executed bool } func NewGinTester() *GinTester { @@ -45,6 +46,7 @@ func (g *GinTester) Handler(handler gin.HandlerFunc) { func (g *GinTester) Execute() { g.ginHandler(g.ctx) + g._executed = true } func (g *GinTester) WithUser() *GinTester { g.ctx.Set(httpbase.CurrentUserCtxVar, "u") @@ -87,6 +89,21 @@ func (g *GinTester) WithQuery(key, value string) *GinTester { return g } +func (g *GinTester) SetPath(path string) *GinTester { + g.ctx.Request.URL.Path = path + return g +} + +func (g *GinTester) WithHeader(key, value string) *GinTester { + h := g.ctx.Request.Header + if h == nil { + h = map[string][]string{} + } + h.Add(key, value) + g.ctx.Request.Header = h + return g +} + func (g *GinTester) AddPagination(page int, per int) *GinTester { g.WithQuery("page", cast.ToString(page)) g.WithQuery("per", cast.ToString(per)) @@ -94,6 +111,9 @@ func (g *GinTester) AddPagination(page int, per int) *GinTester { } func (g *GinTester) ResponseEq(t *testing.T, code int, msg string, expected any) { + if !g._executed { + require.FailNow(t, "call Execute method first") + } var r = struct { Msg string `json:"msg"` Data any `json:"data,omitempty"` @@ -109,9 +129,12 @@ func (g *GinTester) ResponseEq(t *testing.T, code int, msg string, expected any) } func (g *GinTester) ResponseEqSimple(t *testing.T, code int, expected any) { + if !g._executed { + require.FailNow(t, "call Execute method first") + } b, err := json.Marshal(expected) require.NoError(t, err) - require.Equal(t, code, g.response.Code) + require.Equal(t, code, g.response.Code, g.response.Body.String()) require.JSONEq(t, string(b), g.response.Body.String()) } @@ -121,6 +144,7 @@ func (g *GinTester) RequireUser(t *testing.T) { tmp := NewGinTester() tmp.ctx.Params = g.ctx.Params g.ginHandler(tmp.ctx) + tmp._executed = true tmp.ResponseEq(t, http.StatusUnauthorized, component.ErrUserNotFound.Error(), nil) // add user to original test ctx now _ = g.WithUser() diff --git a/api/handler/model.go b/api/handler/model.go index cd0eb829..218c1294 100644 --- a/api/handler/model.go +++ b/api/handler/model.go @@ -32,16 +32,16 @@ func NewModelHandler(config *config.Config) (*ModelHandler, error) { } return &ModelHandler{ - c: uc, - sc: sc, - repo: repo, + model: uc, + sensitive: sc, + repo: repo, }, nil } type ModelHandler struct { - c component.ModelComponent - sc component.SensitiveComponent - repo component.RepoComponent + model component.ModelComponent + repo component.RepoComponent + sensitive component.SensitiveComponent } // GetVisiableModels godoc @@ -92,7 +92,8 @@ func (h *ModelHandler) Index(ctx *gin.Context) { return } - models, total, err := h.c.Index(ctx, filter, per, page, false) + models, total, err := h.model.Index(ctx, filter, per, page, false) + if err != nil { slog.Error("Failed to get models", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -133,14 +134,14 @@ func (h *ModelHandler) Create(ctx *gin.Context) { } req.Username = currentUser - _, err := h.sc.CheckRequestV2(ctx, req) + _, err := h.sensitive.CheckRequestV2(ctx, req) if err != nil { slog.Error("failed to check sensitive request", slog.Any("error", err)) httpbase.BadRequest(ctx, fmt.Errorf("sensitive check failed: %w", err).Error()) return } - model, err := h.c.Create(ctx, req) + model, err := h.model.Create(ctx, req) if err != nil { slog.Error("Failed to create model", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -178,7 +179,7 @@ func (h *ModelHandler) Update(ctx *gin.Context) { return } - _, err := h.sc.CheckRequestV2(ctx, req) + _, err := h.sensitive.CheckRequestV2(ctx, req) if err != nil { slog.Error("failed to check sensitive request", slog.Any("error", err)) httpbase.BadRequest(ctx, fmt.Errorf("sensitive check failed: %w", err).Error()) @@ -195,7 +196,7 @@ func (h *ModelHandler) Update(ctx *gin.Context) { req.Name = name req.Username = currentUser - model, err := h.c.Update(ctx, req) + model, err := h.model.Update(ctx, req) if err != nil { slog.Error("Failed to update model", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -232,7 +233,7 @@ func (h *ModelHandler) Delete(ctx *gin.Context) { httpbase.BadRequest(ctx, err.Error()) return } - err = h.c.Delete(ctx, namespace, name, currentUser) + err = h.model.Delete(ctx, namespace, name, currentUser) if err != nil { slog.Error("Failed to delete model", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -264,7 +265,8 @@ func (h *ModelHandler) Show(ctx *gin.Context) { return } currentUser := httpbase.GetCurrentUser(ctx) - detail, err := h.c.Show(ctx, namespace, name, currentUser, false) + detail, err := h.model.Show(ctx, namespace, name, currentUser, false) + if err != nil { if errors.Is(err, component.ErrUnauthorized) { httpbase.UnauthorizedError(ctx, err) @@ -292,7 +294,7 @@ func (h *ModelHandler) SDKModelInfo(ctx *gin.Context) { ref = mappedBranch } currentUser := httpbase.GetCurrentUser(ctx) - modelInfo, err := h.c.SDKModelInfo(ctx, namespace, name, ref, currentUser) + modelInfo, err := h.model.SDKModelInfo(ctx, namespace, name, ref, currentUser) if err != nil { if errors.Is(err, component.ErrUnauthorized) { httpbase.UnauthorizedError(ctx, err) @@ -327,7 +329,7 @@ func (h *ModelHandler) Relations(ctx *gin.Context) { return } currentUser := httpbase.GetCurrentUser(ctx) - detail, err := h.c.Relations(ctx, namespace, name, currentUser) + detail, err := h.model.Relations(ctx, namespace, name, currentUser) if err != nil { if errors.Is(err, component.ErrUnauthorized) { httpbase.UnauthorizedError(ctx, err) @@ -379,7 +381,7 @@ func (h *ModelHandler) SetRelations(ctx *gin.Context) { req.Name = name req.CurrentUser = currentUser - err = h.c.SetRelationDatasets(ctx, req) + err = h.model.SetRelationDatasets(ctx, req) if err != nil { slog.Error("Failed to set datasets for model", slog.Any("req", req), slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -426,7 +428,7 @@ func (h *ModelHandler) AddDatasetRelation(ctx *gin.Context) { req.Name = name req.CurrentUser = currentUser - err = h.c.AddRelationDataset(ctx, req) + err = h.model.AddRelationDataset(ctx, req) if err != nil { slog.Error("Failed to add dataset for model", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -473,7 +475,7 @@ func (h *ModelHandler) DelDatasetRelation(ctx *gin.Context) { req.Name = name req.CurrentUser = currentUser - err = h.c.DelRelationDataset(ctx, req) + err = h.model.DelRelationDataset(ctx, req) if err != nil { slog.Error("Failed to delete dataset for model", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -598,7 +600,7 @@ func (h *ModelHandler) DeployDedicated(ctx *gin.Context) { return } - _, err = h.sc.CheckRequestV2(ctx, &req) + _, err = h.sensitive.CheckRequestV2(ctx, &req) if err != nil { slog.Error("failed to check sensitive request", slog.Any("error", err)) httpbase.BadRequest(ctx, fmt.Errorf("sensitive check failed: %w", err).Error()) @@ -611,7 +613,7 @@ func (h *ModelHandler) DeployDedicated(ctx *gin.Context) { CurrentUser: currentUser, DeployType: types.InferenceType, } - deployID, err := h.c.Deploy(ctx, epReq, req) + deployID, err := h.model.Deploy(ctx, epReq, req) if err != nil { slog.Error("failed to deploy model as inference", slog.String("namespace", namespace), slog.String("name", name), slog.Any("currentUser", currentUser), slog.Any("req", req), slog.Any("error", err)) @@ -693,7 +695,7 @@ func (h *ModelHandler) FinetuneCreate(ctx *gin.Context) { DeployType: types.FinetuneType, } - deployID, err := h.c.Deploy(ctx, ftReq, *modelReq) + deployID, err := h.model.Deploy(ctx, ftReq, *modelReq) if err != nil { slog.Error("failed to deploy model as notebook instance", slog.String("namespace", namespace), slog.String("name", name), slog.Any("error", err)) @@ -975,7 +977,7 @@ func (h *ModelHandler) ListByRuntimeFrameworkID(ctx *gin.Context) { return } - models, total, err := h.c.ListModelsByRuntimeFrameworkID(ctx, currentUser, per, page, id, deployType) + models, total, err := h.model.ListModelsByRuntimeFrameworkID(ctx, currentUser, per, page, id, deployType) if err != nil { slog.Error("Failed to get models", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -1115,7 +1117,7 @@ func (h *ModelHandler) ListAllRuntimeFramework(ctx *gin.Context) { return } - runtimes, err := h.c.ListAllByRuntimeFramework(ctx, currentUser) + runtimes, err := h.model.ListAllByRuntimeFramework(ctx, currentUser) if err != nil { slog.Error("Failed to get runtime frameworks", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -1171,7 +1173,7 @@ func (h *ModelHandler) UpdateModelRuntimeFrameworks(ctx *gin.Context) { slog.Info("update runtime frameworks models", slog.Any("req", req), slog.Any("runtime framework id", id), slog.Any("deployType", deployType)) - list, err := h.c.SetRuntimeFrameworkModes(ctx, deployType, id, req.Models) + list, err := h.model.SetRuntimeFrameworkModes(ctx, deployType, id, req.Models) if err != nil { slog.Error("Failed to set models runtime framework", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -1224,7 +1226,7 @@ func (h *ModelHandler) DeleteModelRuntimeFrameworks(ctx *gin.Context) { slog.Info("update runtime frameworks models", slog.Any("req", req), slog.Any("runtime framework id", id), slog.Any("deployType", deployType)) - list, err := h.c.DeleteRuntimeFrameworkModes(ctx, deployType, id, req.Models) + list, err := h.model.DeleteRuntimeFrameworkModes(ctx, deployType, id, req.Models) if err != nil { slog.Error("Failed to set models runtime framework", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -1277,7 +1279,7 @@ func (h *ModelHandler) ListModelsOfRuntimeFrameworks(ctx *gin.Context) { return } - models, total, err := h.c.ListModelsOfRuntimeFrameworks(ctx, currentUser, filter.Search, filter.Sort, per, page, deployType) + models, total, err := h.model.ListModelsOfRuntimeFrameworks(ctx, currentUser, filter.Search, filter.Sort, per, page, deployType) if err != nil { slog.Error("fail to get models for all runtime frameworks", slog.Any("deployType", deployType), slog.Any("per", per), slog.Any("page", page), slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -1382,7 +1384,7 @@ func (h *ModelHandler) DeployServerless(ctx *gin.Context) { } req.SecureLevel = 1 // public for serverless - deployID, err := h.c.Deploy(ctx, deployReq, req) + deployID, err := h.model.Deploy(ctx, deployReq, req) if err != nil { slog.Error("failed to deploy model as serverless", slog.String("namespace", namespace), slog.String("name", name), slog.Any("currentUser", currentUser), slog.Any("req", req), slog.Any("error", err)) @@ -1532,7 +1534,7 @@ func (h *ModelHandler) GetDeployServerless(ctx *gin.Context) { return } - response, err := h.c.GetServerless(ctx, namespace, name, currentUser) + response, err := h.model.GetServerless(ctx, namespace, name, currentUser) if err != nil { slog.Error("failed to get model serverless endpoint", slog.String("namespace", namespace), slog.String("name", name), slog.Any("currentUser", currentUser), slog.Any("error", err)) diff --git a/api/handler/model_test.go b/api/handler/model_test.go new file mode 100644 index 00000000..5a082cdc --- /dev/null +++ b/api/handler/model_test.go @@ -0,0 +1,561 @@ +package handler + +import ( + "fmt" + "testing" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/require" + mockcomponent "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/component" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/types" +) + +type ModelTester struct { + *GinTester + handler *ModelHandler + mocks struct { + model *mockcomponent.MockModelComponent + sensitive *mockcomponent.MockSensitiveComponent + repo *mockcomponent.MockRepoComponent + } +} + +func NewModelTester(t *testing.T) *ModelTester { + tester := &ModelTester{GinTester: NewGinTester()} + tester.mocks.model = mockcomponent.NewMockModelComponent(t) + tester.mocks.sensitive = mockcomponent.NewMockSensitiveComponent(t) + tester.mocks.repo = mockcomponent.NewMockRepoComponent(t) + + tester.handler = &ModelHandler{ + model: tester.mocks.model, sensitive: tester.mocks.sensitive, + repo: tester.mocks.repo, + } + tester.WithParam("name", "r") + tester.WithParam("namespace", "u") + return tester + +} + +func (t *ModelTester) WithHandleFunc(fn func(h *ModelHandler) gin.HandlerFunc) *ModelTester { + t.ginHandler = fn(t.handler) + return t + +} + +func TestModelHandler_Index(t *testing.T) { + cases := []struct { + sort string + source string + error bool + }{ + {"most_download", "local", false}, + {"foo", "local", true}, + {"most_download", "bar", true}, + } + + for _, c := range cases { + t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) { + + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.Index + }) + + if !c.error { + tester.mocks.model.EXPECT().Index(tester.ctx, &types.RepoFilter{ + Search: "foo", + Sort: c.sort, + Source: c.source, + }, 10, 1, false).Return([]*types.Model{ + {Name: "cc"}, + }, 100, nil) + } + + tester.AddPagination(1, 10).WithQuery("search", "foo"). + WithQuery("sort", c.sort). + WithQuery("source", c.source).Execute() + + if c.error { + require.Equal(t, 400, tester.response.Code) + } else { + tester.ResponseEqSimple(t, 200, gin.H{ + "data": []*types.Model{{Name: "cc"}}, + "total": 100, + }) + } + }) + } +} + +func TestModelHandler_Create(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.Create + }) + tester.RequireUser(t) + + req := &types.CreateModelReq{CreateRepoReq: types.CreateRepoReq{Username: "u"}} + tester.mocks.sensitive.EXPECT().CheckRequestV2(tester.ctx, req).Return(true, nil) + tester.mocks.model.EXPECT().Create(tester.ctx, req).Return(&types.Model{Name: "m"}, nil) + tester.WithBody(t, req).Execute() + + tester.ResponseEq(t, 200, tester.OKText, &types.Model{Name: "m"}) +} + +func TestModelHandler_Update(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.Update + }) + tester.RequireUser(t) + + req := &types.UpdateModelReq{UpdateRepoReq: types.UpdateRepoReq{}} + tester.mocks.sensitive.EXPECT().CheckRequestV2(tester.ctx, req).Return(true, nil) + tester.mocks.model.EXPECT().Update(tester.ctx, &types.UpdateModelReq{ + UpdateRepoReq: types.UpdateRepoReq{ + Namespace: "u", + Name: "r", + Username: "u", + }, + }).Return(&types.Model{Name: "m"}, nil) + tester.WithBody(t, req).Execute() + + tester.ResponseEq(t, 200, tester.OKText, &types.Model{Name: "m"}) +} + +func TestModelHandler_Delete(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.Delete + }) + tester.RequireUser(t) + + tester.mocks.model.EXPECT().Delete(tester.ctx, "u", "r", "u").Return(nil) + tester.Execute() + + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestModelHandler_Show(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.Show + }) + + tester.WithUser() + tester.mocks.model.EXPECT().Show(tester.ctx, "u", "r", "u", false).Return(&types.Model{ + Name: "m", + }, nil) + tester.Execute() + + tester.ResponseEq(t, 200, tester.OKText, &types.Model{Name: "m"}) +} + +func TestModelHandler_SDKModelInfo(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.SDKModelInfo + }) + + tester.WithUser() + tester.mocks.model.EXPECT().SDKModelInfo(tester.ctx, "u", "r", "main", "u").Return(&types.SDKModelInfo{ + ID: "m", + }, nil) + tester.WithParam("ref", "main").Execute() + + tester.ResponseEqSimple(t, 200, &types.SDKModelInfo{ID: "m"}) +} + +func TestModelHandler_Relations(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.Relations + }) + + tester.WithUser() + tester.mocks.model.EXPECT().Relations(tester.ctx, "u", "r", "u").Return(&types.Relations{ + Models: []*types.Model{{Name: "m1"}}, + }, nil) + tester.Execute() + + tester.ResponseEq(t, 200, tester.OKText, &types.Relations{ + Models: []*types.Model{{Name: "m1"}}, + }) +} + +func TestModelHandler_SetRelations(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.SetRelations + }) + tester.RequireUser(t) + + req := &types.RelationDatasets{ + Namespace: "u", + Name: "r", + CurrentUser: "u", + } + tester.mocks.model.EXPECT().SetRelationDatasets(tester.ctx, *req).Return(nil) + tester.WithBody(t, &types.RelationDatasets{}).Execute() + + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestModelHandler_AddDatasetRelation(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.AddDatasetRelation + }) + tester.RequireUser(t) + + req := &types.RelationDataset{ + Namespace: "u", + Name: "r", + CurrentUser: "u", + } + tester.mocks.model.EXPECT().AddRelationDataset(tester.ctx, *req).Return(nil) + tester.WithBody(t, &types.RelationDataset{}).Execute() + + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestModelHandler_DelDatasetRelation(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.DelDatasetRelation + }) + tester.RequireUser(t) + + req := &types.RelationDataset{ + Namespace: "u", + Name: "r", + CurrentUser: "u", + } + tester.mocks.model.EXPECT().DelRelationDataset(tester.ctx, *req).Return(nil) + tester.WithBody(t, &types.RelationDataset{}).Execute() + + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestModelHandler_DeployDedicated(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.DeployDedicated + }) + tester.RequireUser(t) + + tester.mocks.repo.EXPECT().AllowReadAccess(tester.ctx, types.ModelRepo, "u", "r", "u").Return(true, nil) + tester.mocks.sensitive.EXPECT().CheckRequestV2(tester.ctx, &types.ModelRunReq{ + Revision: "main", + MinReplica: 1, + MaxReplica: 2, + }).Return(true, nil) + tester.mocks.model.EXPECT().Deploy(tester.ctx, types.DeployActReq{ + Namespace: "u", + Name: "r", + CurrentUser: "u", + DeployType: types.InferenceType, + }, types.ModelRunReq{MinReplica: 1, MaxReplica: 2, Revision: "main"}).Return(123, nil) + + tester.WithBody(t, &types.ModelRunReq{MinReplica: 1, MaxReplica: 2}).Execute() + + tester.ResponseEq(t, 200, tester.OKText, types.DeployRepo{DeployID: 123}) +} + +func TestModelHandler_FinetuneCreate(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.FinetuneCreate + }) + tester.RequireUser(t) + + tester.mocks.repo.EXPECT().AllowAdminAccess(tester.ctx, types.ModelRepo, "u", "r", "u").Return(true, nil) + + tester.mocks.model.EXPECT().Deploy(tester.ctx, types.DeployActReq{ + Namespace: "u", + Name: "r", + CurrentUser: "u", + DeployType: types.FinetuneType, + }, types.ModelRunReq{MinReplica: 1, MaxReplica: 1, Revision: "main", SecureLevel: 2}).Return(123, nil) + + tester.WithBody(t, &types.ModelRunReq{MinReplica: 1, MaxReplica: 2, Revision: "main"}).Execute() + + tester.ResponseEq(t, 200, tester.OKText, types.DeployRepo{DeployID: 123}) + +} + +func TestModelHandler_DeployDelete(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.DeployDelete + }) + tester.RequireUser(t) + + tester.mocks.repo.EXPECT().DeleteDeploy(tester.ctx, types.DeployActReq{ + RepoType: types.ModelRepo, + Namespace: "u", + Name: "r", + CurrentUser: "u", + DeployID: 1, + DeployType: types.InferenceType, + }).Return(nil) + + tester.WithParam("id", "1").Execute() + + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestModelHandler_FinetuneDelete(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.FinetuneDelete + }) + tester.RequireUser(t) + + tester.mocks.repo.EXPECT().DeleteDeploy(tester.ctx, types.DeployActReq{ + RepoType: types.ModelRepo, + Namespace: "u", + Name: "r", + CurrentUser: "u", + DeployID: 1, + DeployType: types.FinetuneType, + }).Return(nil) + + tester.WithParam("id", "1").Execute() + + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestModelHandler_DeployStop(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.DeployStop + }) + tester.RequireUser(t) + + tester.mocks.repo.EXPECT().DeployStop(tester.ctx, types.DeployActReq{ + RepoType: types.ModelRepo, + Namespace: "u", + Name: "r", + CurrentUser: "u", + DeployID: 1, + DeployType: types.InferenceType, + }).Return(nil) + + tester.WithParam("id", "1").Execute() + + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestModelHandler_DeployStart(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.DeployStart + }) + tester.RequireUser(t) + + tester.mocks.repo.EXPECT().DeployStart(tester.ctx, types.DeployActReq{ + RepoType: types.ModelRepo, + Namespace: "u", + Name: "r", + CurrentUser: "u", + DeployID: 1, + DeployType: types.InferenceType, + }).Return(nil) + + tester.WithParam("id", "1").Execute() + + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestModelHandler_FinetuneStop(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.FinetuneStop + }) + tester.RequireUser(t) + + tester.mocks.repo.EXPECT().DeployStop(tester.ctx, types.DeployActReq{ + RepoType: types.ModelRepo, + Namespace: "u", + Name: "r", + CurrentUser: "u", + DeployID: 1, + DeployType: types.FinetuneType, + }).Return(nil) + + tester.WithParam("id", "1").Execute() + + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestModelHandler_FinetuneStart(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.FinetuneStart + }) + tester.RequireUser(t) + + tester.mocks.repo.EXPECT().DeployStart(tester.ctx, types.DeployActReq{ + RepoType: types.ModelRepo, + Namespace: "u", + Name: "r", + CurrentUser: "u", + DeployID: 1, + DeployType: types.FinetuneType, + }).Return(nil) + + tester.WithParam("id", "1").Execute() + + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestModelHandler_ListByRuntimeFrameworkID(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.ListByRuntimeFrameworkID + }) + tester.RequireUser(t) + + tester.WithQuery("deploy_type", "").AddPagination(1, 10).WithParam("id", "1") + tester.mocks.model.EXPECT().ListModelsByRuntimeFrameworkID( + tester.ctx, "u", 10, 1, int64(1), types.InferenceType, + ).Return([]types.Model{{Name: "foo"}}, 100, nil) + tester.Execute() + tester.ResponseEqSimple(t, 200, gin.H{ + "data": []types.Model{{Name: "foo"}}, + "total": 100, + }) +} + +func TestModelHandler_ListAllRuntimeFramework(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.ListAllRuntimeFramework + }) + tester.RequireUser(t) + + tester.mocks.model.EXPECT().ListAllByRuntimeFramework( + tester.ctx, "u", + ).Return([]database.RuntimeFramework{{FrameName: "foo"}}, nil) + tester.Execute() + tester.ResponseEqSimple(t, 200, gin.H{ + "data": []database.RuntimeFramework{{FrameName: "foo"}}, + }) +} + +func TestModelHandler_UpdateModelRuntimeFramework(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.UpdateModelRuntimeFrameworks + }) + + tester.WithUser().WithQuery("deploy_type", "").AddPagination(1, 10).WithParam("id", "1") + tester.mocks.model.EXPECT().SetRuntimeFrameworkModes( + tester.ctx, types.InferenceType, int64(1), []string{"foo"}, + ).Return([]string{"bar"}, nil) + tester.WithBody(t, types.RuntimeFrameworkModels{ + Models: []string{"foo"}, + }).Execute() + tester.ResponseEq(t, 200, tester.OKText, []string{"bar"}) +} + +func TestModelHandler_DeleteModelRuntimeFramework(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.DeleteModelRuntimeFrameworks + }) + + tester.WithUser().WithQuery("deploy_type", "").AddPagination(1, 10).WithParam("id", "1") + tester.mocks.model.EXPECT().DeleteRuntimeFrameworkModes( + tester.ctx, types.InferenceType, int64(1), []string{"foo"}, + ).Return([]string{"bar"}, nil) + tester.WithBody(t, types.RuntimeFrameworkModels{ + Models: []string{"foo"}, + }).Execute() + tester.ResponseEq(t, 200, tester.OKText, []string{"bar"}) +} + +func TestModelHandler_ListModelsOfRuntimeFrameworks(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.ListModelsOfRuntimeFrameworks + }) + tester.RequireUser(t) + + tester.WithQuery("deploy_type", "").AddPagination(1, 10).WithParam("id", "1") + tester.mocks.model.EXPECT().ListModelsOfRuntimeFrameworks( + tester.ctx, "u", "foo", "most_downloads", 10, 1, types.InferenceType, + ).Return([]types.Model{{Name: "foo"}}, 100, nil) + tester.WithQuery("search", "foo").WithQuery("sort", "most_downloads").Execute() + + tester.ResponseEqSimple(t, 200, gin.H{ + "data": []types.Model{{Name: "foo"}}, + "total": 100, + }) +} + +func TestModelHandler_AllFiles(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.AllFiles + }) + + tester.mocks.repo.EXPECT().AllFiles(tester.ctx, types.GetAllFilesReq{ + Namespace: "u", + Name: "r", + RepoType: types.ModelRepo, + CurrentUser: "u", + }).Return([]*types.File{{Name: "foo"}}, nil) + tester.WithUser().Execute() + + tester.ResponseEq(t, 200, tester.OKText, []*types.File{{Name: "foo"}}) +} + +func TestModelHandler_DeployServerless(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.DeployServerless + }) + tester.RequireUser(t) + + tester.mocks.model.EXPECT().Deploy(tester.ctx, types.DeployActReq{ + Namespace: "u", + Name: "r", + CurrentUser: "u", + DeployType: types.ServerlessType, + }, types.ModelRunReq{MinReplica: 1, MaxReplica: 2, Revision: "main", SecureLevel: 1}).Return(123, nil) + + tester.WithBody(t, &types.ModelRunReq{MinReplica: 1, MaxReplica: 2}).Execute() + + tester.ResponseEq(t, 200, tester.OKText, types.DeployRepo{DeployID: 123}) +} + +func TestModelHandler_ServerlessStop(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.ServerlessStop + }) + tester.RequireUser(t) + + tester.mocks.repo.EXPECT().DeployStop(tester.ctx, types.DeployActReq{ + RepoType: types.ModelRepo, + Namespace: "u", + Name: "r", + CurrentUser: "u", + DeployID: 1, + DeployType: types.ServerlessType, + }).Return(nil) + + tester.WithParam("id", "1").Execute() + + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestModelHandler_ServerlessStart(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.ServerlessStart + }) + tester.RequireUser(t) + + tester.mocks.repo.EXPECT().DeployStart(tester.ctx, types.DeployActReq{ + RepoType: types.ModelRepo, + Namespace: "u", + Name: "r", + CurrentUser: "u", + DeployID: 1, + DeployType: types.ServerlessType, + }).Return(nil) + + tester.WithParam("id", "1").Execute() + + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestModelHandler_GetDeployServerless(t *testing.T) { + tester := NewModelTester(t).WithHandleFunc(func(h *ModelHandler) gin.HandlerFunc { + return h.GetDeployServerless + }) + + tester.mocks.model.EXPECT().GetServerless(tester.ctx, "u", "r", "u").Return(&types.DeployRepo{ + DeployID: 1, + }, nil) + tester.WithUser().Execute() + + tester.ResponseEq(t, 200, tester.OKText, &types.DeployRepo{DeployID: 1}) +} diff --git a/api/handler/user.go b/api/handler/user.go index c062710f..41984d76 100644 --- a/api/handler/user.go +++ b/api/handler/user.go @@ -20,12 +20,12 @@ func NewUserHandler(config *config.Config) (*UserHandler, error) { return nil, err } return &UserHandler{ - c: uc, + user: uc, }, nil } type UserHandler struct { - c component.UserComponent + user component.UserComponent } // GetUserDatasets godoc @@ -53,7 +53,7 @@ func (h *UserHandler) Datasets(ctx *gin.Context) { req.CurrentUser = httpbase.GetCurrentUser(ctx) req.Page = page req.PageSize = per - ds, total, err := h.c.Datasets(ctx, &req) + ds, total, err := h.user.Datasets(ctx, &req) if err != nil { slog.Error("Failed to gat user datasets", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -94,7 +94,7 @@ func (h *UserHandler) Models(ctx *gin.Context) { req.CurrentUser = httpbase.GetCurrentUser(ctx) req.Page = page req.PageSize = per - ms, total, err := h.c.Models(ctx, &req) + ms, total, err := h.user.Models(ctx, &req) if err != nil { slog.Error("Failed to gat user models", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -136,7 +136,7 @@ func (h *UserHandler) Codes(ctx *gin.Context) { req.CurrentUser = httpbase.GetCurrentUser(ctx) req.Page = page req.PageSize = per - ms, total, err := h.c.Codes(ctx, &req) + ms, total, err := h.user.Codes(ctx, &req) if err != nil { slog.Error("Failed to gat user codes", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -177,7 +177,7 @@ func (h *UserHandler) Spaces(ctx *gin.Context) { req.CurrentUser = httpbase.GetCurrentUser(ctx) req.Page = page req.PageSize = per - ms, total, err := h.c.Spaces(ctx, &req) + ms, total, err := h.user.Spaces(ctx, &req) if err != nil { slog.Error("Failed to gat user space", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -219,8 +219,8 @@ func (h *UserHandler) LikesAdd(ctx *gin.Context) { httpbase.ServerError(ctx, err) return } - req.Repo_id = repo_id - err = h.c.AddLikes(ctx, &req) + req.RepoID = repo_id + err = h.user.AddLikes(ctx, &req) if err != nil { httpbase.ServerError(ctx, err) return @@ -257,7 +257,7 @@ func (h *UserHandler) LikesCollections(ctx *gin.Context) { req.CurrentUser = httpbase.GetCurrentUser(ctx) req.Page = page req.PageSize = per - ms, total, err := h.c.LikesCollection(ctx, &req) + ms, total, err := h.user.LikesCollection(ctx, &req) if err != nil { slog.Error("Failed to get user collections", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -296,7 +296,7 @@ func (h *UserHandler) UserCollections(ctx *gin.Context) { req.CurrentUser = httpbase.GetCurrentUser(ctx) req.Page = page req.PageSize = per - ms, total, err := h.c.Collections(ctx, &req) + ms, total, err := h.user.Collections(ctx, &req) if err != nil { slog.Error("Failed to get user collections", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -331,13 +331,13 @@ func (h *UserHandler) LikeCollection(ctx *gin.Context) { } var req types.UserLikesRequest req.CurrentUser = currentUser - collection_id, err := strconv.ParseInt(ctx.Param("id"), 10, 64) + collectionID, err := strconv.ParseInt(ctx.Param("id"), 10, 64) if err != nil { httpbase.ServerError(ctx, err) return } - req.Collection_id = collection_id - err = h.c.LikeCollection(ctx, &req) + req.CollectionID = collectionID + err = h.user.LikeCollection(ctx, &req) if err != nil { httpbase.ServerError(ctx, err) return @@ -370,8 +370,8 @@ func (h *UserHandler) UnLikeCollection(ctx *gin.Context) { httpbase.ServerError(ctx, err) return } - req.Collection_id = collection_id - err = h.c.UnLikeCollection(ctx, &req) + req.CollectionID = collection_id + err = h.user.UnLikeCollection(ctx, &req) if err != nil { httpbase.ServerError(ctx, err) return @@ -406,9 +406,9 @@ func (h *UserHandler) LikesDelete(ctx *gin.Context) { httpbase.ServerError(ctx, err) return } - req.Repo_id = repo_id + req.RepoID = repo_id // slog.Info("user.likes.delete.req=%v", req) - err = h.c.DeleteLikes(ctx, &req) + err = h.user.DeleteLikes(ctx, &req) if err != nil { httpbase.ServerError(ctx, err) return @@ -446,7 +446,7 @@ func (h *UserHandler) LikesSpaces(ctx *gin.Context) { req.Page = page req.PageSize = per - ms, total, err := h.c.LikesSpaces(ctx, &req) + ms, total, err := h.user.LikesSpaces(ctx, &req) if err != nil { slog.Error("Failed to gat user space", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -492,7 +492,7 @@ func (h *UserHandler) LikesCodes(ctx *gin.Context) { req.CurrentUser = currentUser req.Page = page req.PageSize = per - ms, total, err := h.c.LikesCodes(ctx, &req) + ms, total, err := h.user.LikesCodes(ctx, &req) if err != nil { slog.Error("Failed to gat user codes", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -539,7 +539,7 @@ func (h *UserHandler) LikesModels(ctx *gin.Context) { req.CurrentUser = currentUser req.Page = page req.PageSize = per - ms, total, err := h.c.LikesModels(ctx, &req) + ms, total, err := h.user.LikesModels(ctx, &req) if err != nil { slog.Error("Failed to gat user models", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -586,7 +586,7 @@ func (h *UserHandler) LikesDatasets(ctx *gin.Context) { req.CurrentUser = currentUser req.Page = page req.PageSize = per - ds, total, err := h.c.LikesDatasets(ctx, &req) + ds, total, err := h.user.LikesDatasets(ctx, &req) if err != nil { slog.Error("Failed to gat user datasets", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -683,7 +683,7 @@ func (h *UserHandler) GetRunDeploys(ctx *gin.Context) { req.PageSize = per req.RepoType = repoType req.DeployType = deployType - ds, total, err := h.c.ListDeploys(ctx, repoType, &req) + ds, total, err := h.user.ListDeploys(ctx, repoType, &req) if err != nil { slog.Error("Failed to get deploy repo list", slog.Any("error", err), slog.Any("req", req)) httpbase.ServerError(ctx, err) @@ -743,7 +743,7 @@ func (h *UserHandler) GetFinetuneInstances(ctx *gin.Context) { req.CurrentUser = currentUser req.Page = page req.PageSize = per - ds, total, err := h.c.ListInstances(ctx, &req) + ds, total, err := h.user.ListInstances(ctx, &req) if err != nil { slog.Error("Failed to get instance list", slog.Any("error", err), slog.Any("req", req)) httpbase.ServerError(ctx, err) @@ -799,7 +799,7 @@ func (h *UserHandler) GetRunServerless(ctx *gin.Context) { req.PageSize = per req.RepoType = types.ModelRepo req.DeployType = types.ServerlessType - ds, total, err := h.c.ListServerless(ctx, req) + ds, total, err := h.user.ListServerless(ctx, req) if err != nil { slog.Error("Failed to get serverless list", slog.Any("error", err), slog.Any("req", req)) httpbase.ServerError(ctx, err) @@ -840,7 +840,7 @@ func (h *UserHandler) Prompts(ctx *gin.Context) { req.CurrentUser = httpbase.GetCurrentUser(ctx) req.Page = page req.PageSize = per - ds, total, err := h.c.Prompts(ctx, &req) + ds, total, err := h.user.Prompts(ctx, &req) if err != nil { slog.Error("Failed to get user prompts", slog.Any("error", err)) httpbase.ServerError(ctx, err) @@ -887,7 +887,7 @@ func (h *UserHandler) GetEvaluations(ctx *gin.Context) { req.CurrentUser = httpbase.GetCurrentUser(ctx) req.Page = page req.PageSize = per - ds, total, err := h.c.Evaluations(ctx, &req) + ds, total, err := h.user.Evaluations(ctx, &req) if err != nil { slog.Error("Failed to get user evaluations", slog.Any("error", err)) httpbase.ServerError(ctx, err) diff --git a/api/handler/user_test.go b/api/handler/user_test.go new file mode 100644 index 00000000..d8544d54 --- /dev/null +++ b/api/handler/user_test.go @@ -0,0 +1,439 @@ +package handler + +import ( + "testing" + + "github.com/gin-gonic/gin" + mockcomponent "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/component" + "opencsg.com/csghub-server/common/types" +) + +type UserTester struct { + *GinTester + handler *UserHandler + mocks struct { + user *mockcomponent.MockUserComponent + } +} + +func NewUserTester(t *testing.T) *UserTester { + tester := &UserTester{GinTester: NewGinTester()} + tester.mocks.user = mockcomponent.NewMockUserComponent(t) + + tester.handler = &UserHandler{ + user: tester.mocks.user, + } + tester.WithParam("name", "u") + tester.WithParam("namespace", "r") + return tester +} + +func (t *UserTester) WithHandleFunc(fn func(h *UserHandler) gin.HandlerFunc) *UserTester { + t.ginHandler = fn(t.handler) + return t +} + +func TestUserHandler_Datasets(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.Datasets + }) + + tester.mocks.user.EXPECT().Datasets(tester.ctx, &types.UserDatasetsReq{ + Owner: "go", + CurrentUser: "u", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.Dataset{{Name: "ds"}}, 100, nil) + tester.AddPagination(1, 10).WithUser().WithParam("username", "go").Execute() + tester.ResponseEqSimple(t, 200, gin.H{ + "message": "OK", + "data": []types.Dataset{{Name: "ds"}}, + "total": 100, + }) +} + +func TestUserHandler_Models(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.Models + }) + + tester.mocks.user.EXPECT().Models(tester.ctx, &types.UserDatasetsReq{ + Owner: "go", + CurrentUser: "u", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.Model{{Name: "ds"}}, 100, nil) + tester.AddPagination(1, 10).WithUser().WithParam("username", "go").Execute() + tester.ResponseEqSimple(t, 200, gin.H{ + "message": "OK", + "data": []types.Model{{Name: "ds"}}, + "total": 100, + }) +} + +func TestUserHandler_Codes(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.Codes + }) + + tester.mocks.user.EXPECT().Codes(tester.ctx, &types.UserDatasetsReq{ + Owner: "go", + CurrentUser: "u", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.Code{{Name: "ds"}}, 100, nil) + tester.AddPagination(1, 10).WithUser().WithParam("username", "go").Execute() + tester.ResponseEqSimple(t, 200, gin.H{ + "message": "OK", + "data": []types.Code{{Name: "ds"}}, + "total": 100, + }) +} + +func TestUserHandler_Spaces(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.Spaces + }) + + tester.mocks.user.EXPECT().Spaces(tester.ctx, &types.UserDatasetsReq{ + Owner: "go", + CurrentUser: "u", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.Space{{Name: "ds"}}, 100, nil) + tester.AddPagination(1, 10).WithUser().WithParam("username", "go").Execute() + tester.ResponseEqSimple(t, 200, gin.H{ + "message": "OK", + "data": []types.Space{{Name: "ds"}}, + "total": 100, + }) +} + +func TestUserHandler_LikesAdd(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.LikesAdd + }) + tester.RequireUser(t) + + tester.mocks.user.EXPECT().AddLikes(tester.ctx, &types.UserLikesRequest{ + Username: "go", + CurrentUser: "u", + RepoID: 123, + }).Return(nil) + tester.WithParam("username", "go").WithParam("repo_id", "123").Execute() + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestUserHandler_LikesCollections(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.LikesCollections + }) + tester.RequireUser(t) + + tester.mocks.user.EXPECT().LikesCollection(tester.ctx, &types.UserCollectionReq{ + Owner: "go", + CurrentUser: "u", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.Collection{{ID: 1}}, 100, nil) + tester.WithParam("username", "go").AddPagination(1, 10).Execute() + tester.ResponseEqSimple(t, 200, gin.H{ + "data": []types.Collection{{ID: 1}}, + "total": 100, + }) +} + +func TestUserHandler_UserCollections(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.UserCollections + }) + + tester.mocks.user.EXPECT().Collections(tester.ctx, &types.UserCollectionReq{ + Owner: "go", + CurrentUser: "u", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.Collection{{ID: 1}}, 100, nil) + tester.WithParam("username", "go").WithUser().AddPagination(1, 10).Execute() + tester.ResponseEqSimple(t, 200, gin.H{ + "data": []types.Collection{{ID: 1}}, + "total": 100, + }) +} + +func TestUserHandler_LikeCollection(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.LikeCollection + }) + tester.RequireUser(t) + + tester.mocks.user.EXPECT().LikeCollection(tester.ctx, &types.UserLikesRequest{ + CurrentUser: "u", + CollectionID: 123, + }).Return(nil) + tester.WithParam("id", "123").Execute() + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestUserHandler_UnLikeCollection(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.UnLikeCollection + }) + tester.RequireUser(t) + + tester.mocks.user.EXPECT().UnLikeCollection(tester.ctx, &types.UserLikesRequest{ + CurrentUser: "u", + CollectionID: 123, + }).Return(nil) + tester.WithParam("id", "123").Execute() + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestUserHandler_LikesDelete(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.LikesDelete + }) + tester.RequireUser(t) + + tester.mocks.user.EXPECT().DeleteLikes(tester.ctx, &types.UserLikesRequest{ + CurrentUser: "u", + RepoID: 123, + }).Return(nil) + tester.WithParam("repo_id", "123").Execute() + tester.ResponseEq(t, 200, tester.OKText, nil) +} + +func TestUserHandler_LikesSpaces(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.LikesSpaces + }) + tester.RequireUser(t) + + tester.mocks.user.EXPECT().LikesSpaces(tester.ctx, &types.UserSpacesReq{ + Owner: "foo", + CurrentUser: "u", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.Space{{Name: "sp"}}, 100, nil) + tester.WithParam("username", "foo").AddPagination(1, 10).Execute() + tester.ResponseEqSimple(t, 200, gin.H{ + "message": "OK", + "data": []types.Space{{Name: "sp"}}, + "total": 100, + }) +} + +func TestUserHandler_LikesCodes(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.LikesCodes + }) + tester.RequireUser(t) + + tester.mocks.user.EXPECT().LikesCodes(tester.ctx, &types.UserDatasetsReq{ + Owner: "foo", + CurrentUser: "u", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.Code{{Name: "sp"}}, 100, nil) + tester.WithParam("username", "foo").AddPagination(1, 10).Execute() + tester.ResponseEqSimple(t, 200, gin.H{ + "message": "OK", + "data": []types.Code{{Name: "sp"}}, + "total": 100, + }) +} + +func TestUserHandler_LikesModels(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.LikesModels + }) + tester.RequireUser(t) + + tester.mocks.user.EXPECT().LikesModels(tester.ctx, &types.UserDatasetsReq{ + Owner: "foo", + CurrentUser: "u", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.Model{{Name: "sp"}}, 100, nil) + tester.WithParam("username", "foo").AddPagination(1, 10).Execute() + tester.ResponseEqSimple(t, 200, gin.H{ + "message": "OK", + "data": []types.Model{{Name: "sp"}}, + "total": 100, + }) +} + +func TestUserHandler_LikesDatasets(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.LikesDatasets + }) + tester.RequireUser(t) + + tester.mocks.user.EXPECT().LikesDatasets(tester.ctx, &types.UserDatasetsReq{ + Owner: "foo", + CurrentUser: "u", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.Dataset{{Name: "sp"}}, 100, nil) + tester.WithParam("username", "foo").AddPagination(1, 10).Execute() + tester.ResponseEqSimple(t, 200, gin.H{ + "message": "OK", + "data": []types.Dataset{{Name: "sp"}}, + "total": 100, + }) +} + +func TestUserHandler_UserPermission(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.UserPermission + }) + tester.RequireUser(t) + + tester.Execute() + tester.ResponseEqSimple(t, 200, types.WhoamiResponse{ + Name: "u", + Auth: types.Auth{ + AccessToken: types.AccessToken{ + DisplayName: "u", + Role: "write", + }, + Type: "Bearer", + }, + }) +} + +func TestUserHandler_GetRunDeploys(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.GetRunDeploys + }) + tester.RequireUser(t) + + tester.mocks.user.EXPECT().ListDeploys(tester.ctx, types.ModelRepo, &types.DeployReq{ + CurrentUser: "u", + RepoType: types.ModelRepo, + DeployType: 1, + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.DeployRepo{{DeployID: 1}}, 100, nil) + tester.WithParam("username", "u").WithQuery("deploy_type", "").AddPagination(1, 10) + tester.WithParam("repo_type", "model").Execute() + + tester.ResponseEqSimple(t, 200, gin.H{ + "message": "OK", + "data": []types.DeployRepo{{DeployID: 1}}, + "total": 100, + }) +} + +func TestUserHandler_GetFinetuneInstances(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.GetFinetuneInstances + }) + + tester.mocks.user.EXPECT().ListInstances(tester.ctx, &types.UserRepoReq{ + CurrentUser: "u", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.DeployRepo{{DeployID: 1}}, 100, nil) + tester.WithUser().WithParam("username", "u").WithQuery("deploy_type", "").AddPagination(1, 10) + tester.Execute() + + tester.ResponseEqSimple(t, 200, gin.H{ + "message": "OK", + "data": []types.DeployRepo{{DeployID: 1}}, + "total": 100, + }) +} + +func TestUserHandler_GetRunServerless(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.GetRunServerless + }) + tester.RequireUser(t) + + tester.mocks.user.EXPECT().ListServerless(tester.ctx, types.DeployReq{ + CurrentUser: "u", + RepoType: types.ModelRepo, + DeployType: 3, + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.DeployRepo{{DeployID: 1}}, 100, nil) + tester.WithParam("username", "u").WithQuery("deploy_type", "").AddPagination(1, 10) + tester.WithParam("repo_type", "model").Execute() + + tester.ResponseEqSimple(t, 200, gin.H{ + "message": "OK", + "data": []types.DeployRepo{{DeployID: 1}}, + "total": 100, + }) +} + +func TestUserHandler_Prompts(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.Prompts + }) + + tester.mocks.user.EXPECT().Prompts(tester.ctx, &types.UserPromptsReq{ + CurrentUser: "u", + Owner: "u", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.PromptRes{{ID: 123}}, 100, nil) + tester.WithUser().WithParam("username", "u").AddPagination(1, 10).Execute() + + tester.ResponseEqSimple(t, 200, gin.H{ + "message": "OK", + "data": []types.PromptRes{{ID: 123}}, + "total": 100, + }) +} + +func TestUserHandler_GetEvaluations(t *testing.T) { + tester := NewUserTester(t).WithHandleFunc(func(h *UserHandler) gin.HandlerFunc { + return h.GetEvaluations + }) + tester.RequireUser(t) + + tester.mocks.user.EXPECT().Evaluations(tester.ctx, &types.UserEvaluationReq{ + CurrentUser: "u", + Owner: "u", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }).Return([]types.ArgoWorkFlowRes{{ID: 123}}, 100, nil) + tester.WithParam("username", "u").AddPagination(1, 10).Execute() + + tester.ResponseEqSimple(t, 200, gin.H{ + "data": []types.ArgoWorkFlowRes{{ID: 123}}, + "total": 100, + }) +} diff --git a/common/types/user.go b/common/types/user.go index 18d4ab65..4459713f 100644 --- a/common/types/user.go +++ b/common/types/user.go @@ -166,10 +166,10 @@ type User struct { } type UserLikesRequest struct { - Username string `json:"username"` - Repo_id int64 `json:"repo_id"` - Collection_id int64 `json:"collection_id"` - CurrentUser string `json:"current_user"` + Username string `json:"username"` + RepoID int64 `json:"repo_id"` + CollectionID int64 `json:"collection_id"` + CurrentUser string `json:"current_user"` } /* for HF compatible apis */ diff --git a/component/user.go b/component/user.go index 86cc31e9..85426990 100644 --- a/component/user.go +++ b/component/user.go @@ -296,7 +296,7 @@ func (c *userComponentImpl) AddLikes(ctx context.Context, req *types.UserLikesRe return newError } var likesRepoIDs []int64 - likesRepoIDs = append(likesRepoIDs, req.Repo_id) + likesRepoIDs = append(likesRepoIDs, req.RepoID) var opts []database.SelectOption opts = append(opts, database.Columns("id", "repository_type", "path", "user_id", "private")) @@ -314,7 +314,7 @@ func (c *userComponentImpl) AddLikes(ctx context.Context, req *types.UserLikesRe return fmt.Errorf("do not found likes repositories visiable to user:%s, %w", req.CurrentUser, err) } - err = c.userLikeStore.Add(ctx, user.ID, req.Repo_id) + err = c.userLikeStore.Add(ctx, user.ID, req.RepoID) return err } @@ -391,7 +391,7 @@ func (c *userComponentImpl) LikeCollection(ctx context.Context, req *types.UserL return newError } - collection, err := c.collectionStore.FindById(ctx, req.Collection_id) + collection, err := c.collectionStore.FindById(ctx, req.CollectionID) if err != nil { return fmt.Errorf("failed to get likes collection by id, error: %w", err) } @@ -400,7 +400,7 @@ func (c *userComponentImpl) LikeCollection(ctx context.Context, req *types.UserL return fmt.Errorf("no permission to like this collection for user:%s", req.CurrentUser) } - err = c.userLikeStore.LikeCollection(ctx, user.ID, req.Collection_id) + err = c.userLikeStore.LikeCollection(ctx, user.ID, req.CollectionID) return err } @@ -410,7 +410,7 @@ func (c *userComponentImpl) UnLikeCollection(ctx context.Context, req *types.Use newError := fmt.Errorf("failed to check for the presence of the user,error:%w", err) return newError } - err = c.userLikeStore.UnLikeCollection(ctx, user.ID, req.Collection_id) + err = c.userLikeStore.UnLikeCollection(ctx, user.ID, req.CollectionID) return err } @@ -420,7 +420,7 @@ func (c *userComponentImpl) DeleteLikes(ctx context.Context, req *types.UserLike newError := fmt.Errorf("failed to check for the presence of the user,error:%w", err) return newError } - err = c.userLikeStore.Delete(ctx, user.ID, req.Repo_id) + err = c.userLikeStore.Delete(ctx, user.ID, req.RepoID) return err } diff --git a/component/user_test.go b/component/user_test.go index efc2b3fb..0052ab62 100644 --- a/component/user_test.go +++ b/component/user_test.go @@ -136,10 +136,10 @@ func TestUserComponent_AddLikes(t *testing.T) { uc.mocks.stores.UserLikesMock().EXPECT().Add(ctx, int64(1), int64(123)).Return(nil) err := uc.AddLikes(ctx, &types.UserLikesRequest{ - Username: "user", - Repo_id: 123, - Collection_id: 456, - CurrentUser: "user", + Username: "user", + RepoID: 123, + CollectionID: 456, + CurrentUser: "user", }) require.Nil(t, err) } @@ -201,10 +201,10 @@ func TestUserComponent_LikeCollection(t *testing.T) { }, nil) uc.mocks.stores.UserLikesMock().EXPECT().LikeCollection(ctx, int64(1), int64(456)).Return(nil) err := uc.LikeCollection(ctx, &types.UserLikesRequest{ - Username: "user", - Repo_id: 123, - Collection_id: 456, - CurrentUser: "user", + Username: "user", + RepoID: 123, + CollectionID: 456, + CurrentUser: "user", }) require.Nil(t, err) } @@ -216,10 +216,10 @@ func TestUserComponent_UnLikeCollection(t *testing.T) { uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) uc.mocks.stores.UserLikesMock().EXPECT().UnLikeCollection(ctx, int64(1), int64(456)).Return(nil) err := uc.UnLikeCollection(ctx, &types.UserLikesRequest{ - Username: "user", - Repo_id: 123, - Collection_id: 456, - CurrentUser: "user", + Username: "user", + RepoID: 123, + CollectionID: 456, + CurrentUser: "user", }) require.Nil(t, err) } @@ -231,10 +231,10 @@ func TestUserComponent_DeleteLikes(t *testing.T) { uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) uc.mocks.stores.UserLikesMock().EXPECT().Delete(ctx, int64(1), int64(123)).Return(nil) err := uc.DeleteLikes(ctx, &types.UserLikesRequest{ - Username: "user", - Repo_id: 123, - Collection_id: 456, - CurrentUser: "user", + Username: "user", + RepoID: 123, + CollectionID: 456, + CurrentUser: "user", }) require.Nil(t, err) }