123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620 |
- package database
- import (
- "sync"
- auth "gogs.io/gogs/internal/auth"
- )
- type MockProvider struct {
-
-
- AuthenticateFunc *ProviderAuthenticateFunc
-
-
- ConfigFunc *ProviderConfigFunc
-
-
- HasTLSFunc *ProviderHasTLSFunc
-
-
- SkipTLSVerifyFunc *ProviderSkipTLSVerifyFunc
-
-
- UseTLSFunc *ProviderUseTLSFunc
- }
- func NewMockProvider() *MockProvider {
- return &MockProvider{
- AuthenticateFunc: &ProviderAuthenticateFunc{
- defaultHook: func(string, string) (r0 *auth.ExternalAccount, r1 error) {
- return
- },
- },
- ConfigFunc: &ProviderConfigFunc{
- defaultHook: func() (r0 interface{}) {
- return
- },
- },
- HasTLSFunc: &ProviderHasTLSFunc{
- defaultHook: func() (r0 bool) {
- return
- },
- },
- SkipTLSVerifyFunc: &ProviderSkipTLSVerifyFunc{
- defaultHook: func() (r0 bool) {
- return
- },
- },
- UseTLSFunc: &ProviderUseTLSFunc{
- defaultHook: func() (r0 bool) {
- return
- },
- },
- }
- }
- func NewStrictMockProvider() *MockProvider {
- return &MockProvider{
- AuthenticateFunc: &ProviderAuthenticateFunc{
- defaultHook: func(string, string) (*auth.ExternalAccount, error) {
- panic("unexpected invocation of MockProvider.Authenticate")
- },
- },
- ConfigFunc: &ProviderConfigFunc{
- defaultHook: func() interface{} {
- panic("unexpected invocation of MockProvider.Config")
- },
- },
- HasTLSFunc: &ProviderHasTLSFunc{
- defaultHook: func() bool {
- panic("unexpected invocation of MockProvider.HasTLS")
- },
- },
- SkipTLSVerifyFunc: &ProviderSkipTLSVerifyFunc{
- defaultHook: func() bool {
- panic("unexpected invocation of MockProvider.SkipTLSVerify")
- },
- },
- UseTLSFunc: &ProviderUseTLSFunc{
- defaultHook: func() bool {
- panic("unexpected invocation of MockProvider.UseTLS")
- },
- },
- }
- }
- func NewMockProviderFrom(i auth.Provider) *MockProvider {
- return &MockProvider{
- AuthenticateFunc: &ProviderAuthenticateFunc{
- defaultHook: i.Authenticate,
- },
- ConfigFunc: &ProviderConfigFunc{
- defaultHook: i.Config,
- },
- HasTLSFunc: &ProviderHasTLSFunc{
- defaultHook: i.HasTLS,
- },
- SkipTLSVerifyFunc: &ProviderSkipTLSVerifyFunc{
- defaultHook: i.SkipTLSVerify,
- },
- UseTLSFunc: &ProviderUseTLSFunc{
- defaultHook: i.UseTLS,
- },
- }
- }
- type ProviderAuthenticateFunc struct {
- defaultHook func(string, string) (*auth.ExternalAccount, error)
- hooks []func(string, string) (*auth.ExternalAccount, error)
- history []ProviderAuthenticateFuncCall
- mutex sync.Mutex
- }
- func (m *MockProvider) Authenticate(v0 string, v1 string) (*auth.ExternalAccount, error) {
- r0, r1 := m.AuthenticateFunc.nextHook()(v0, v1)
- m.AuthenticateFunc.appendCall(ProviderAuthenticateFuncCall{v0, v1, r0, r1})
- return r0, r1
- }
- func (f *ProviderAuthenticateFunc) SetDefaultHook(hook func(string, string) (*auth.ExternalAccount, error)) {
- f.defaultHook = hook
- }
- func (f *ProviderAuthenticateFunc) PushHook(hook func(string, string) (*auth.ExternalAccount, error)) {
- f.mutex.Lock()
- f.hooks = append(f.hooks, hook)
- f.mutex.Unlock()
- }
- func (f *ProviderAuthenticateFunc) SetDefaultReturn(r0 *auth.ExternalAccount, r1 error) {
- f.SetDefaultHook(func(string, string) (*auth.ExternalAccount, error) {
- return r0, r1
- })
- }
- func (f *ProviderAuthenticateFunc) PushReturn(r0 *auth.ExternalAccount, r1 error) {
- f.PushHook(func(string, string) (*auth.ExternalAccount, error) {
- return r0, r1
- })
- }
- func (f *ProviderAuthenticateFunc) nextHook() func(string, string) (*auth.ExternalAccount, 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 *ProviderAuthenticateFunc) appendCall(r0 ProviderAuthenticateFuncCall) {
- f.mutex.Lock()
- f.history = append(f.history, r0)
- f.mutex.Unlock()
- }
- func (f *ProviderAuthenticateFunc) History() []ProviderAuthenticateFuncCall {
- f.mutex.Lock()
- history := make([]ProviderAuthenticateFuncCall, len(f.history))
- copy(history, f.history)
- f.mutex.Unlock()
- return history
- }
- type ProviderAuthenticateFuncCall struct {
-
-
- Arg0 string
-
-
- Arg1 string
-
-
- Result0 *auth.ExternalAccount
-
-
- Result1 error
- }
- func (c ProviderAuthenticateFuncCall) Args() []interface{} {
- return []interface{}{c.Arg0, c.Arg1}
- }
- func (c ProviderAuthenticateFuncCall) Results() []interface{} {
- return []interface{}{c.Result0, c.Result1}
- }
- type ProviderConfigFunc struct {
- defaultHook func() interface{}
- hooks []func() interface{}
- history []ProviderConfigFuncCall
- mutex sync.Mutex
- }
- func (m *MockProvider) Config() interface{} {
- r0 := m.ConfigFunc.nextHook()()
- m.ConfigFunc.appendCall(ProviderConfigFuncCall{r0})
- return r0
- }
- func (f *ProviderConfigFunc) SetDefaultHook(hook func() interface{}) {
- f.defaultHook = hook
- }
- func (f *ProviderConfigFunc) PushHook(hook func() interface{}) {
- f.mutex.Lock()
- f.hooks = append(f.hooks, hook)
- f.mutex.Unlock()
- }
- func (f *ProviderConfigFunc) SetDefaultReturn(r0 interface{}) {
- f.SetDefaultHook(func() interface{} {
- return r0
- })
- }
- func (f *ProviderConfigFunc) PushReturn(r0 interface{}) {
- f.PushHook(func() interface{} {
- return r0
- })
- }
- func (f *ProviderConfigFunc) nextHook() func() interface{} {
- 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 *ProviderConfigFunc) appendCall(r0 ProviderConfigFuncCall) {
- f.mutex.Lock()
- f.history = append(f.history, r0)
- f.mutex.Unlock()
- }
- func (f *ProviderConfigFunc) History() []ProviderConfigFuncCall {
- f.mutex.Lock()
- history := make([]ProviderConfigFuncCall, len(f.history))
- copy(history, f.history)
- f.mutex.Unlock()
- return history
- }
- type ProviderConfigFuncCall struct {
-
-
- Result0 interface{}
- }
- func (c ProviderConfigFuncCall) Args() []interface{} {
- return []interface{}{}
- }
- func (c ProviderConfigFuncCall) Results() []interface{} {
- return []interface{}{c.Result0}
- }
- type ProviderHasTLSFunc struct {
- defaultHook func() bool
- hooks []func() bool
- history []ProviderHasTLSFuncCall
- mutex sync.Mutex
- }
- func (m *MockProvider) HasTLS() bool {
- r0 := m.HasTLSFunc.nextHook()()
- m.HasTLSFunc.appendCall(ProviderHasTLSFuncCall{r0})
- return r0
- }
- func (f *ProviderHasTLSFunc) SetDefaultHook(hook func() bool) {
- f.defaultHook = hook
- }
- func (f *ProviderHasTLSFunc) PushHook(hook func() bool) {
- f.mutex.Lock()
- f.hooks = append(f.hooks, hook)
- f.mutex.Unlock()
- }
- func (f *ProviderHasTLSFunc) SetDefaultReturn(r0 bool) {
- f.SetDefaultHook(func() bool {
- return r0
- })
- }
- func (f *ProviderHasTLSFunc) PushReturn(r0 bool) {
- f.PushHook(func() bool {
- return r0
- })
- }
- func (f *ProviderHasTLSFunc) nextHook() func() 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 *ProviderHasTLSFunc) appendCall(r0 ProviderHasTLSFuncCall) {
- f.mutex.Lock()
- f.history = append(f.history, r0)
- f.mutex.Unlock()
- }
- func (f *ProviderHasTLSFunc) History() []ProviderHasTLSFuncCall {
- f.mutex.Lock()
- history := make([]ProviderHasTLSFuncCall, len(f.history))
- copy(history, f.history)
- f.mutex.Unlock()
- return history
- }
- type ProviderHasTLSFuncCall struct {
-
-
- Result0 bool
- }
- func (c ProviderHasTLSFuncCall) Args() []interface{} {
- return []interface{}{}
- }
- func (c ProviderHasTLSFuncCall) Results() []interface{} {
- return []interface{}{c.Result0}
- }
- type ProviderSkipTLSVerifyFunc struct {
- defaultHook func() bool
- hooks []func() bool
- history []ProviderSkipTLSVerifyFuncCall
- mutex sync.Mutex
- }
- func (m *MockProvider) SkipTLSVerify() bool {
- r0 := m.SkipTLSVerifyFunc.nextHook()()
- m.SkipTLSVerifyFunc.appendCall(ProviderSkipTLSVerifyFuncCall{r0})
- return r0
- }
- func (f *ProviderSkipTLSVerifyFunc) SetDefaultHook(hook func() bool) {
- f.defaultHook = hook
- }
- func (f *ProviderSkipTLSVerifyFunc) PushHook(hook func() bool) {
- f.mutex.Lock()
- f.hooks = append(f.hooks, hook)
- f.mutex.Unlock()
- }
- func (f *ProviderSkipTLSVerifyFunc) SetDefaultReturn(r0 bool) {
- f.SetDefaultHook(func() bool {
- return r0
- })
- }
- func (f *ProviderSkipTLSVerifyFunc) PushReturn(r0 bool) {
- f.PushHook(func() bool {
- return r0
- })
- }
- func (f *ProviderSkipTLSVerifyFunc) nextHook() func() 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 *ProviderSkipTLSVerifyFunc) appendCall(r0 ProviderSkipTLSVerifyFuncCall) {
- f.mutex.Lock()
- f.history = append(f.history, r0)
- f.mutex.Unlock()
- }
- func (f *ProviderSkipTLSVerifyFunc) History() []ProviderSkipTLSVerifyFuncCall {
- f.mutex.Lock()
- history := make([]ProviderSkipTLSVerifyFuncCall, len(f.history))
- copy(history, f.history)
- f.mutex.Unlock()
- return history
- }
- type ProviderSkipTLSVerifyFuncCall struct {
-
-
- Result0 bool
- }
- func (c ProviderSkipTLSVerifyFuncCall) Args() []interface{} {
- return []interface{}{}
- }
- func (c ProviderSkipTLSVerifyFuncCall) Results() []interface{} {
- return []interface{}{c.Result0}
- }
- type ProviderUseTLSFunc struct {
- defaultHook func() bool
- hooks []func() bool
- history []ProviderUseTLSFuncCall
- mutex sync.Mutex
- }
- func (m *MockProvider) UseTLS() bool {
- r0 := m.UseTLSFunc.nextHook()()
- m.UseTLSFunc.appendCall(ProviderUseTLSFuncCall{r0})
- return r0
- }
- func (f *ProviderUseTLSFunc) SetDefaultHook(hook func() bool) {
- f.defaultHook = hook
- }
- func (f *ProviderUseTLSFunc) PushHook(hook func() bool) {
- f.mutex.Lock()
- f.hooks = append(f.hooks, hook)
- f.mutex.Unlock()
- }
- func (f *ProviderUseTLSFunc) SetDefaultReturn(r0 bool) {
- f.SetDefaultHook(func() bool {
- return r0
- })
- }
- func (f *ProviderUseTLSFunc) PushReturn(r0 bool) {
- f.PushHook(func() bool {
- return r0
- })
- }
- func (f *ProviderUseTLSFunc) nextHook() func() 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 *ProviderUseTLSFunc) appendCall(r0 ProviderUseTLSFuncCall) {
- f.mutex.Lock()
- f.history = append(f.history, r0)
- f.mutex.Unlock()
- }
- func (f *ProviderUseTLSFunc) History() []ProviderUseTLSFuncCall {
- f.mutex.Lock()
- history := make([]ProviderUseTLSFuncCall, len(f.history))
- copy(history, f.history)
- f.mutex.Unlock()
- return history
- }
- type ProviderUseTLSFuncCall struct {
-
-
- Result0 bool
- }
- func (c ProviderUseTLSFuncCall) Args() []interface{} {
- return []interface{}{}
- }
- func (c ProviderUseTLSFuncCall) Results() []interface{} {
- return []interface{}{c.Result0}
- }
|