aboutsummaryrefslogtreecommitdiff
path: root/internal/db/mocks.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/mocks.go')
-rw-r--r--internal/db/mocks.go709
1 files changed, 562 insertions, 147 deletions
diff --git a/internal/db/mocks.go b/internal/db/mocks.go
index 4addae93..95c30695 100644
--- a/internal/db/mocks.go
+++ b/internal/db/mocks.go
@@ -1,244 +1,659 @@
-// Copyright 2020 The Gogs Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
+// Code generated by go-mockgen 1.2.0; DO NOT EDIT.
package db
import (
- "testing"
-
- "gogs.io/gogs/internal/lfsutil"
+ "context"
+ "sync"
)
-// NOTE: Mocks are sorted in alphabetical order.
-
-var _ AccessTokensStore = (*MockAccessTokensStore)(nil)
-
+// MockAccessTokensStore is a mock implementation of the AccessTokensStore
+// interface (from the package gogs.io/gogs/internal/db) used for unit
+// testing.
type MockAccessTokensStore struct {
- MockCreate func(userID int64, name string) (*AccessToken, error)
- MockDeleteByID func(userID, id int64) error
- MockGetBySHA1 func(sha string) (*AccessToken, error)
- MockList func(userID int64) ([]*AccessToken, error)
- MockSave func(t *AccessToken) error
+ // CreateFunc is an instance of a mock function object controlling the
+ // behavior of the method Create.
+ CreateFunc *AccessTokensStoreCreateFunc
+ // DeleteByIDFunc is an instance of a mock function object controlling
+ // the behavior of the method DeleteByID.
+ DeleteByIDFunc *AccessTokensStoreDeleteByIDFunc
+ // GetBySHA1Func is an instance of a mock function object controlling
+ // the behavior of the method GetBySHA1.
+ GetBySHA1Func *AccessTokensStoreGetBySHA1Func
+ // ListFunc is an instance of a mock function object controlling the
+ // behavior of the method List.
+ ListFunc *AccessTokensStoreListFunc
+ // SaveFunc is an instance of a mock function object controlling the
+ // behavior of the method Save.
+ SaveFunc *AccessTokensStoreSaveFunc
+}
+
+// NewMockAccessTokensStore creates a new mock of the AccessTokensStore
+// interface. All methods return zero values for all results, unless
+// overwritten.
+func NewMockAccessTokensStore() *MockAccessTokensStore {
+ return &MockAccessTokensStore{
+ CreateFunc: &AccessTokensStoreCreateFunc{
+ defaultHook: func(context.Context, int64, string) (r0 *AccessToken, r1 error) {
+ return
+ },
+ },
+ DeleteByIDFunc: &AccessTokensStoreDeleteByIDFunc{
+ defaultHook: func(context.Context, int64, int64) (r0 error) {
+ return
+ },
+ },
+ GetBySHA1Func: &AccessTokensStoreGetBySHA1Func{
+ defaultHook: func(context.Context, string) (r0 *AccessToken, r1 error) {
+ return
+ },
+ },
+ ListFunc: &AccessTokensStoreListFunc{
+ defaultHook: func(context.Context, int64) (r0 []*AccessToken, r1 error) {
+ return
+ },
+ },
+ SaveFunc: &AccessTokensStoreSaveFunc{
+ defaultHook: func(context.Context, *AccessToken) (r0 error) {
+ return
+ },
+ },
+ }
+}
+
+// NewStrictMockAccessTokensStore creates a new mock of the
+// AccessTokensStore interface. All methods panic on invocation, unless
+// overwritten.
+func NewStrictMockAccessTokensStore() *MockAccessTokensStore {
+ return &MockAccessTokensStore{
+ CreateFunc: &AccessTokensStoreCreateFunc{
+ defaultHook: func(context.Context, int64, string) (*AccessToken, error) {
+ panic("unexpected invocation of MockAccessTokensStore.Create")
+ },
+ },
+ DeleteByIDFunc: &AccessTokensStoreDeleteByIDFunc{
+ defaultHook: func(context.Context, int64, int64) error {
+ panic("unexpected invocation of MockAccessTokensStore.DeleteByID")
+ },
+ },
+ GetBySHA1Func: &AccessTokensStoreGetBySHA1Func{
+ defaultHook: func(context.Context, string) (*AccessToken, error) {
+ panic("unexpected invocation of MockAccessTokensStore.GetBySHA1")
+ },
+ },
+ ListFunc: &AccessTokensStoreListFunc{
+ defaultHook: func(context.Context, int64) ([]*AccessToken, error) {
+ panic("unexpected invocation of MockAccessTokensStore.List")
+ },
+ },
+ SaveFunc: &AccessTokensStoreSaveFunc{
+ defaultHook: func(context.Context, *AccessToken) error {
+ panic("unexpected invocation of MockAccessTokensStore.Save")
+ },
+ },
+ }
+}
+
+// NewMockAccessTokensStoreFrom creates a new mock of the
+// MockAccessTokensStore interface. All methods delegate to the given
+// implementation, unless overwritten.
+func NewMockAccessTokensStoreFrom(i AccessTokensStore) *MockAccessTokensStore {
+ return &MockAccessTokensStore{
+ CreateFunc: &AccessTokensStoreCreateFunc{
+ defaultHook: i.Create,
+ },
+ DeleteByIDFunc: &AccessTokensStoreDeleteByIDFunc{
+ defaultHook: i.DeleteByID,
+ },
+ GetBySHA1Func: &AccessTokensStoreGetBySHA1Func{
+ defaultHook: i.GetBySHA1,
+ },
+ ListFunc: &AccessTokensStoreListFunc{
+ defaultHook: i.List,
+ },
+ SaveFunc: &AccessTokensStoreSaveFunc{
+ defaultHook: i.Save,
+ },
+ }
+}
+
+// AccessTokensStoreCreateFunc describes the behavior when the Create method
+// of the parent MockAccessTokensStore instance is invoked.
+type AccessTokensStoreCreateFunc struct {
+ defaultHook func(context.Context, int64, string) (*AccessToken, error)
+ hooks []func(context.Context, int64, string) (*AccessToken, error)
+ history []AccessTokensStoreCreateFuncCall
+ 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 *MockAccessTokensStore) Create(v0 context.Context, v1 int64, v2 string) (*AccessToken, error) {
+ r0, r1 := m.CreateFunc.nextHook()(v0, v1, v2)
+ m.CreateFunc.appendCall(AccessTokensStoreCreateFuncCall{v0, v1, v2, r0, r1})
+ return r0, r1
+}
+
+// SetDefaultHook sets function that is called when the Create method of the
+// parent MockAccessTokensStore instance is invoked and the hook queue is
+// empty.
+func (f *AccessTokensStoreCreateFunc) SetDefaultHook(hook func(context.Context, int64, string) (*AccessToken, error)) {
+ f.defaultHook = hook
+}
+
+// PushHook adds a function to the end of hook queue. Each invocation of the
+// Create method of the parent MockAccessTokensStore 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 *AccessTokensStoreCreateFunc) PushHook(hook func(context.Context, int64, string) (*AccessToken, 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 *AccessTokensStoreCreateFunc) SetDefaultReturn(r0 *AccessToken, r1 error) {
+ f.SetDefaultHook(func(context.Context, int64, string) (*AccessToken, error) {
+ return r0, r1
+ })
}
-func (m *MockAccessTokensStore) Create(userID int64, name string) (*AccessToken, error) {
- return m.MockCreate(userID, name)
+// PushReturn calls PushHook with a function that returns the given values.
+func (f *AccessTokensStoreCreateFunc) PushReturn(r0 *AccessToken, r1 error) {
+ f.PushHook(func(context.Context, int64, string) (*AccessToken, error) {
+ return r0, r1
+ })
}
-func (m *MockAccessTokensStore) DeleteByID(userID, id int64) error {
- return m.MockDeleteByID(userID, id)
+func (f *AccessTokensStoreCreateFunc) nextHook() func(context.Context, int64, string) (*AccessToken, 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 *AccessTokensStoreCreateFunc) appendCall(r0 AccessTokensStoreCreateFuncCall) {
+ f.mutex.Lock()
+ f.history = append(f.history, r0)
+ f.mutex.Unlock()
+}
+
+// History returns a sequence of AccessTokensStoreCreateFuncCall objects
+// describing the invocations of this function.
+func (f *AccessTokensStoreCreateFunc) History() []AccessTokensStoreCreateFuncCall {
+ f.mutex.Lock()
+ history := make([]AccessTokensStoreCreateFuncCall, len(f.history))
+ copy(history, f.history)
+ f.mutex.Unlock()
+
+ return history
+}
+
+// AccessTokensStoreCreateFuncCall is an object that describes an invocation
+// of method Create on an instance of MockAccessTokensStore.
+type AccessTokensStoreCreateFuncCall 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
+ // Result0 is the value of the 1st result returned from this method
+ // invocation.
+ Result0 *AccessToken
+ // 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 AccessTokensStoreCreateFuncCall) Args() []interface{} {
+ return []interface{}{c.Arg0, c.Arg1, c.Arg2}
+}
+
+// Results returns an interface slice containing the results of this
+// invocation.
+func (c AccessTokensStoreCreateFuncCall) Results() []interface{} {
+ return []interface{}{c.Result0, c.Result1}
+}
+
+// AccessTokensStoreDeleteByIDFunc describes the behavior when the
+// DeleteByID method of the parent MockAccessTokensStore instance is
+// invoked.
+type AccessTokensStoreDeleteByIDFunc struct {
+ defaultHook func(context.Context, int64, int64) error
+ hooks []func(context.Context, int64, int64) error
+ history []AccessTokensStoreDeleteByIDFuncCall
+ mutex sync.Mutex
+}
+
+// DeleteByID delegates to the next hook function in the queue and stores
+// the parameter and result values of this invocation.
+func (m *MockAccessTokensStore) DeleteByID(v0 context.Context, v1 int64, v2 int64) error {
+ r0 := m.DeleteByIDFunc.nextHook()(v0, v1, v2)
+ m.DeleteByIDFunc.appendCall(AccessTokensStoreDeleteByIDFuncCall{v0, v1, v2, r0})
+ return r0
+}
+
+// SetDefaultHook sets function that is called when the DeleteByID method of
+// the parent MockAccessTokensStore instance is invoked and the hook queue
+// is empty.
+func (f *AccessTokensStoreDeleteByIDFunc) SetDefaultHook(hook func(context.Context, int64, int64) error) {
+ f.defaultHook = hook
+}
+
+// PushHook adds a function to the end of hook queue. Each invocation of the
+// DeleteByID method of the parent MockAccessTokensStore 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 *AccessTokensStoreDeleteByIDFunc) PushHook(hook func(context.Context, int64, int64) 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 *AccessTokensStoreDeleteByIDFunc) SetDefaultReturn(r0 error) {
+ f.SetDefaultHook(func(context.Context, int64, int64) error {
+ return r0
+ })
}
-func (m *MockAccessTokensStore) GetBySHA1(sha string) (*AccessToken, error) {
- return m.MockGetBySHA1(sha)
+// PushReturn calls PushHook with a function that returns the given values.
+func (f *AccessTokensStoreDeleteByIDFunc) PushReturn(r0 error) {
+ f.PushHook(func(context.Context, int64, int64) error {
+ return r0
+ })
}
-func (m *MockAccessTokensStore) List(userID int64) ([]*AccessToken, error) {
- return m.MockList(userID)
-}
+func (f *AccessTokensStoreDeleteByIDFunc) nextHook() func(context.Context, int64, int64) error {
+ f.mutex.Lock()
+ defer f.mutex.Unlock()
+
+ if len(f.hooks) == 0 {
+ return f.defaultHook
+ }
-func (m *MockAccessTokensStore) Save(t *AccessToken) error {
- return m.MockSave(t)
+ hook := f.hooks[0]
+ f.hooks = f.hooks[1:]
+ return hook
}
-func SetMockAccessTokensStore(t *testing.T, mock AccessTokensStore) {
- before := AccessTokens
- AccessTokens = mock
- t.Cleanup(func() {
- AccessTokens = before
- })
+func (f *AccessTokensStoreDeleteByIDFunc) appendCall(r0 AccessTokensStoreDeleteByIDFuncCall) {
+ f.mutex.Lock()
+ f.history = append(f.history, r0)
+ f.mutex.Unlock()
}
-var _ LFSStore = (*MockLFSStore)(nil)
+// History returns a sequence of AccessTokensStoreDeleteByIDFuncCall objects
+// describing the invocations of this function.
+func (f *AccessTokensStoreDeleteByIDFunc) History() []AccessTokensStoreDeleteByIDFuncCall {
+ f.mutex.Lock()
+ history := make([]AccessTokensStoreDeleteByIDFuncCall, len(f.history))
+ copy(history, f.history)
+ f.mutex.Unlock()
-type MockLFSStore struct {
- MockCreateObject func(repoID int64, oid lfsutil.OID, size int64, storage lfsutil.Storage) error
- MockGetObjectByOID func(repoID int64, oid lfsutil.OID) (*LFSObject, error)
- MockGetObjectsByOIDs func(repoID int64, oids ...lfsutil.OID) ([]*LFSObject, error)
+ return history
}
-func (m *MockLFSStore) CreateObject(repoID int64, oid lfsutil.OID, size int64, storage lfsutil.Storage) error {
- return m.MockCreateObject(repoID, oid, size, storage)
+// AccessTokensStoreDeleteByIDFuncCall is an object that describes an
+// invocation of method DeleteByID on an instance of MockAccessTokensStore.
+type AccessTokensStoreDeleteByIDFuncCall 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 int64
+ // Result0 is the value of the 1st result returned from this method
+ // invocation.
+ Result0 error
}
-func (m *MockLFSStore) GetObjectByOID(repoID int64, oid lfsutil.OID) (*LFSObject, error) {
- return m.MockGetObjectByOID(repoID, oid)
+// Args returns an interface slice containing the arguments of this
+// invocation.
+func (c AccessTokensStoreDeleteByIDFuncCall) Args() []interface{} {
+ return []interface{}{c.Arg0, c.Arg1, c.Arg2}
}
-func (m *MockLFSStore) GetObjectsByOIDs(repoID int64, oids ...lfsutil.OID) ([]*LFSObject, error) {
- return m.MockGetObjectsByOIDs(repoID, oids...)
+// Results returns an interface slice containing the results of this
+// invocation.
+func (c AccessTokensStoreDeleteByIDFuncCall) Results() []interface{} {
+ return []interface{}{c.Result0}
}
-func SetMockLFSStore(t *testing.T, mock LFSStore) {
- before := LFS
- LFS = mock
- t.Cleanup(func() {
- LFS = before
- })
+// AccessTokensStoreGetBySHA1Func describes the behavior when the GetBySHA1
+// method of the parent MockAccessTokensStore instance is invoked.
+type AccessTokensStoreGetBySHA1Func struct {
+ defaultHook func(context.Context, string) (*AccessToken, error)
+ hooks []func(context.Context, string) (*AccessToken, error)
+ history []AccessTokensStoreGetBySHA1FuncCall
+ mutex sync.Mutex
}
-var _ loginSourceFilesStore = (*mockLoginSourceFilesStore)(nil)
+// GetBySHA1 delegates to the next hook function in the queue and stores the
+// parameter and result values of this invocation.
+func (m *MockAccessTokensStore) GetBySHA1(v0 context.Context, v1 string) (*AccessToken, error) {
+ r0, r1 := m.GetBySHA1Func.nextHook()(v0, v1)
+ m.GetBySHA1Func.appendCall(AccessTokensStoreGetBySHA1FuncCall{v0, v1, r0, r1})
+ return r0, r1
+}
-type mockLoginSourceFilesStore struct {
- MockGetByID func(id int64) (*LoginSource, error)
- MockLen func() int
- MockList func(opts ListLoginSourceOpts) []*LoginSource
- MockUpdate func(source *LoginSource)
+// SetDefaultHook sets function that is called when the GetBySHA1 method of
+// the parent MockAccessTokensStore instance is invoked and the hook queue
+// is empty.
+func (f *AccessTokensStoreGetBySHA1Func) SetDefaultHook(hook func(context.Context, string) (*AccessToken, error)) {
+ f.defaultHook = hook
}
-func (m *mockLoginSourceFilesStore) GetByID(id int64) (*LoginSource, error) {
- return m.MockGetByID(id)
+// PushHook adds a function to the end of hook queue. Each invocation of the
+// GetBySHA1 method of the parent MockAccessTokensStore 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 *AccessTokensStoreGetBySHA1Func) PushHook(hook func(context.Context, string) (*AccessToken, error)) {
+ f.mutex.Lock()
+ f.hooks = append(f.hooks, hook)
+ f.mutex.Unlock()
}
-func (m *mockLoginSourceFilesStore) Len() int {
- return m.MockLen()
+// SetDefaultReturn calls SetDefaultHook with a function that returns the
+// given values.
+func (f *AccessTokensStoreGetBySHA1Func) SetDefaultReturn(r0 *AccessToken, r1 error) {
+ f.SetDefaultHook(func(context.Context, string) (*AccessToken, error) {
+ return r0, r1
+ })
}
-func (m *mockLoginSourceFilesStore) List(opts ListLoginSourceOpts) []*LoginSource {
- return m.MockList(opts)
+// PushReturn calls PushHook with a function that returns the given values.
+func (f *AccessTokensStoreGetBySHA1Func) PushReturn(r0 *AccessToken, r1 error) {
+ f.PushHook(func(context.Context, string) (*AccessToken, error) {
+ return r0, r1
+ })
}
-func (m *mockLoginSourceFilesStore) Update(source *LoginSource) {
- m.MockUpdate(source)
+func (f *AccessTokensStoreGetBySHA1Func) nextHook() func(context.Context, string) (*AccessToken, 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 setMockLoginSourceFilesStore(t *testing.T, db *loginSources, mock loginSourceFilesStore) {
- before := db.files
- db.files = mock
- t.Cleanup(func() {
- db.files = before
- })
+func (f *AccessTokensStoreGetBySHA1Func) appendCall(r0 AccessTokensStoreGetBySHA1FuncCall) {
+ f.mutex.Lock()
+ f.history = append(f.history, r0)
+ f.mutex.Unlock()
}
-var _ loginSourceFileStore = (*mockLoginSourceFileStore)(nil)
+// History returns a sequence of AccessTokensStoreGetBySHA1FuncCall objects
+// describing the invocations of this function.
+func (f *AccessTokensStoreGetBySHA1Func) History() []AccessTokensStoreGetBySHA1FuncCall {
+ f.mutex.Lock()
+ history := make([]AccessTokensStoreGetBySHA1FuncCall, len(f.history))
+ copy(history, f.history)
+ f.mutex.Unlock()
-type mockLoginSourceFileStore struct {
- MockSetGeneral func(name, value string)
- MockSetConfig func(cfg interface{}) error
- MockSave func() error
+ return history
}
-func (m *mockLoginSourceFileStore) SetGeneral(name, value string) {
- m.MockSetGeneral(name, value)
+// AccessTokensStoreGetBySHA1FuncCall is an object that describes an
+// invocation of method GetBySHA1 on an instance of MockAccessTokensStore.
+type AccessTokensStoreGetBySHA1FuncCall 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 string
+ // Result0 is the value of the 1st result returned from this method
+ // invocation.
+ Result0 *AccessToken
+ // Result1 is the value of the 2nd result returned from this method
+ // invocation.
+ Result1 error
}
-func (m *mockLoginSourceFileStore) SetConfig(cfg interface{}) error {
- return m.MockSetConfig(cfg)
+// Args returns an interface slice containing the arguments of this
+// invocation.
+func (c AccessTokensStoreGetBySHA1FuncCall) Args() []interface{} {
+ return []interface{}{c.Arg0, c.Arg1}
}
-func (m *mockLoginSourceFileStore) Save() error {
- return m.MockSave()
+// Results returns an interface slice containing the results of this
+// invocation.
+func (c AccessTokensStoreGetBySHA1FuncCall) Results() []interface{} {
+ return []interface{}{c.Result0, c.Result1}
}
-var _ PermsStore = (*MockPermsStore)(nil)
+// AccessTokensStoreListFunc describes the behavior when the List method of
+// the parent MockAccessTokensStore instance is invoked.
+type AccessTokensStoreListFunc struct {
+ defaultHook func(context.Context, int64) ([]*AccessToken, error)
+ hooks []func(context.Context, int64) ([]*AccessToken, error)
+ history []AccessTokensStoreListFuncCall
+ mutex sync.Mutex
+}
-type MockPermsStore struct {
- MockAccessMode func(userID, repoID int64, opts AccessModeOptions) AccessMode
- MockAuthorize func(userID, repoID int64, desired AccessMode, opts AccessModeOptions) bool
- MockSetRepoPerms func(repoID int64, accessMap map[int64]AccessMode) error
+// List delegates to the next hook function in the queue and stores the
+// parameter and result values of this invocation.
+func (m *MockAccessTokensStore) List(v0 context.Context, v1 int64) ([]*AccessToken, error) {
+ r0, r1 := m.ListFunc.nextHook()(v0, v1)
+ m.ListFunc.appendCall(AccessTokensStoreListFuncCall{v0, v1, r0, r1})
+ return r0, r1
}
-func (m *MockPermsStore) AccessMode(userID, repoID int64, opts AccessModeOptions) AccessMode {
- return m.MockAccessMode(userID, repoID, opts)
+// SetDefaultHook sets function that is called when the List method of the
+// parent MockAccessTokensStore instance is invoked and the hook queue is
+// empty.
+func (f *AccessTokensStoreListFunc) SetDefaultHook(hook func(context.Context, int64) ([]*AccessToken, error)) {
+ f.defaultHook = hook
}
-func (m *MockPermsStore) Authorize(userID, repoID int64, desired AccessMode, opts AccessModeOptions) bool {
- return m.MockAuthorize(userID, repoID, desired, opts)
+// PushHook adds a function to the end of hook queue. Each invocation of the
+// List method of the parent MockAccessTokensStore 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 *AccessTokensStoreListFunc) PushHook(hook func(context.Context, int64) ([]*AccessToken, error)) {
+ f.mutex.Lock()
+ f.hooks = append(f.hooks, hook)
+ f.mutex.Unlock()
}
-func (m *MockPermsStore) SetRepoPerms(repoID int64, accessMap map[int64]AccessMode) error {
- return m.MockSetRepoPerms(repoID, accessMap)
+// SetDefaultReturn calls SetDefaultHook with a function that returns the
+// given values.
+func (f *AccessTokensStoreListFunc) SetDefaultReturn(r0 []*AccessToken, r1 error) {
+ f.SetDefaultHook(func(context.Context, int64) ([]*AccessToken, error) {
+ return r0, r1
+ })
}
-func SetMockPermsStore(t *testing.T, mock PermsStore) {
- before := Perms
- Perms = mock
- t.Cleanup(func() {
- Perms = before
+// PushReturn calls PushHook with a function that returns the given values.
+func (f *AccessTokensStoreListFunc) PushReturn(r0 []*AccessToken, r1 error) {
+ f.PushHook(func(context.Context, int64) ([]*AccessToken, error) {
+ return r0, r1
})
}
-var _ ReposStore = (*MockReposStore)(nil)
+func (f *AccessTokensStoreListFunc) nextHook() func(context.Context, int64) ([]*AccessToken, error) {
+ f.mutex.Lock()
+ defer f.mutex.Unlock()
-type MockReposStore struct {
- MockGetByName func(ownerID int64, name string) (*Repository, error)
+ if len(f.hooks) == 0 {
+ return f.defaultHook
+ }
+
+ hook := f.hooks[0]
+ f.hooks = f.hooks[1:]
+ return hook
}
-func (m *MockReposStore) GetByName(ownerID int64, name string) (*Repository, error) {
- return m.MockGetByName(ownerID, name)
+func (f *AccessTokensStoreListFunc) appendCall(r0 AccessTokensStoreListFuncCall) {
+ f.mutex.Lock()
+ f.history = append(f.history, r0)
+ f.mutex.Unlock()
}
-func SetMockReposStore(t *testing.T, mock ReposStore) {
- before := Repos
- Repos = mock
- t.Cleanup(func() {
- Repos = before
- })
+// History returns a sequence of AccessTokensStoreListFuncCall objects
+// describing the invocations of this function.
+func (f *AccessTokensStoreListFunc) History() []AccessTokensStoreListFuncCall {
+ f.mutex.Lock()
+ history := make([]AccessTokensStoreListFuncCall, len(f.history))
+ copy(history, f.history)
+ f.mutex.Unlock()
+
+ return history
}
-var _ TwoFactorsStore = (*MockTwoFactorsStore)(nil)
+// AccessTokensStoreListFuncCall is an object that describes an invocation
+// of method List on an instance of MockAccessTokensStore.
+type AccessTokensStoreListFuncCall 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 []*AccessToken
+ // Result1 is the value of the 2nd result returned from this method
+ // invocation.
+ Result1 error
+}
-type MockTwoFactorsStore struct {
- MockCreate func(userID int64, key, secret string) error
- MockGetByUserID func(userID int64) (*TwoFactor, error)
- MockIsUserEnabled func(userID int64) bool
+// Args returns an interface slice containing the arguments of this
+// invocation.
+func (c AccessTokensStoreListFuncCall) Args() []interface{} {
+ return []interface{}{c.Arg0, c.Arg1}
}
-func (m *MockTwoFactorsStore) Create(userID int64, key, secret string) error {
- return m.MockCreate(userID, key, secret)
+// Results returns an interface slice containing the results of this
+// invocation.
+func (c AccessTokensStoreListFuncCall) Results() []interface{} {
+ return []interface{}{c.Result0, c.Result1}
}
-func (m *MockTwoFactorsStore) GetByUserID(userID int64) (*TwoFactor, error) {
- return m.MockGetByUserID(userID)
+// AccessTokensStoreSaveFunc describes the behavior when the Save method of
+// the parent MockAccessTokensStore instance is invoked.
+type AccessTokensStoreSaveFunc struct {
+ defaultHook func(context.Context, *AccessToken) error
+ hooks []func(context.Context, *AccessToken) error
+ history []AccessTokensStoreSaveFuncCall
+ mutex sync.Mutex
}
-func (m *MockTwoFactorsStore) IsUserEnabled(userID int64) bool {
- return m.MockIsUserEnabled(userID)
+// Save delegates to the next hook function in the queue and stores the
+// parameter and result values of this invocation.
+func (m *MockAccessTokensStore) Save(v0 context.Context, v1 *AccessToken) error {
+ r0 := m.SaveFunc.nextHook()(v0, v1)
+ m.SaveFunc.appendCall(AccessTokensStoreSaveFuncCall{v0, v1, r0})
+ return r0
}
-func SetMockTwoFactorsStore(t *testing.T, mock TwoFactorsStore) {
- before := TwoFactors
- TwoFactors = mock
- t.Cleanup(func() {
- TwoFactors = before
- })
+// SetDefaultHook sets function that is called when the Save method of the
+// parent MockAccessTokensStore instance is invoked and the hook queue is
+// empty.
+func (f *AccessTokensStoreSaveFunc) SetDefaultHook(hook func(context.Context, *AccessToken) error) {
+ f.defaultHook = hook
+}
+
+// PushHook adds a function to the end of hook queue. Each invocation of the
+// Save method of the parent MockAccessTokensStore 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 *AccessTokensStoreSaveFunc) PushHook(hook func(context.Context, *AccessToken) error) {
+ f.mutex.Lock()
+ f.hooks = append(f.hooks, hook)
+ f.mutex.Unlock()
}
-var _ UsersStore = (*MockUsersStore)(nil)
+// SetDefaultReturn calls SetDefaultHook with a function that returns the
+// given values.
+func (f *AccessTokensStoreSaveFunc) SetDefaultReturn(r0 error) {
+ f.SetDefaultHook(func(context.Context, *AccessToken) error {
+ return r0
+ })
+}
-type MockUsersStore struct {
- MockAuthenticate func(username, password string, loginSourceID int64) (*User, error)
- MockCreate func(username, email string, opts CreateUserOpts) (*User, error)
- MockGetByEmail func(email string) (*User, error)
- MockGetByID func(id int64) (*User, error)
- MockGetByUsername func(username string) (*User, error)
+// PushReturn calls PushHook with a function that returns the given values.
+func (f *AccessTokensStoreSaveFunc) PushReturn(r0 error) {
+ f.PushHook(func(context.Context, *AccessToken) error {
+ return r0
+ })
}
-func (m *MockUsersStore) Authenticate(username, password string, loginSourceID int64) (*User, error) {
- return m.MockAuthenticate(username, password, loginSourceID)
+func (f *AccessTokensStoreSaveFunc) nextHook() func(context.Context, *AccessToken) 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 (m *MockUsersStore) Create(username, email string, opts CreateUserOpts) (*User, error) {
- return m.MockCreate(username, email, opts)
+func (f *AccessTokensStoreSaveFunc) appendCall(r0 AccessTokensStoreSaveFuncCall) {
+ f.mutex.Lock()
+ f.history = append(f.history, r0)
+ f.mutex.Unlock()
}
-func (m *MockUsersStore) GetByEmail(email string) (*User, error) {
- return m.MockGetByEmail(email)
+// History returns a sequence of AccessTokensStoreSaveFuncCall objects
+// describing the invocations of this function.
+func (f *AccessTokensStoreSaveFunc) History() []AccessTokensStoreSaveFuncCall {
+ f.mutex.Lock()
+ history := make([]AccessTokensStoreSaveFuncCall, len(f.history))
+ copy(history, f.history)
+ f.mutex.Unlock()
+
+ return history
}
-func (m *MockUsersStore) GetByID(id int64) (*User, error) {
- return m.MockGetByID(id)
+// AccessTokensStoreSaveFuncCall is an object that describes an invocation
+// of method Save on an instance of MockAccessTokensStore.
+type AccessTokensStoreSaveFuncCall 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 *AccessToken
+ // Result0 is the value of the 1st result returned from this method
+ // invocation.
+ Result0 error
}
-func (m *MockUsersStore) GetByUsername(username string) (*User, error) {
- return m.MockGetByUsername(username)
+// Args returns an interface slice containing the arguments of this
+// invocation.
+func (c AccessTokensStoreSaveFuncCall) Args() []interface{} {
+ return []interface{}{c.Arg0, c.Arg1}
}
-func SetMockUsersStore(t *testing.T, mock UsersStore) {
- before := Users
- Users = mock
- t.Cleanup(func() {
- Users = before
- })
+// Results returns an interface slice containing the results of this
+// invocation.
+func (c AccessTokensStoreSaveFuncCall) Results() []interface{} {
+ return []interface{}{c.Result0}
}