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() }