123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969 |
- package mocks
- // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT.
- //go:generate minimock -i git.dmitriygnatenko.ru/dima/homethings/internal/interfaces.Auth -o ./mocks/auth_minimock.go -n AuthMock
- import (
- "sync"
- mm_atomic "sync/atomic"
- mm_time "time"
- "git.dmitriygnatenko.ru/dima/homethings/internal/models"
- "github.com/gofiber/fiber/v2"
- "github.com/gojuno/minimock/v3"
- "github.com/golang-jwt/jwt/v4"
- )
- // AuthMock implements interfaces.Auth
- type AuthMock struct {
- t minimock.Tester
- funcGeneratePasswordHash func(password string) (s1 string, err error)
- inspectFuncGeneratePasswordHash func(password string)
- afterGeneratePasswordHashCounter uint64
- beforeGeneratePasswordHashCounter uint64
- GeneratePasswordHashMock mAuthMockGeneratePasswordHash
- funcGenerateToken func(user models.User) (s1 string, err error)
- inspectFuncGenerateToken func(user models.User)
- afterGenerateTokenCounter uint64
- beforeGenerateTokenCounter uint64
- GenerateTokenMock mAuthMockGenerateToken
- funcGetClaims func(fctx *fiber.Ctx) (m1 jwt.MapClaims)
- inspectFuncGetClaims func(fctx *fiber.Ctx)
- afterGetClaimsCounter uint64
- beforeGetClaimsCounter uint64
- GetClaimsMock mAuthMockGetClaims
- funcIsCorrectPassword func(password string, hash string) (b1 bool)
- inspectFuncIsCorrectPassword func(password string, hash string)
- afterIsCorrectPasswordCounter uint64
- beforeIsCorrectPasswordCounter uint64
- IsCorrectPasswordMock mAuthMockIsCorrectPassword
- }
- // NewAuthMock returns a mock for interfaces.Auth
- func NewAuthMock(t minimock.Tester) *AuthMock {
- m := &AuthMock{t: t}
- if controller, ok := t.(minimock.MockController); ok {
- controller.RegisterMocker(m)
- }
- m.GeneratePasswordHashMock = mAuthMockGeneratePasswordHash{mock: m}
- m.GeneratePasswordHashMock.callArgs = []*AuthMockGeneratePasswordHashParams{}
- m.GenerateTokenMock = mAuthMockGenerateToken{mock: m}
- m.GenerateTokenMock.callArgs = []*AuthMockGenerateTokenParams{}
- m.GetClaimsMock = mAuthMockGetClaims{mock: m}
- m.GetClaimsMock.callArgs = []*AuthMockGetClaimsParams{}
- m.IsCorrectPasswordMock = mAuthMockIsCorrectPassword{mock: m}
- m.IsCorrectPasswordMock.callArgs = []*AuthMockIsCorrectPasswordParams{}
- return m
- }
- type mAuthMockGeneratePasswordHash struct {
- mock *AuthMock
- defaultExpectation *AuthMockGeneratePasswordHashExpectation
- expectations []*AuthMockGeneratePasswordHashExpectation
- callArgs []*AuthMockGeneratePasswordHashParams
- mutex sync.RWMutex
- }
- // AuthMockGeneratePasswordHashExpectation specifies expectation struct of the Auth.GeneratePasswordHash
- type AuthMockGeneratePasswordHashExpectation struct {
- mock *AuthMock
- params *AuthMockGeneratePasswordHashParams
- results *AuthMockGeneratePasswordHashResults
- Counter uint64
- }
- // AuthMockGeneratePasswordHashParams contains parameters of the Auth.GeneratePasswordHash
- type AuthMockGeneratePasswordHashParams struct {
- password string
- }
- // AuthMockGeneratePasswordHashResults contains results of the Auth.GeneratePasswordHash
- type AuthMockGeneratePasswordHashResults struct {
- s1 string
- err error
- }
- // Expect sets up expected params for Auth.GeneratePasswordHash
- func (mmGeneratePasswordHash *mAuthMockGeneratePasswordHash) Expect(password string) *mAuthMockGeneratePasswordHash {
- if mmGeneratePasswordHash.mock.funcGeneratePasswordHash != nil {
- mmGeneratePasswordHash.mock.t.Fatalf("AuthMock.GeneratePasswordHash mock is already set by Set")
- }
- if mmGeneratePasswordHash.defaultExpectation == nil {
- mmGeneratePasswordHash.defaultExpectation = &AuthMockGeneratePasswordHashExpectation{}
- }
- mmGeneratePasswordHash.defaultExpectation.params = &AuthMockGeneratePasswordHashParams{password}
- for _, e := range mmGeneratePasswordHash.expectations {
- if minimock.Equal(e.params, mmGeneratePasswordHash.defaultExpectation.params) {
- mmGeneratePasswordHash.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGeneratePasswordHash.defaultExpectation.params)
- }
- }
- return mmGeneratePasswordHash
- }
- // Inspect accepts an inspector function that has same arguments as the Auth.GeneratePasswordHash
- func (mmGeneratePasswordHash *mAuthMockGeneratePasswordHash) Inspect(f func(password string)) *mAuthMockGeneratePasswordHash {
- if mmGeneratePasswordHash.mock.inspectFuncGeneratePasswordHash != nil {
- mmGeneratePasswordHash.mock.t.Fatalf("Inspect function is already set for AuthMock.GeneratePasswordHash")
- }
- mmGeneratePasswordHash.mock.inspectFuncGeneratePasswordHash = f
- return mmGeneratePasswordHash
- }
- // Return sets up results that will be returned by Auth.GeneratePasswordHash
- func (mmGeneratePasswordHash *mAuthMockGeneratePasswordHash) Return(s1 string, err error) *AuthMock {
- if mmGeneratePasswordHash.mock.funcGeneratePasswordHash != nil {
- mmGeneratePasswordHash.mock.t.Fatalf("AuthMock.GeneratePasswordHash mock is already set by Set")
- }
- if mmGeneratePasswordHash.defaultExpectation == nil {
- mmGeneratePasswordHash.defaultExpectation = &AuthMockGeneratePasswordHashExpectation{mock: mmGeneratePasswordHash.mock}
- }
- mmGeneratePasswordHash.defaultExpectation.results = &AuthMockGeneratePasswordHashResults{s1, err}
- return mmGeneratePasswordHash.mock
- }
- // Set uses given function f to mock the Auth.GeneratePasswordHash method
- func (mmGeneratePasswordHash *mAuthMockGeneratePasswordHash) Set(f func(password string) (s1 string, err error)) *AuthMock {
- if mmGeneratePasswordHash.defaultExpectation != nil {
- mmGeneratePasswordHash.mock.t.Fatalf("Default expectation is already set for the Auth.GeneratePasswordHash method")
- }
- if len(mmGeneratePasswordHash.expectations) > 0 {
- mmGeneratePasswordHash.mock.t.Fatalf("Some expectations are already set for the Auth.GeneratePasswordHash method")
- }
- mmGeneratePasswordHash.mock.funcGeneratePasswordHash = f
- return mmGeneratePasswordHash.mock
- }
- // When sets expectation for the Auth.GeneratePasswordHash which will trigger the result defined by the following
- // Then helper
- func (mmGeneratePasswordHash *mAuthMockGeneratePasswordHash) When(password string) *AuthMockGeneratePasswordHashExpectation {
- if mmGeneratePasswordHash.mock.funcGeneratePasswordHash != nil {
- mmGeneratePasswordHash.mock.t.Fatalf("AuthMock.GeneratePasswordHash mock is already set by Set")
- }
- expectation := &AuthMockGeneratePasswordHashExpectation{
- mock: mmGeneratePasswordHash.mock,
- params: &AuthMockGeneratePasswordHashParams{password},
- }
- mmGeneratePasswordHash.expectations = append(mmGeneratePasswordHash.expectations, expectation)
- return expectation
- }
- // Then sets up Auth.GeneratePasswordHash return parameters for the expectation previously defined by the When method
- func (e *AuthMockGeneratePasswordHashExpectation) Then(s1 string, err error) *AuthMock {
- e.results = &AuthMockGeneratePasswordHashResults{s1, err}
- return e.mock
- }
- // GeneratePasswordHash implements interfaces.Auth
- func (mmGeneratePasswordHash *AuthMock) GeneratePasswordHash(password string) (s1 string, err error) {
- mm_atomic.AddUint64(&mmGeneratePasswordHash.beforeGeneratePasswordHashCounter, 1)
- defer mm_atomic.AddUint64(&mmGeneratePasswordHash.afterGeneratePasswordHashCounter, 1)
- if mmGeneratePasswordHash.inspectFuncGeneratePasswordHash != nil {
- mmGeneratePasswordHash.inspectFuncGeneratePasswordHash(password)
- }
- mm_params := &AuthMockGeneratePasswordHashParams{password}
- // Record call args
- mmGeneratePasswordHash.GeneratePasswordHashMock.mutex.Lock()
- mmGeneratePasswordHash.GeneratePasswordHashMock.callArgs = append(mmGeneratePasswordHash.GeneratePasswordHashMock.callArgs, mm_params)
- mmGeneratePasswordHash.GeneratePasswordHashMock.mutex.Unlock()
- for _, e := range mmGeneratePasswordHash.GeneratePasswordHashMock.expectations {
- if minimock.Equal(e.params, mm_params) {
- mm_atomic.AddUint64(&e.Counter, 1)
- return e.results.s1, e.results.err
- }
- }
- if mmGeneratePasswordHash.GeneratePasswordHashMock.defaultExpectation != nil {
- mm_atomic.AddUint64(&mmGeneratePasswordHash.GeneratePasswordHashMock.defaultExpectation.Counter, 1)
- mm_want := mmGeneratePasswordHash.GeneratePasswordHashMock.defaultExpectation.params
- mm_got := AuthMockGeneratePasswordHashParams{password}
- if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
- mmGeneratePasswordHash.t.Errorf("AuthMock.GeneratePasswordHash got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
- }
- mm_results := mmGeneratePasswordHash.GeneratePasswordHashMock.defaultExpectation.results
- if mm_results == nil {
- mmGeneratePasswordHash.t.Fatal("No results are set for the AuthMock.GeneratePasswordHash")
- }
- return (*mm_results).s1, (*mm_results).err
- }
- if mmGeneratePasswordHash.funcGeneratePasswordHash != nil {
- return mmGeneratePasswordHash.funcGeneratePasswordHash(password)
- }
- mmGeneratePasswordHash.t.Fatalf("Unexpected call to AuthMock.GeneratePasswordHash. %v", password)
- return
- }
- // GeneratePasswordHashAfterCounter returns a count of finished AuthMock.GeneratePasswordHash invocations
- func (mmGeneratePasswordHash *AuthMock) GeneratePasswordHashAfterCounter() uint64 {
- return mm_atomic.LoadUint64(&mmGeneratePasswordHash.afterGeneratePasswordHashCounter)
- }
- // GeneratePasswordHashBeforeCounter returns a count of AuthMock.GeneratePasswordHash invocations
- func (mmGeneratePasswordHash *AuthMock) GeneratePasswordHashBeforeCounter() uint64 {
- return mm_atomic.LoadUint64(&mmGeneratePasswordHash.beforeGeneratePasswordHashCounter)
- }
- // Calls returns a list of arguments used in each call to AuthMock.GeneratePasswordHash.
- // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
- func (mmGeneratePasswordHash *mAuthMockGeneratePasswordHash) Calls() []*AuthMockGeneratePasswordHashParams {
- mmGeneratePasswordHash.mutex.RLock()
- argCopy := make([]*AuthMockGeneratePasswordHashParams, len(mmGeneratePasswordHash.callArgs))
- copy(argCopy, mmGeneratePasswordHash.callArgs)
- mmGeneratePasswordHash.mutex.RUnlock()
- return argCopy
- }
- // MinimockGeneratePasswordHashDone returns true if the count of the GeneratePasswordHash invocations corresponds
- // the number of defined expectations
- func (m *AuthMock) MinimockGeneratePasswordHashDone() bool {
- for _, e := range m.GeneratePasswordHashMock.expectations {
- if mm_atomic.LoadUint64(&e.Counter) < 1 {
- return false
- }
- }
- // if default expectation was set then invocations count should be greater than zero
- if m.GeneratePasswordHashMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGeneratePasswordHashCounter) < 1 {
- return false
- }
- // if func was set then invocations count should be greater than zero
- if m.funcGeneratePasswordHash != nil && mm_atomic.LoadUint64(&m.afterGeneratePasswordHashCounter) < 1 {
- return false
- }
- return true
- }
- // MinimockGeneratePasswordHashInspect logs each unmet expectation
- func (m *AuthMock) MinimockGeneratePasswordHashInspect() {
- for _, e := range m.GeneratePasswordHashMock.expectations {
- if mm_atomic.LoadUint64(&e.Counter) < 1 {
- m.t.Errorf("Expected call to AuthMock.GeneratePasswordHash with params: %#v", *e.params)
- }
- }
- // if default expectation was set then invocations count should be greater than zero
- if m.GeneratePasswordHashMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGeneratePasswordHashCounter) < 1 {
- if m.GeneratePasswordHashMock.defaultExpectation.params == nil {
- m.t.Error("Expected call to AuthMock.GeneratePasswordHash")
- } else {
- m.t.Errorf("Expected call to AuthMock.GeneratePasswordHash with params: %#v", *m.GeneratePasswordHashMock.defaultExpectation.params)
- }
- }
- // if func was set then invocations count should be greater than zero
- if m.funcGeneratePasswordHash != nil && mm_atomic.LoadUint64(&m.afterGeneratePasswordHashCounter) < 1 {
- m.t.Error("Expected call to AuthMock.GeneratePasswordHash")
- }
- }
- type mAuthMockGenerateToken struct {
- mock *AuthMock
- defaultExpectation *AuthMockGenerateTokenExpectation
- expectations []*AuthMockGenerateTokenExpectation
- callArgs []*AuthMockGenerateTokenParams
- mutex sync.RWMutex
- }
- // AuthMockGenerateTokenExpectation specifies expectation struct of the Auth.GenerateToken
- type AuthMockGenerateTokenExpectation struct {
- mock *AuthMock
- params *AuthMockGenerateTokenParams
- results *AuthMockGenerateTokenResults
- Counter uint64
- }
- // AuthMockGenerateTokenParams contains parameters of the Auth.GenerateToken
- type AuthMockGenerateTokenParams struct {
- user models.User
- }
- // AuthMockGenerateTokenResults contains results of the Auth.GenerateToken
- type AuthMockGenerateTokenResults struct {
- s1 string
- err error
- }
- // Expect sets up expected params for Auth.GenerateToken
- func (mmGenerateToken *mAuthMockGenerateToken) Expect(user models.User) *mAuthMockGenerateToken {
- if mmGenerateToken.mock.funcGenerateToken != nil {
- mmGenerateToken.mock.t.Fatalf("AuthMock.GenerateToken mock is already set by Set")
- }
- if mmGenerateToken.defaultExpectation == nil {
- mmGenerateToken.defaultExpectation = &AuthMockGenerateTokenExpectation{}
- }
- mmGenerateToken.defaultExpectation.params = &AuthMockGenerateTokenParams{user}
- for _, e := range mmGenerateToken.expectations {
- if minimock.Equal(e.params, mmGenerateToken.defaultExpectation.params) {
- mmGenerateToken.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGenerateToken.defaultExpectation.params)
- }
- }
- return mmGenerateToken
- }
- // Inspect accepts an inspector function that has same arguments as the Auth.GenerateToken
- func (mmGenerateToken *mAuthMockGenerateToken) Inspect(f func(user models.User)) *mAuthMockGenerateToken {
- if mmGenerateToken.mock.inspectFuncGenerateToken != nil {
- mmGenerateToken.mock.t.Fatalf("Inspect function is already set for AuthMock.GenerateToken")
- }
- mmGenerateToken.mock.inspectFuncGenerateToken = f
- return mmGenerateToken
- }
- // Return sets up results that will be returned by Auth.GenerateToken
- func (mmGenerateToken *mAuthMockGenerateToken) Return(s1 string, err error) *AuthMock {
- if mmGenerateToken.mock.funcGenerateToken != nil {
- mmGenerateToken.mock.t.Fatalf("AuthMock.GenerateToken mock is already set by Set")
- }
- if mmGenerateToken.defaultExpectation == nil {
- mmGenerateToken.defaultExpectation = &AuthMockGenerateTokenExpectation{mock: mmGenerateToken.mock}
- }
- mmGenerateToken.defaultExpectation.results = &AuthMockGenerateTokenResults{s1, err}
- return mmGenerateToken.mock
- }
- // Set uses given function f to mock the Auth.GenerateToken method
- func (mmGenerateToken *mAuthMockGenerateToken) Set(f func(user models.User) (s1 string, err error)) *AuthMock {
- if mmGenerateToken.defaultExpectation != nil {
- mmGenerateToken.mock.t.Fatalf("Default expectation is already set for the Auth.GenerateToken method")
- }
- if len(mmGenerateToken.expectations) > 0 {
- mmGenerateToken.mock.t.Fatalf("Some expectations are already set for the Auth.GenerateToken method")
- }
- mmGenerateToken.mock.funcGenerateToken = f
- return mmGenerateToken.mock
- }
- // When sets expectation for the Auth.GenerateToken which will trigger the result defined by the following
- // Then helper
- func (mmGenerateToken *mAuthMockGenerateToken) When(user models.User) *AuthMockGenerateTokenExpectation {
- if mmGenerateToken.mock.funcGenerateToken != nil {
- mmGenerateToken.mock.t.Fatalf("AuthMock.GenerateToken mock is already set by Set")
- }
- expectation := &AuthMockGenerateTokenExpectation{
- mock: mmGenerateToken.mock,
- params: &AuthMockGenerateTokenParams{user},
- }
- mmGenerateToken.expectations = append(mmGenerateToken.expectations, expectation)
- return expectation
- }
- // Then sets up Auth.GenerateToken return parameters for the expectation previously defined by the When method
- func (e *AuthMockGenerateTokenExpectation) Then(s1 string, err error) *AuthMock {
- e.results = &AuthMockGenerateTokenResults{s1, err}
- return e.mock
- }
- // GenerateToken implements interfaces.Auth
- func (mmGenerateToken *AuthMock) GenerateToken(user models.User) (s1 string, err error) {
- mm_atomic.AddUint64(&mmGenerateToken.beforeGenerateTokenCounter, 1)
- defer mm_atomic.AddUint64(&mmGenerateToken.afterGenerateTokenCounter, 1)
- if mmGenerateToken.inspectFuncGenerateToken != nil {
- mmGenerateToken.inspectFuncGenerateToken(user)
- }
- mm_params := &AuthMockGenerateTokenParams{user}
- // Record call args
- mmGenerateToken.GenerateTokenMock.mutex.Lock()
- mmGenerateToken.GenerateTokenMock.callArgs = append(mmGenerateToken.GenerateTokenMock.callArgs, mm_params)
- mmGenerateToken.GenerateTokenMock.mutex.Unlock()
- for _, e := range mmGenerateToken.GenerateTokenMock.expectations {
- if minimock.Equal(e.params, mm_params) {
- mm_atomic.AddUint64(&e.Counter, 1)
- return e.results.s1, e.results.err
- }
- }
- if mmGenerateToken.GenerateTokenMock.defaultExpectation != nil {
- mm_atomic.AddUint64(&mmGenerateToken.GenerateTokenMock.defaultExpectation.Counter, 1)
- mm_want := mmGenerateToken.GenerateTokenMock.defaultExpectation.params
- mm_got := AuthMockGenerateTokenParams{user}
- if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
- mmGenerateToken.t.Errorf("AuthMock.GenerateToken got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
- }
- mm_results := mmGenerateToken.GenerateTokenMock.defaultExpectation.results
- if mm_results == nil {
- mmGenerateToken.t.Fatal("No results are set for the AuthMock.GenerateToken")
- }
- return (*mm_results).s1, (*mm_results).err
- }
- if mmGenerateToken.funcGenerateToken != nil {
- return mmGenerateToken.funcGenerateToken(user)
- }
- mmGenerateToken.t.Fatalf("Unexpected call to AuthMock.GenerateToken. %v", user)
- return
- }
- // GenerateTokenAfterCounter returns a count of finished AuthMock.GenerateToken invocations
- func (mmGenerateToken *AuthMock) GenerateTokenAfterCounter() uint64 {
- return mm_atomic.LoadUint64(&mmGenerateToken.afterGenerateTokenCounter)
- }
- // GenerateTokenBeforeCounter returns a count of AuthMock.GenerateToken invocations
- func (mmGenerateToken *AuthMock) GenerateTokenBeforeCounter() uint64 {
- return mm_atomic.LoadUint64(&mmGenerateToken.beforeGenerateTokenCounter)
- }
- // Calls returns a list of arguments used in each call to AuthMock.GenerateToken.
- // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
- func (mmGenerateToken *mAuthMockGenerateToken) Calls() []*AuthMockGenerateTokenParams {
- mmGenerateToken.mutex.RLock()
- argCopy := make([]*AuthMockGenerateTokenParams, len(mmGenerateToken.callArgs))
- copy(argCopy, mmGenerateToken.callArgs)
- mmGenerateToken.mutex.RUnlock()
- return argCopy
- }
- // MinimockGenerateTokenDone returns true if the count of the GenerateToken invocations corresponds
- // the number of defined expectations
- func (m *AuthMock) MinimockGenerateTokenDone() bool {
- for _, e := range m.GenerateTokenMock.expectations {
- if mm_atomic.LoadUint64(&e.Counter) < 1 {
- return false
- }
- }
- // if default expectation was set then invocations count should be greater than zero
- if m.GenerateTokenMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGenerateTokenCounter) < 1 {
- return false
- }
- // if func was set then invocations count should be greater than zero
- if m.funcGenerateToken != nil && mm_atomic.LoadUint64(&m.afterGenerateTokenCounter) < 1 {
- return false
- }
- return true
- }
- // MinimockGenerateTokenInspect logs each unmet expectation
- func (m *AuthMock) MinimockGenerateTokenInspect() {
- for _, e := range m.GenerateTokenMock.expectations {
- if mm_atomic.LoadUint64(&e.Counter) < 1 {
- m.t.Errorf("Expected call to AuthMock.GenerateToken with params: %#v", *e.params)
- }
- }
- // if default expectation was set then invocations count should be greater than zero
- if m.GenerateTokenMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGenerateTokenCounter) < 1 {
- if m.GenerateTokenMock.defaultExpectation.params == nil {
- m.t.Error("Expected call to AuthMock.GenerateToken")
- } else {
- m.t.Errorf("Expected call to AuthMock.GenerateToken with params: %#v", *m.GenerateTokenMock.defaultExpectation.params)
- }
- }
- // if func was set then invocations count should be greater than zero
- if m.funcGenerateToken != nil && mm_atomic.LoadUint64(&m.afterGenerateTokenCounter) < 1 {
- m.t.Error("Expected call to AuthMock.GenerateToken")
- }
- }
- type mAuthMockGetClaims struct {
- mock *AuthMock
- defaultExpectation *AuthMockGetClaimsExpectation
- expectations []*AuthMockGetClaimsExpectation
- callArgs []*AuthMockGetClaimsParams
- mutex sync.RWMutex
- }
- // AuthMockGetClaimsExpectation specifies expectation struct of the Auth.GetClaims
- type AuthMockGetClaimsExpectation struct {
- mock *AuthMock
- params *AuthMockGetClaimsParams
- results *AuthMockGetClaimsResults
- Counter uint64
- }
- // AuthMockGetClaimsParams contains parameters of the Auth.GetClaims
- type AuthMockGetClaimsParams struct {
- fctx *fiber.Ctx
- }
- // AuthMockGetClaimsResults contains results of the Auth.GetClaims
- type AuthMockGetClaimsResults struct {
- m1 jwt.MapClaims
- }
- // Expect sets up expected params for Auth.GetClaims
- func (mmGetClaims *mAuthMockGetClaims) Expect(fctx *fiber.Ctx) *mAuthMockGetClaims {
- if mmGetClaims.mock.funcGetClaims != nil {
- mmGetClaims.mock.t.Fatalf("AuthMock.GetClaims mock is already set by Set")
- }
- if mmGetClaims.defaultExpectation == nil {
- mmGetClaims.defaultExpectation = &AuthMockGetClaimsExpectation{}
- }
- mmGetClaims.defaultExpectation.params = &AuthMockGetClaimsParams{fctx}
- for _, e := range mmGetClaims.expectations {
- if minimock.Equal(e.params, mmGetClaims.defaultExpectation.params) {
- mmGetClaims.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetClaims.defaultExpectation.params)
- }
- }
- return mmGetClaims
- }
- // Inspect accepts an inspector function that has same arguments as the Auth.GetClaims
- func (mmGetClaims *mAuthMockGetClaims) Inspect(f func(fctx *fiber.Ctx)) *mAuthMockGetClaims {
- if mmGetClaims.mock.inspectFuncGetClaims != nil {
- mmGetClaims.mock.t.Fatalf("Inspect function is already set for AuthMock.GetClaims")
- }
- mmGetClaims.mock.inspectFuncGetClaims = f
- return mmGetClaims
- }
- // Return sets up results that will be returned by Auth.GetClaims
- func (mmGetClaims *mAuthMockGetClaims) Return(m1 jwt.MapClaims) *AuthMock {
- if mmGetClaims.mock.funcGetClaims != nil {
- mmGetClaims.mock.t.Fatalf("AuthMock.GetClaims mock is already set by Set")
- }
- if mmGetClaims.defaultExpectation == nil {
- mmGetClaims.defaultExpectation = &AuthMockGetClaimsExpectation{mock: mmGetClaims.mock}
- }
- mmGetClaims.defaultExpectation.results = &AuthMockGetClaimsResults{m1}
- return mmGetClaims.mock
- }
- // Set uses given function f to mock the Auth.GetClaims method
- func (mmGetClaims *mAuthMockGetClaims) Set(f func(fctx *fiber.Ctx) (m1 jwt.MapClaims)) *AuthMock {
- if mmGetClaims.defaultExpectation != nil {
- mmGetClaims.mock.t.Fatalf("Default expectation is already set for the Auth.GetClaims method")
- }
- if len(mmGetClaims.expectations) > 0 {
- mmGetClaims.mock.t.Fatalf("Some expectations are already set for the Auth.GetClaims method")
- }
- mmGetClaims.mock.funcGetClaims = f
- return mmGetClaims.mock
- }
- // When sets expectation for the Auth.GetClaims which will trigger the result defined by the following
- // Then helper
- func (mmGetClaims *mAuthMockGetClaims) When(fctx *fiber.Ctx) *AuthMockGetClaimsExpectation {
- if mmGetClaims.mock.funcGetClaims != nil {
- mmGetClaims.mock.t.Fatalf("AuthMock.GetClaims mock is already set by Set")
- }
- expectation := &AuthMockGetClaimsExpectation{
- mock: mmGetClaims.mock,
- params: &AuthMockGetClaimsParams{fctx},
- }
- mmGetClaims.expectations = append(mmGetClaims.expectations, expectation)
- return expectation
- }
- // Then sets up Auth.GetClaims return parameters for the expectation previously defined by the When method
- func (e *AuthMockGetClaimsExpectation) Then(m1 jwt.MapClaims) *AuthMock {
- e.results = &AuthMockGetClaimsResults{m1}
- return e.mock
- }
- // GetClaims implements interfaces.Auth
- func (mmGetClaims *AuthMock) GetClaims(fctx *fiber.Ctx) (m1 jwt.MapClaims) {
- mm_atomic.AddUint64(&mmGetClaims.beforeGetClaimsCounter, 1)
- defer mm_atomic.AddUint64(&mmGetClaims.afterGetClaimsCounter, 1)
- if mmGetClaims.inspectFuncGetClaims != nil {
- mmGetClaims.inspectFuncGetClaims(fctx)
- }
- mm_params := &AuthMockGetClaimsParams{fctx}
- // Record call args
- mmGetClaims.GetClaimsMock.mutex.Lock()
- mmGetClaims.GetClaimsMock.callArgs = append(mmGetClaims.GetClaimsMock.callArgs, mm_params)
- mmGetClaims.GetClaimsMock.mutex.Unlock()
- for _, e := range mmGetClaims.GetClaimsMock.expectations {
- if minimock.Equal(e.params, mm_params) {
- mm_atomic.AddUint64(&e.Counter, 1)
- return e.results.m1
- }
- }
- if mmGetClaims.GetClaimsMock.defaultExpectation != nil {
- mm_atomic.AddUint64(&mmGetClaims.GetClaimsMock.defaultExpectation.Counter, 1)
- mm_want := mmGetClaims.GetClaimsMock.defaultExpectation.params
- mm_got := AuthMockGetClaimsParams{fctx}
- if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
- mmGetClaims.t.Errorf("AuthMock.GetClaims got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
- }
- mm_results := mmGetClaims.GetClaimsMock.defaultExpectation.results
- if mm_results == nil {
- mmGetClaims.t.Fatal("No results are set for the AuthMock.GetClaims")
- }
- return (*mm_results).m1
- }
- if mmGetClaims.funcGetClaims != nil {
- return mmGetClaims.funcGetClaims(fctx)
- }
- mmGetClaims.t.Fatalf("Unexpected call to AuthMock.GetClaims. %v", fctx)
- return
- }
- // GetClaimsAfterCounter returns a count of finished AuthMock.GetClaims invocations
- func (mmGetClaims *AuthMock) GetClaimsAfterCounter() uint64 {
- return mm_atomic.LoadUint64(&mmGetClaims.afterGetClaimsCounter)
- }
- // GetClaimsBeforeCounter returns a count of AuthMock.GetClaims invocations
- func (mmGetClaims *AuthMock) GetClaimsBeforeCounter() uint64 {
- return mm_atomic.LoadUint64(&mmGetClaims.beforeGetClaimsCounter)
- }
- // Calls returns a list of arguments used in each call to AuthMock.GetClaims.
- // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
- func (mmGetClaims *mAuthMockGetClaims) Calls() []*AuthMockGetClaimsParams {
- mmGetClaims.mutex.RLock()
- argCopy := make([]*AuthMockGetClaimsParams, len(mmGetClaims.callArgs))
- copy(argCopy, mmGetClaims.callArgs)
- mmGetClaims.mutex.RUnlock()
- return argCopy
- }
- // MinimockGetClaimsDone returns true if the count of the GetClaims invocations corresponds
- // the number of defined expectations
- func (m *AuthMock) MinimockGetClaimsDone() bool {
- for _, e := range m.GetClaimsMock.expectations {
- if mm_atomic.LoadUint64(&e.Counter) < 1 {
- return false
- }
- }
- // if default expectation was set then invocations count should be greater than zero
- if m.GetClaimsMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGetClaimsCounter) < 1 {
- return false
- }
- // if func was set then invocations count should be greater than zero
- if m.funcGetClaims != nil && mm_atomic.LoadUint64(&m.afterGetClaimsCounter) < 1 {
- return false
- }
- return true
- }
- // MinimockGetClaimsInspect logs each unmet expectation
- func (m *AuthMock) MinimockGetClaimsInspect() {
- for _, e := range m.GetClaimsMock.expectations {
- if mm_atomic.LoadUint64(&e.Counter) < 1 {
- m.t.Errorf("Expected call to AuthMock.GetClaims with params: %#v", *e.params)
- }
- }
- // if default expectation was set then invocations count should be greater than zero
- if m.GetClaimsMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGetClaimsCounter) < 1 {
- if m.GetClaimsMock.defaultExpectation.params == nil {
- m.t.Error("Expected call to AuthMock.GetClaims")
- } else {
- m.t.Errorf("Expected call to AuthMock.GetClaims with params: %#v", *m.GetClaimsMock.defaultExpectation.params)
- }
- }
- // if func was set then invocations count should be greater than zero
- if m.funcGetClaims != nil && mm_atomic.LoadUint64(&m.afterGetClaimsCounter) < 1 {
- m.t.Error("Expected call to AuthMock.GetClaims")
- }
- }
- type mAuthMockIsCorrectPassword struct {
- mock *AuthMock
- defaultExpectation *AuthMockIsCorrectPasswordExpectation
- expectations []*AuthMockIsCorrectPasswordExpectation
- callArgs []*AuthMockIsCorrectPasswordParams
- mutex sync.RWMutex
- }
- // AuthMockIsCorrectPasswordExpectation specifies expectation struct of the Auth.IsCorrectPassword
- type AuthMockIsCorrectPasswordExpectation struct {
- mock *AuthMock
- params *AuthMockIsCorrectPasswordParams
- results *AuthMockIsCorrectPasswordResults
- Counter uint64
- }
- // AuthMockIsCorrectPasswordParams contains parameters of the Auth.IsCorrectPassword
- type AuthMockIsCorrectPasswordParams struct {
- password string
- hash string
- }
- // AuthMockIsCorrectPasswordResults contains results of the Auth.IsCorrectPassword
- type AuthMockIsCorrectPasswordResults struct {
- b1 bool
- }
- // Expect sets up expected params for Auth.IsCorrectPassword
- func (mmIsCorrectPassword *mAuthMockIsCorrectPassword) Expect(password string, hash string) *mAuthMockIsCorrectPassword {
- if mmIsCorrectPassword.mock.funcIsCorrectPassword != nil {
- mmIsCorrectPassword.mock.t.Fatalf("AuthMock.IsCorrectPassword mock is already set by Set")
- }
- if mmIsCorrectPassword.defaultExpectation == nil {
- mmIsCorrectPassword.defaultExpectation = &AuthMockIsCorrectPasswordExpectation{}
- }
- mmIsCorrectPassword.defaultExpectation.params = &AuthMockIsCorrectPasswordParams{password, hash}
- for _, e := range mmIsCorrectPassword.expectations {
- if minimock.Equal(e.params, mmIsCorrectPassword.defaultExpectation.params) {
- mmIsCorrectPassword.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmIsCorrectPassword.defaultExpectation.params)
- }
- }
- return mmIsCorrectPassword
- }
- // Inspect accepts an inspector function that has same arguments as the Auth.IsCorrectPassword
- func (mmIsCorrectPassword *mAuthMockIsCorrectPassword) Inspect(f func(password string, hash string)) *mAuthMockIsCorrectPassword {
- if mmIsCorrectPassword.mock.inspectFuncIsCorrectPassword != nil {
- mmIsCorrectPassword.mock.t.Fatalf("Inspect function is already set for AuthMock.IsCorrectPassword")
- }
- mmIsCorrectPassword.mock.inspectFuncIsCorrectPassword = f
- return mmIsCorrectPassword
- }
- // Return sets up results that will be returned by Auth.IsCorrectPassword
- func (mmIsCorrectPassword *mAuthMockIsCorrectPassword) Return(b1 bool) *AuthMock {
- if mmIsCorrectPassword.mock.funcIsCorrectPassword != nil {
- mmIsCorrectPassword.mock.t.Fatalf("AuthMock.IsCorrectPassword mock is already set by Set")
- }
- if mmIsCorrectPassword.defaultExpectation == nil {
- mmIsCorrectPassword.defaultExpectation = &AuthMockIsCorrectPasswordExpectation{mock: mmIsCorrectPassword.mock}
- }
- mmIsCorrectPassword.defaultExpectation.results = &AuthMockIsCorrectPasswordResults{b1}
- return mmIsCorrectPassword.mock
- }
- // Set uses given function f to mock the Auth.IsCorrectPassword method
- func (mmIsCorrectPassword *mAuthMockIsCorrectPassword) Set(f func(password string, hash string) (b1 bool)) *AuthMock {
- if mmIsCorrectPassword.defaultExpectation != nil {
- mmIsCorrectPassword.mock.t.Fatalf("Default expectation is already set for the Auth.IsCorrectPassword method")
- }
- if len(mmIsCorrectPassword.expectations) > 0 {
- mmIsCorrectPassword.mock.t.Fatalf("Some expectations are already set for the Auth.IsCorrectPassword method")
- }
- mmIsCorrectPassword.mock.funcIsCorrectPassword = f
- return mmIsCorrectPassword.mock
- }
- // When sets expectation for the Auth.IsCorrectPassword which will trigger the result defined by the following
- // Then helper
- func (mmIsCorrectPassword *mAuthMockIsCorrectPassword) When(password string, hash string) *AuthMockIsCorrectPasswordExpectation {
- if mmIsCorrectPassword.mock.funcIsCorrectPassword != nil {
- mmIsCorrectPassword.mock.t.Fatalf("AuthMock.IsCorrectPassword mock is already set by Set")
- }
- expectation := &AuthMockIsCorrectPasswordExpectation{
- mock: mmIsCorrectPassword.mock,
- params: &AuthMockIsCorrectPasswordParams{password, hash},
- }
- mmIsCorrectPassword.expectations = append(mmIsCorrectPassword.expectations, expectation)
- return expectation
- }
- // Then sets up Auth.IsCorrectPassword return parameters for the expectation previously defined by the When method
- func (e *AuthMockIsCorrectPasswordExpectation) Then(b1 bool) *AuthMock {
- e.results = &AuthMockIsCorrectPasswordResults{b1}
- return e.mock
- }
- // IsCorrectPassword implements interfaces.Auth
- func (mmIsCorrectPassword *AuthMock) IsCorrectPassword(password string, hash string) (b1 bool) {
- mm_atomic.AddUint64(&mmIsCorrectPassword.beforeIsCorrectPasswordCounter, 1)
- defer mm_atomic.AddUint64(&mmIsCorrectPassword.afterIsCorrectPasswordCounter, 1)
- if mmIsCorrectPassword.inspectFuncIsCorrectPassword != nil {
- mmIsCorrectPassword.inspectFuncIsCorrectPassword(password, hash)
- }
- mm_params := &AuthMockIsCorrectPasswordParams{password, hash}
- // Record call args
- mmIsCorrectPassword.IsCorrectPasswordMock.mutex.Lock()
- mmIsCorrectPassword.IsCorrectPasswordMock.callArgs = append(mmIsCorrectPassword.IsCorrectPasswordMock.callArgs, mm_params)
- mmIsCorrectPassword.IsCorrectPasswordMock.mutex.Unlock()
- for _, e := range mmIsCorrectPassword.IsCorrectPasswordMock.expectations {
- if minimock.Equal(e.params, mm_params) {
- mm_atomic.AddUint64(&e.Counter, 1)
- return e.results.b1
- }
- }
- if mmIsCorrectPassword.IsCorrectPasswordMock.defaultExpectation != nil {
- mm_atomic.AddUint64(&mmIsCorrectPassword.IsCorrectPasswordMock.defaultExpectation.Counter, 1)
- mm_want := mmIsCorrectPassword.IsCorrectPasswordMock.defaultExpectation.params
- mm_got := AuthMockIsCorrectPasswordParams{password, hash}
- if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
- mmIsCorrectPassword.t.Errorf("AuthMock.IsCorrectPassword got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
- }
- mm_results := mmIsCorrectPassword.IsCorrectPasswordMock.defaultExpectation.results
- if mm_results == nil {
- mmIsCorrectPassword.t.Fatal("No results are set for the AuthMock.IsCorrectPassword")
- }
- return (*mm_results).b1
- }
- if mmIsCorrectPassword.funcIsCorrectPassword != nil {
- return mmIsCorrectPassword.funcIsCorrectPassword(password, hash)
- }
- mmIsCorrectPassword.t.Fatalf("Unexpected call to AuthMock.IsCorrectPassword. %v %v", password, hash)
- return
- }
- // IsCorrectPasswordAfterCounter returns a count of finished AuthMock.IsCorrectPassword invocations
- func (mmIsCorrectPassword *AuthMock) IsCorrectPasswordAfterCounter() uint64 {
- return mm_atomic.LoadUint64(&mmIsCorrectPassword.afterIsCorrectPasswordCounter)
- }
- // IsCorrectPasswordBeforeCounter returns a count of AuthMock.IsCorrectPassword invocations
- func (mmIsCorrectPassword *AuthMock) IsCorrectPasswordBeforeCounter() uint64 {
- return mm_atomic.LoadUint64(&mmIsCorrectPassword.beforeIsCorrectPasswordCounter)
- }
- // Calls returns a list of arguments used in each call to AuthMock.IsCorrectPassword.
- // The list is in the same order as the calls were made (i.e. recent calls have a higher index)
- func (mmIsCorrectPassword *mAuthMockIsCorrectPassword) Calls() []*AuthMockIsCorrectPasswordParams {
- mmIsCorrectPassword.mutex.RLock()
- argCopy := make([]*AuthMockIsCorrectPasswordParams, len(mmIsCorrectPassword.callArgs))
- copy(argCopy, mmIsCorrectPassword.callArgs)
- mmIsCorrectPassword.mutex.RUnlock()
- return argCopy
- }
- // MinimockIsCorrectPasswordDone returns true if the count of the IsCorrectPassword invocations corresponds
- // the number of defined expectations
- func (m *AuthMock) MinimockIsCorrectPasswordDone() bool {
- for _, e := range m.IsCorrectPasswordMock.expectations {
- if mm_atomic.LoadUint64(&e.Counter) < 1 {
- return false
- }
- }
- // if default expectation was set then invocations count should be greater than zero
- if m.IsCorrectPasswordMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterIsCorrectPasswordCounter) < 1 {
- return false
- }
- // if func was set then invocations count should be greater than zero
- if m.funcIsCorrectPassword != nil && mm_atomic.LoadUint64(&m.afterIsCorrectPasswordCounter) < 1 {
- return false
- }
- return true
- }
- // MinimockIsCorrectPasswordInspect logs each unmet expectation
- func (m *AuthMock) MinimockIsCorrectPasswordInspect() {
- for _, e := range m.IsCorrectPasswordMock.expectations {
- if mm_atomic.LoadUint64(&e.Counter) < 1 {
- m.t.Errorf("Expected call to AuthMock.IsCorrectPassword with params: %#v", *e.params)
- }
- }
- // if default expectation was set then invocations count should be greater than zero
- if m.IsCorrectPasswordMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterIsCorrectPasswordCounter) < 1 {
- if m.IsCorrectPasswordMock.defaultExpectation.params == nil {
- m.t.Error("Expected call to AuthMock.IsCorrectPassword")
- } else {
- m.t.Errorf("Expected call to AuthMock.IsCorrectPassword with params: %#v", *m.IsCorrectPasswordMock.defaultExpectation.params)
- }
- }
- // if func was set then invocations count should be greater than zero
- if m.funcIsCorrectPassword != nil && mm_atomic.LoadUint64(&m.afterIsCorrectPasswordCounter) < 1 {
- m.t.Error("Expected call to AuthMock.IsCorrectPassword")
- }
- }
- // MinimockFinish checks that all mocked methods have been called the expected number of times
- func (m *AuthMock) MinimockFinish() {
- if !m.minimockDone() {
- m.MinimockGeneratePasswordHashInspect()
- m.MinimockGenerateTokenInspect()
- m.MinimockGetClaimsInspect()
- m.MinimockIsCorrectPasswordInspect()
- m.t.FailNow()
- }
- }
- // MinimockWait waits for all mocked methods to be called the expected number of times
- func (m *AuthMock) MinimockWait(timeout mm_time.Duration) {
- timeoutCh := mm_time.After(timeout)
- for {
- if m.minimockDone() {
- return
- }
- select {
- case <-timeoutCh:
- m.MinimockFinish()
- return
- case <-mm_time.After(10 * mm_time.Millisecond):
- }
- }
- }
- func (m *AuthMock) minimockDone() bool {
- done := true
- return done &&
- m.MinimockGeneratePasswordHashDone() &&
- m.MinimockGenerateTokenDone() &&
- m.MinimockGetClaimsDone() &&
- m.MinimockIsCorrectPasswordDone()
- }
|