|
@@ -5,6 +5,8 @@ package db
|
|
|
import (
|
|
|
"context"
|
|
|
"sync"
|
|
|
+
|
|
|
+ lfsutil "gogs.io/gogs/internal/lfsutil"
|
|
|
)
|
|
|
|
|
|
|
|
@@ -658,6 +660,423 @@ func (c AccessTokensStoreTouchFuncCall) Results() []interface{} {
|
|
|
return []interface{}{c.Result0}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+type MockLFSStore struct {
|
|
|
+
|
|
|
+
|
|
|
+ CreateObjectFunc *LFSStoreCreateObjectFunc
|
|
|
+
|
|
|
+
|
|
|
+ GetObjectByOIDFunc *LFSStoreGetObjectByOIDFunc
|
|
|
+
|
|
|
+
|
|
|
+ GetObjectsByOIDsFunc *LFSStoreGetObjectsByOIDsFunc
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func NewMockLFSStore() *MockLFSStore {
|
|
|
+ return &MockLFSStore{
|
|
|
+ CreateObjectFunc: &LFSStoreCreateObjectFunc{
|
|
|
+ defaultHook: func(context.Context, int64, lfsutil.OID, int64, lfsutil.Storage) (r0 error) {
|
|
|
+ return
|
|
|
+ },
|
|
|
+ },
|
|
|
+ GetObjectByOIDFunc: &LFSStoreGetObjectByOIDFunc{
|
|
|
+ defaultHook: func(context.Context, int64, lfsutil.OID) (r0 *LFSObject, r1 error) {
|
|
|
+ return
|
|
|
+ },
|
|
|
+ },
|
|
|
+ GetObjectsByOIDsFunc: &LFSStoreGetObjectsByOIDsFunc{
|
|
|
+ defaultHook: func(context.Context, int64, ...lfsutil.OID) (r0 []*LFSObject, r1 error) {
|
|
|
+ return
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func NewStrictMockLFSStore() *MockLFSStore {
|
|
|
+ return &MockLFSStore{
|
|
|
+ CreateObjectFunc: &LFSStoreCreateObjectFunc{
|
|
|
+ defaultHook: func(context.Context, int64, lfsutil.OID, int64, lfsutil.Storage) error {
|
|
|
+ panic("unexpected invocation of MockLFSStore.CreateObject")
|
|
|
+ },
|
|
|
+ },
|
|
|
+ GetObjectByOIDFunc: &LFSStoreGetObjectByOIDFunc{
|
|
|
+ defaultHook: func(context.Context, int64, lfsutil.OID) (*LFSObject, error) {
|
|
|
+ panic("unexpected invocation of MockLFSStore.GetObjectByOID")
|
|
|
+ },
|
|
|
+ },
|
|
|
+ GetObjectsByOIDsFunc: &LFSStoreGetObjectsByOIDsFunc{
|
|
|
+ defaultHook: func(context.Context, int64, ...lfsutil.OID) ([]*LFSObject, error) {
|
|
|
+ panic("unexpected invocation of MockLFSStore.GetObjectsByOIDs")
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func NewMockLFSStoreFrom(i LFSStore) *MockLFSStore {
|
|
|
+ return &MockLFSStore{
|
|
|
+ CreateObjectFunc: &LFSStoreCreateObjectFunc{
|
|
|
+ defaultHook: i.CreateObject,
|
|
|
+ },
|
|
|
+ GetObjectByOIDFunc: &LFSStoreGetObjectByOIDFunc{
|
|
|
+ defaultHook: i.GetObjectByOID,
|
|
|
+ },
|
|
|
+ GetObjectsByOIDsFunc: &LFSStoreGetObjectsByOIDsFunc{
|
|
|
+ defaultHook: i.GetObjectsByOIDs,
|
|
|
+ },
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+type LFSStoreCreateObjectFunc struct {
|
|
|
+ defaultHook func(context.Context, int64, lfsutil.OID, int64, lfsutil.Storage) error
|
|
|
+ hooks []func(context.Context, int64, lfsutil.OID, int64, lfsutil.Storage) error
|
|
|
+ history []LFSStoreCreateObjectFuncCall
|
|
|
+ mutex sync.Mutex
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (m *MockLFSStore) CreateObject(v0 context.Context, v1 int64, v2 lfsutil.OID, v3 int64, v4 lfsutil.Storage) error {
|
|
|
+ r0 := m.CreateObjectFunc.nextHook()(v0, v1, v2, v3, v4)
|
|
|
+ m.CreateObjectFunc.appendCall(LFSStoreCreateObjectFuncCall{v0, v1, v2, v3, v4, r0})
|
|
|
+ return r0
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreCreateObjectFunc) SetDefaultHook(hook func(context.Context, int64, lfsutil.OID, int64, lfsutil.Storage) error) {
|
|
|
+ f.defaultHook = hook
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreCreateObjectFunc) PushHook(hook func(context.Context, int64, lfsutil.OID, int64, lfsutil.Storage) error) {
|
|
|
+ f.mutex.Lock()
|
|
|
+ f.hooks = append(f.hooks, hook)
|
|
|
+ f.mutex.Unlock()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreCreateObjectFunc) SetDefaultReturn(r0 error) {
|
|
|
+ f.SetDefaultHook(func(context.Context, int64, lfsutil.OID, int64, lfsutil.Storage) error {
|
|
|
+ return r0
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreCreateObjectFunc) PushReturn(r0 error) {
|
|
|
+ f.PushHook(func(context.Context, int64, lfsutil.OID, int64, lfsutil.Storage) error {
|
|
|
+ return r0
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+func (f *LFSStoreCreateObjectFunc) nextHook() func(context.Context, int64, lfsutil.OID, int64, lfsutil.Storage) error {
|
|
|
+ f.mutex.Lock()
|
|
|
+ defer f.mutex.Unlock()
|
|
|
+
|
|
|
+ if len(f.hooks) == 0 {
|
|
|
+ return f.defaultHook
|
|
|
+ }
|
|
|
+
|
|
|
+ hook := f.hooks[0]
|
|
|
+ f.hooks = f.hooks[1:]
|
|
|
+ return hook
|
|
|
+}
|
|
|
+
|
|
|
+func (f *LFSStoreCreateObjectFunc) appendCall(r0 LFSStoreCreateObjectFuncCall) {
|
|
|
+ f.mutex.Lock()
|
|
|
+ f.history = append(f.history, r0)
|
|
|
+ f.mutex.Unlock()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreCreateObjectFunc) History() []LFSStoreCreateObjectFuncCall {
|
|
|
+ f.mutex.Lock()
|
|
|
+ history := make([]LFSStoreCreateObjectFuncCall, len(f.history))
|
|
|
+ copy(history, f.history)
|
|
|
+ f.mutex.Unlock()
|
|
|
+
|
|
|
+ return history
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+type LFSStoreCreateObjectFuncCall struct {
|
|
|
+
|
|
|
+
|
|
|
+ Arg0 context.Context
|
|
|
+
|
|
|
+
|
|
|
+ Arg1 int64
|
|
|
+
|
|
|
+
|
|
|
+ Arg2 lfsutil.OID
|
|
|
+
|
|
|
+
|
|
|
+ Arg3 int64
|
|
|
+
|
|
|
+
|
|
|
+ Arg4 lfsutil.Storage
|
|
|
+
|
|
|
+
|
|
|
+ Result0 error
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (c LFSStoreCreateObjectFuncCall) Args() []interface{} {
|
|
|
+ return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3, c.Arg4}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (c LFSStoreCreateObjectFuncCall) Results() []interface{} {
|
|
|
+ return []interface{}{c.Result0}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+type LFSStoreGetObjectByOIDFunc struct {
|
|
|
+ defaultHook func(context.Context, int64, lfsutil.OID) (*LFSObject, error)
|
|
|
+ hooks []func(context.Context, int64, lfsutil.OID) (*LFSObject, error)
|
|
|
+ history []LFSStoreGetObjectByOIDFuncCall
|
|
|
+ mutex sync.Mutex
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (m *MockLFSStore) GetObjectByOID(v0 context.Context, v1 int64, v2 lfsutil.OID) (*LFSObject, error) {
|
|
|
+ r0, r1 := m.GetObjectByOIDFunc.nextHook()(v0, v1, v2)
|
|
|
+ m.GetObjectByOIDFunc.appendCall(LFSStoreGetObjectByOIDFuncCall{v0, v1, v2, r0, r1})
|
|
|
+ return r0, r1
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectByOIDFunc) SetDefaultHook(hook func(context.Context, int64, lfsutil.OID) (*LFSObject, error)) {
|
|
|
+ f.defaultHook = hook
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectByOIDFunc) PushHook(hook func(context.Context, int64, lfsutil.OID) (*LFSObject, error)) {
|
|
|
+ f.mutex.Lock()
|
|
|
+ f.hooks = append(f.hooks, hook)
|
|
|
+ f.mutex.Unlock()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectByOIDFunc) SetDefaultReturn(r0 *LFSObject, r1 error) {
|
|
|
+ f.SetDefaultHook(func(context.Context, int64, lfsutil.OID) (*LFSObject, error) {
|
|
|
+ return r0, r1
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectByOIDFunc) PushReturn(r0 *LFSObject, r1 error) {
|
|
|
+ f.PushHook(func(context.Context, int64, lfsutil.OID) (*LFSObject, error) {
|
|
|
+ return r0, r1
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectByOIDFunc) nextHook() func(context.Context, int64, lfsutil.OID) (*LFSObject, error) {
|
|
|
+ f.mutex.Lock()
|
|
|
+ defer f.mutex.Unlock()
|
|
|
+
|
|
|
+ if len(f.hooks) == 0 {
|
|
|
+ return f.defaultHook
|
|
|
+ }
|
|
|
+
|
|
|
+ hook := f.hooks[0]
|
|
|
+ f.hooks = f.hooks[1:]
|
|
|
+ return hook
|
|
|
+}
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectByOIDFunc) appendCall(r0 LFSStoreGetObjectByOIDFuncCall) {
|
|
|
+ f.mutex.Lock()
|
|
|
+ f.history = append(f.history, r0)
|
|
|
+ f.mutex.Unlock()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectByOIDFunc) History() []LFSStoreGetObjectByOIDFuncCall {
|
|
|
+ f.mutex.Lock()
|
|
|
+ history := make([]LFSStoreGetObjectByOIDFuncCall, len(f.history))
|
|
|
+ copy(history, f.history)
|
|
|
+ f.mutex.Unlock()
|
|
|
+
|
|
|
+ return history
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+type LFSStoreGetObjectByOIDFuncCall struct {
|
|
|
+
|
|
|
+
|
|
|
+ Arg0 context.Context
|
|
|
+
|
|
|
+
|
|
|
+ Arg1 int64
|
|
|
+
|
|
|
+
|
|
|
+ Arg2 lfsutil.OID
|
|
|
+
|
|
|
+
|
|
|
+ Result0 *LFSObject
|
|
|
+
|
|
|
+
|
|
|
+ Result1 error
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (c LFSStoreGetObjectByOIDFuncCall) Args() []interface{} {
|
|
|
+ return []interface{}{c.Arg0, c.Arg1, c.Arg2}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (c LFSStoreGetObjectByOIDFuncCall) Results() []interface{} {
|
|
|
+ return []interface{}{c.Result0, c.Result1}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+type LFSStoreGetObjectsByOIDsFunc struct {
|
|
|
+ defaultHook func(context.Context, int64, ...lfsutil.OID) ([]*LFSObject, error)
|
|
|
+ hooks []func(context.Context, int64, ...lfsutil.OID) ([]*LFSObject, error)
|
|
|
+ history []LFSStoreGetObjectsByOIDsFuncCall
|
|
|
+ mutex sync.Mutex
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (m *MockLFSStore) GetObjectsByOIDs(v0 context.Context, v1 int64, v2 ...lfsutil.OID) ([]*LFSObject, error) {
|
|
|
+ r0, r1 := m.GetObjectsByOIDsFunc.nextHook()(v0, v1, v2...)
|
|
|
+ m.GetObjectsByOIDsFunc.appendCall(LFSStoreGetObjectsByOIDsFuncCall{v0, v1, v2, r0, r1})
|
|
|
+ return r0, r1
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectsByOIDsFunc) SetDefaultHook(hook func(context.Context, int64, ...lfsutil.OID) ([]*LFSObject, error)) {
|
|
|
+ f.defaultHook = hook
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectsByOIDsFunc) PushHook(hook func(context.Context, int64, ...lfsutil.OID) ([]*LFSObject, error)) {
|
|
|
+ f.mutex.Lock()
|
|
|
+ f.hooks = append(f.hooks, hook)
|
|
|
+ f.mutex.Unlock()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectsByOIDsFunc) SetDefaultReturn(r0 []*LFSObject, r1 error) {
|
|
|
+ f.SetDefaultHook(func(context.Context, int64, ...lfsutil.OID) ([]*LFSObject, error) {
|
|
|
+ return r0, r1
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectsByOIDsFunc) PushReturn(r0 []*LFSObject, r1 error) {
|
|
|
+ f.PushHook(func(context.Context, int64, ...lfsutil.OID) ([]*LFSObject, error) {
|
|
|
+ return r0, r1
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectsByOIDsFunc) nextHook() func(context.Context, int64, ...lfsutil.OID) ([]*LFSObject, error) {
|
|
|
+ f.mutex.Lock()
|
|
|
+ defer f.mutex.Unlock()
|
|
|
+
|
|
|
+ if len(f.hooks) == 0 {
|
|
|
+ return f.defaultHook
|
|
|
+ }
|
|
|
+
|
|
|
+ hook := f.hooks[0]
|
|
|
+ f.hooks = f.hooks[1:]
|
|
|
+ return hook
|
|
|
+}
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectsByOIDsFunc) appendCall(r0 LFSStoreGetObjectsByOIDsFuncCall) {
|
|
|
+ f.mutex.Lock()
|
|
|
+ f.history = append(f.history, r0)
|
|
|
+ f.mutex.Unlock()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (f *LFSStoreGetObjectsByOIDsFunc) History() []LFSStoreGetObjectsByOIDsFuncCall {
|
|
|
+ f.mutex.Lock()
|
|
|
+ history := make([]LFSStoreGetObjectsByOIDsFuncCall, len(f.history))
|
|
|
+ copy(history, f.history)
|
|
|
+ f.mutex.Unlock()
|
|
|
+
|
|
|
+ return history
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+type LFSStoreGetObjectsByOIDsFuncCall struct {
|
|
|
+
|
|
|
+
|
|
|
+ Arg0 context.Context
|
|
|
+
|
|
|
+
|
|
|
+ Arg1 int64
|
|
|
+
|
|
|
+
|
|
|
+ Arg2 []lfsutil.OID
|
|
|
+
|
|
|
+
|
|
|
+ Result0 []*LFSObject
|
|
|
+
|
|
|
+
|
|
|
+ Result1 error
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (c LFSStoreGetObjectsByOIDsFuncCall) Args() []interface{} {
|
|
|
+ trailing := []interface{}{}
|
|
|
+ for _, val := range c.Arg2 {
|
|
|
+ trailing = append(trailing, val)
|
|
|
+ }
|
|
|
+
|
|
|
+ return append([]interface{}{c.Arg0, c.Arg1}, trailing...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (c LFSStoreGetObjectsByOIDsFuncCall) Results() []interface{} {
|
|
|
+ return []interface{}{c.Result0, c.Result1}
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
type MockPermsStore struct {
|