aboutsummaryrefslogtreecommitdiff
path: root/internal/db/mocks.go
diff options
context:
space:
mode:
authorJoe Chen <jc@unknwon.io>2022-06-11 11:54:11 +0800
committerGitHub <noreply@github.com>2022-06-11 11:54:11 +0800
commit5e32058c13f34b46c69b7cdee6ccc0b7fe3b6df3 (patch)
tree92353ba2d8b6461754b89e95f581f4d402cf42af /internal/db/mocks.go
parent75fbb8244086a2ad964d1c51e3bdbdfb95df90ac (diff)
db: use `context` and go-mockgen for `TwoFactorsStore` (#7045)
Diffstat (limited to 'internal/db/mocks.go')
-rw-r--r--internal/db/mocks.go402
1 files changed, 402 insertions, 0 deletions
diff --git a/internal/db/mocks.go b/internal/db/mocks.go
index e6a39963..d3e302a8 100644
--- a/internal/db/mocks.go
+++ b/internal/db/mocks.go
@@ -2371,6 +2371,408 @@ func (c PermsStoreSetRepoPermsFuncCall) Results() []interface{} {
return []interface{}{c.Result0}
}
+// MockTwoFactorsStore is a mock implementation of the TwoFactorsStore
+// interface (from the package gogs.io/gogs/internal/db) used for unit
+// testing.
+type MockTwoFactorsStore struct {
+ // CreateFunc is an instance of a mock function object controlling the
+ // behavior of the method Create.
+ CreateFunc *TwoFactorsStoreCreateFunc
+ // GetByUserIDFunc is an instance of a mock function object controlling
+ // the behavior of the method GetByUserID.
+ GetByUserIDFunc *TwoFactorsStoreGetByUserIDFunc
+ // IsUserEnabledFunc is an instance of a mock function object
+ // controlling the behavior of the method IsUserEnabled.
+ IsUserEnabledFunc *TwoFactorsStoreIsUserEnabledFunc
+}
+
+// NewMockTwoFactorsStore creates a new mock of the TwoFactorsStore
+// interface. All methods return zero values for all results, unless
+// overwritten.
+func NewMockTwoFactorsStore() *MockTwoFactorsStore {
+ return &MockTwoFactorsStore{
+ CreateFunc: &TwoFactorsStoreCreateFunc{
+ defaultHook: func(context.Context, int64, string, string) (r0 error) {
+ return
+ },
+ },
+ GetByUserIDFunc: &TwoFactorsStoreGetByUserIDFunc{
+ defaultHook: func(context.Context, int64) (r0 *TwoFactor, r1 error) {
+ return
+ },
+ },
+ IsUserEnabledFunc: &TwoFactorsStoreIsUserEnabledFunc{
+ defaultHook: func(context.Context, int64) (r0 bool) {
+ return
+ },
+ },
+ }
+}
+
+// NewStrictMockTwoFactorsStore creates a new mock of the TwoFactorsStore
+// interface. All methods panic on invocation, unless overwritten.
+func NewStrictMockTwoFactorsStore() *MockTwoFactorsStore {
+ return &MockTwoFactorsStore{
+ CreateFunc: &TwoFactorsStoreCreateFunc{
+ defaultHook: func(context.Context, int64, string, string) error {
+ panic("unexpected invocation of MockTwoFactorsStore.Create")
+ },
+ },
+ GetByUserIDFunc: &TwoFactorsStoreGetByUserIDFunc{
+ defaultHook: func(context.Context, int64) (*TwoFactor, error) {
+ panic("unexpected invocation of MockTwoFactorsStore.GetByUserID")
+ },
+ },
+ IsUserEnabledFunc: &TwoFactorsStoreIsUserEnabledFunc{
+ defaultHook: func(context.Context, int64) bool {
+ panic("unexpected invocation of MockTwoFactorsStore.IsUserEnabled")
+ },
+ },
+ }
+}
+
+// NewMockTwoFactorsStoreFrom creates a new mock of the MockTwoFactorsStore
+// interface. All methods delegate to the given implementation, unless
+// overwritten.
+func NewMockTwoFactorsStoreFrom(i TwoFactorsStore) *MockTwoFactorsStore {
+ return &MockTwoFactorsStore{
+ CreateFunc: &TwoFactorsStoreCreateFunc{
+ defaultHook: i.Create,
+ },
+ GetByUserIDFunc: &TwoFactorsStoreGetByUserIDFunc{
+ defaultHook: i.GetByUserID,
+ },
+ IsUserEnabledFunc: &TwoFactorsStoreIsUserEnabledFunc{
+ defaultHook: i.IsUserEnabled,
+ },
+ }
+}
+
+// TwoFactorsStoreCreateFunc describes the behavior when the Create method
+// of the parent MockTwoFactorsStore instance is invoked.
+type TwoFactorsStoreCreateFunc struct {
+ defaultHook func(context.Context, int64, string, string) error
+ hooks []func(context.Context, int64, string, string) error
+ history []TwoFactorsStoreCreateFuncCall
+ mutex sync.Mutex
+}
+
+// Create delegates to the next hook function in the queue and stores the
+// parameter and result values of this invocation.
+func (m *MockTwoFactorsStore) Create(v0 context.Context, v1 int64, v2 string, v3 string) error {
+ r0 := m.CreateFunc.nextHook()(v0, v1, v2, v3)
+ m.CreateFunc.appendCall(TwoFactorsStoreCreateFuncCall{v0, v1, v2, v3, r0})
+ return r0
+}
+
+// SetDefaultHook sets function that is called when the Create method of the
+// parent MockTwoFactorsStore instance is invoked and the hook queue is
+// empty.
+func (f *TwoFactorsStoreCreateFunc) SetDefaultHook(hook func(context.Context, int64, string, string) error) {
+ f.defaultHook = hook
+}
+
+// PushHook adds a function to the end of hook queue. Each invocation of the
+// Create method of the parent MockTwoFactorsStore instance invokes the hook
+// at the front of the queue and discards it. After the queue is empty, the
+// default hook function is invoked for any future action.
+func (f *TwoFactorsStoreCreateFunc) PushHook(hook func(context.Context, int64, string, string) error) {
+ f.mutex.Lock()
+ f.hooks = append(f.hooks, hook)
+ f.mutex.Unlock()
+}
+
+// SetDefaultReturn calls SetDefaultHook with a function that returns the
+// given values.
+func (f *TwoFactorsStoreCreateFunc) SetDefaultReturn(r0 error) {
+ f.SetDefaultHook(func(context.Context, int64, string, string) error {
+ return r0
+ })
+}
+
+// PushReturn calls PushHook with a function that returns the given values.
+func (f *TwoFactorsStoreCreateFunc) PushReturn(r0 error) {
+ f.PushHook(func(context.Context, int64, string, string) error {
+ return r0
+ })
+}
+
+func (f *TwoFactorsStoreCreateFunc) nextHook() func(context.Context, int64, string, string) 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 *TwoFactorsStoreCreateFunc) appendCall(r0 TwoFactorsStoreCreateFuncCall) {
+ f.mutex.Lock()
+ f.history = append(f.history, r0)
+ f.mutex.Unlock()
+}
+
+// History returns a sequence of TwoFactorsStoreCreateFuncCall objects
+// describing the invocations of this function.
+func (f *TwoFactorsStoreCreateFunc) History() []TwoFactorsStoreCreateFuncCall {
+ f.mutex.Lock()
+ history := make([]TwoFactorsStoreCreateFuncCall, len(f.history))
+ copy(history, f.history)
+ f.mutex.Unlock()
+
+ return history
+}
+
+// TwoFactorsStoreCreateFuncCall is an object that describes an invocation
+// of method Create on an instance of MockTwoFactorsStore.
+type TwoFactorsStoreCreateFuncCall struct {
+ // Arg0 is the value of the 1st argument passed to this method
+ // invocation.
+ Arg0 context.Context
+ // Arg1 is the value of the 2nd argument passed to this method
+ // invocation.
+ Arg1 int64
+ // Arg2 is the value of the 3rd argument passed to this method
+ // invocation.
+ Arg2 string
+ // Arg3 is the value of the 4th argument passed to this method
+ // invocation.
+ Arg3 string
+ // Result0 is the value of the 1st result returned from this method
+ // invocation.
+ Result0 error
+}
+
+// Args returns an interface slice containing the arguments of this
+// invocation.
+func (c TwoFactorsStoreCreateFuncCall) Args() []interface{} {
+ return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3}
+}
+
+// Results returns an interface slice containing the results of this
+// invocation.
+func (c TwoFactorsStoreCreateFuncCall) Results() []interface{} {
+ return []interface{}{c.Result0}
+}
+
+// TwoFactorsStoreGetByUserIDFunc describes the behavior when the
+// GetByUserID method of the parent MockTwoFactorsStore instance is invoked.
+type TwoFactorsStoreGetByUserIDFunc struct {
+ defaultHook func(context.Context, int64) (*TwoFactor, error)
+ hooks []func(context.Context, int64) (*TwoFactor, error)
+ history []TwoFactorsStoreGetByUserIDFuncCall
+ mutex sync.Mutex
+}
+
+// GetByUserID delegates to the next hook function in the queue and stores
+// the parameter and result values of this invocation.
+func (m *MockTwoFactorsStore) GetByUserID(v0 context.Context, v1 int64) (*TwoFactor, error) {
+ r0, r1 := m.GetByUserIDFunc.nextHook()(v0, v1)
+ m.GetByUserIDFunc.appendCall(TwoFactorsStoreGetByUserIDFuncCall{v0, v1, r0, r1})
+ return r0, r1
+}
+
+// SetDefaultHook sets function that is called when the GetByUserID method
+// of the parent MockTwoFactorsStore instance is invoked and the hook queue
+// is empty.
+func (f *TwoFactorsStoreGetByUserIDFunc) SetDefaultHook(hook func(context.Context, int64) (*TwoFactor, error)) {
+ f.defaultHook = hook
+}
+
+// PushHook adds a function to the end of hook queue. Each invocation of the
+// GetByUserID method of the parent MockTwoFactorsStore instance invokes the
+// hook at the front of the queue and discards it. After the queue is empty,
+// the default hook function is invoked for any future action.
+func (f *TwoFactorsStoreGetByUserIDFunc) PushHook(hook func(context.Context, int64) (*TwoFactor, error)) {
+ f.mutex.Lock()
+ f.hooks = append(f.hooks, hook)
+ f.mutex.Unlock()
+}
+
+// SetDefaultReturn calls SetDefaultHook with a function that returns the
+// given values.
+func (f *TwoFactorsStoreGetByUserIDFunc) SetDefaultReturn(r0 *TwoFactor, r1 error) {
+ f.SetDefaultHook(func(context.Context, int64) (*TwoFactor, error) {
+ return r0, r1
+ })
+}
+
+// PushReturn calls PushHook with a function that returns the given values.
+func (f *TwoFactorsStoreGetByUserIDFunc) PushReturn(r0 *TwoFactor, r1 error) {
+ f.PushHook(func(context.Context, int64) (*TwoFactor, error) {
+ return r0, r1
+ })
+}
+
+func (f *TwoFactorsStoreGetByUserIDFunc) nextHook() func(context.Context, int64) (*TwoFactor, 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 *TwoFactorsStoreGetByUserIDFunc) appendCall(r0 TwoFactorsStoreGetByUserIDFuncCall) {
+ f.mutex.Lock()
+ f.history = append(f.history, r0)
+ f.mutex.Unlock()
+}
+
+// History returns a sequence of TwoFactorsStoreGetByUserIDFuncCall objects
+// describing the invocations of this function.
+func (f *TwoFactorsStoreGetByUserIDFunc) History() []TwoFactorsStoreGetByUserIDFuncCall {
+ f.mutex.Lock()
+ history := make([]TwoFactorsStoreGetByUserIDFuncCall, len(f.history))
+ copy(history, f.history)
+ f.mutex.Unlock()
+
+ return history
+}
+
+// TwoFactorsStoreGetByUserIDFuncCall is an object that describes an
+// invocation of method GetByUserID on an instance of MockTwoFactorsStore.
+type TwoFactorsStoreGetByUserIDFuncCall struct {
+ // Arg0 is the value of the 1st argument passed to this method
+ // invocation.
+ Arg0 context.Context
+ // Arg1 is the value of the 2nd argument passed to this method
+ // invocation.
+ Arg1 int64
+ // Result0 is the value of the 1st result returned from this method
+ // invocation.
+ Result0 *TwoFactor
+ // Result1 is the value of the 2nd result returned from this method
+ // invocation.
+ Result1 error
+}
+
+// Args returns an interface slice containing the arguments of this
+// invocation.
+func (c TwoFactorsStoreGetByUserIDFuncCall) Args() []interface{} {
+ return []interface{}{c.Arg0, c.Arg1}
+}
+
+// Results returns an interface slice containing the results of this
+// invocation.
+func (c TwoFactorsStoreGetByUserIDFuncCall) Results() []interface{} {
+ return []interface{}{c.Result0, c.Result1}
+}
+
+// TwoFactorsStoreIsUserEnabledFunc describes the behavior when the
+// IsUserEnabled method of the parent MockTwoFactorsStore instance is
+// invoked.
+type TwoFactorsStoreIsUserEnabledFunc struct {
+ defaultHook func(context.Context, int64) bool
+ hooks []func(context.Context, int64) bool
+ history []TwoFactorsStoreIsUserEnabledFuncCall
+ mutex sync.Mutex
+}
+
+// IsUserEnabled delegates to the next hook function in the queue and stores
+// the parameter and result values of this invocation.
+func (m *MockTwoFactorsStore) IsUserEnabled(v0 context.Context, v1 int64) bool {
+ r0 := m.IsUserEnabledFunc.nextHook()(v0, v1)
+ m.IsUserEnabledFunc.appendCall(TwoFactorsStoreIsUserEnabledFuncCall{v0, v1, r0})
+ return r0
+}
+
+// SetDefaultHook sets function that is called when the IsUserEnabled method
+// of the parent MockTwoFactorsStore instance is invoked and the hook queue
+// is empty.
+func (f *TwoFactorsStoreIsUserEnabledFunc) SetDefaultHook(hook func(context.Context, int64) bool) {
+ f.defaultHook = hook
+}
+
+// PushHook adds a function to the end of hook queue. Each invocation of the
+// IsUserEnabled method of the parent MockTwoFactorsStore instance invokes
+// the hook at the front of the queue and discards it. After the queue is
+// empty, the default hook function is invoked for any future action.
+func (f *TwoFactorsStoreIsUserEnabledFunc) PushHook(hook func(context.Context, int64) bool) {
+ f.mutex.Lock()
+ f.hooks = append(f.hooks, hook)
+ f.mutex.Unlock()
+}
+
+// SetDefaultReturn calls SetDefaultHook with a function that returns the
+// given values.
+func (f *TwoFactorsStoreIsUserEnabledFunc) SetDefaultReturn(r0 bool) {
+ f.SetDefaultHook(func(context.Context, int64) bool {
+ return r0
+ })
+}
+
+// PushReturn calls PushHook with a function that returns the given values.
+func (f *TwoFactorsStoreIsUserEnabledFunc) PushReturn(r0 bool) {
+ f.PushHook(func(context.Context, int64) bool {
+ return r0
+ })
+}
+
+func (f *TwoFactorsStoreIsUserEnabledFunc) nextHook() func(context.Context, int64) bool {
+ 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 *TwoFactorsStoreIsUserEnabledFunc) appendCall(r0 TwoFactorsStoreIsUserEnabledFuncCall) {
+ f.mutex.Lock()
+ f.history = append(f.history, r0)
+ f.mutex.Unlock()
+}
+
+// History returns a sequence of TwoFactorsStoreIsUserEnabledFuncCall
+// objects describing the invocations of this function.
+func (f *TwoFactorsStoreIsUserEnabledFunc) History() []TwoFactorsStoreIsUserEnabledFuncCall {
+ f.mutex.Lock()
+ history := make([]TwoFactorsStoreIsUserEnabledFuncCall, len(f.history))
+ copy(history, f.history)
+ f.mutex.Unlock()
+
+ return history
+}
+
+// TwoFactorsStoreIsUserEnabledFuncCall is an object that describes an
+// invocation of method IsUserEnabled on an instance of MockTwoFactorsStore.
+type TwoFactorsStoreIsUserEnabledFuncCall struct {
+ // Arg0 is the value of the 1st argument passed to this method
+ // invocation.
+ Arg0 context.Context
+ // Arg1 is the value of the 2nd argument passed to this method
+ // invocation.
+ Arg1 int64
+ // Result0 is the value of the 1st result returned from this method
+ // invocation.
+ Result0 bool
+}
+
+// Args returns an interface slice containing the arguments of this
+// invocation.
+func (c TwoFactorsStoreIsUserEnabledFuncCall) Args() []interface{} {
+ return []interface{}{c.Arg0, c.Arg1}
+}
+
+// Results returns an interface slice containing the results of this
+// invocation.
+func (c TwoFactorsStoreIsUserEnabledFuncCall) Results() []interface{} {
+ return []interface{}{c.Result0}
+}
+
// MockUsersStore is a mock implementation of the UsersStore interface (from
// the package gogs.io/gogs/internal/db) used for unit testing.
type MockUsersStore struct {