// Code generated by http://github.com/gojuno/minimock (v3.3.13). DO NOT EDIT. package mocks //go:generate minimock -i git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/auth.AuthService -o auth_service_minimock.go -n AuthServiceMock -p mocks 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" ) // AuthServiceMock implements auth.AuthService type AuthServiceMock struct { t minimock.Tester finishOnce sync.Once funcGenerateToken func(user models.User) (s1 string, err error) inspectFuncGenerateToken func(user models.User) afterGenerateTokenCounter uint64 beforeGenerateTokenCounter uint64 GenerateTokenMock mAuthServiceMockGenerateToken funcGetClaims func(fctx *fiber.Ctx) (m1 jwt.MapClaims) inspectFuncGetClaims func(fctx *fiber.Ctx) afterGetClaimsCounter uint64 beforeGetClaimsCounter uint64 GetClaimsMock mAuthServiceMockGetClaims funcIsCorrectPassword func(password string, hash string) (b1 bool) inspectFuncIsCorrectPassword func(password string, hash string) afterIsCorrectPasswordCounter uint64 beforeIsCorrectPasswordCounter uint64 IsCorrectPasswordMock mAuthServiceMockIsCorrectPassword } // NewAuthServiceMock returns a mock for auth.AuthService func NewAuthServiceMock(t minimock.Tester) *AuthServiceMock { m := &AuthServiceMock{t: t} if controller, ok := t.(minimock.MockController); ok { controller.RegisterMocker(m) } m.GenerateTokenMock = mAuthServiceMockGenerateToken{mock: m} m.GenerateTokenMock.callArgs = []*AuthServiceMockGenerateTokenParams{} m.GetClaimsMock = mAuthServiceMockGetClaims{mock: m} m.GetClaimsMock.callArgs = []*AuthServiceMockGetClaimsParams{} m.IsCorrectPasswordMock = mAuthServiceMockIsCorrectPassword{mock: m} m.IsCorrectPasswordMock.callArgs = []*AuthServiceMockIsCorrectPasswordParams{} t.Cleanup(m.MinimockFinish) return m } type mAuthServiceMockGenerateToken struct { optional bool mock *AuthServiceMock defaultExpectation *AuthServiceMockGenerateTokenExpectation expectations []*AuthServiceMockGenerateTokenExpectation callArgs []*AuthServiceMockGenerateTokenParams mutex sync.RWMutex expectedInvocations uint64 } // AuthServiceMockGenerateTokenExpectation specifies expectation struct of the AuthService.GenerateToken type AuthServiceMockGenerateTokenExpectation struct { mock *AuthServiceMock params *AuthServiceMockGenerateTokenParams paramPtrs *AuthServiceMockGenerateTokenParamPtrs results *AuthServiceMockGenerateTokenResults Counter uint64 } // AuthServiceMockGenerateTokenParams contains parameters of the AuthService.GenerateToken type AuthServiceMockGenerateTokenParams struct { user models.User } // AuthServiceMockGenerateTokenParamPtrs contains pointers to parameters of the AuthService.GenerateToken type AuthServiceMockGenerateTokenParamPtrs struct { user *models.User } // AuthServiceMockGenerateTokenResults contains results of the AuthService.GenerateToken type AuthServiceMockGenerateTokenResults struct { s1 string err error } // Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning // the test will fail minimock's automatic final call check if the mocked method was not called at least once. // Optional() makes method check to work in '0 or more' mode. // It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to // catch the problems when the expected method call is totally skipped during test run. func (mmGenerateToken *mAuthServiceMockGenerateToken) Optional() *mAuthServiceMockGenerateToken { mmGenerateToken.optional = true return mmGenerateToken } // Expect sets up expected params for AuthService.GenerateToken func (mmGenerateToken *mAuthServiceMockGenerateToken) Expect(user models.User) *mAuthServiceMockGenerateToken { if mmGenerateToken.mock.funcGenerateToken != nil { mmGenerateToken.mock.t.Fatalf("AuthServiceMock.GenerateToken mock is already set by Set") } if mmGenerateToken.defaultExpectation == nil { mmGenerateToken.defaultExpectation = &AuthServiceMockGenerateTokenExpectation{} } if mmGenerateToken.defaultExpectation.paramPtrs != nil { mmGenerateToken.mock.t.Fatalf("AuthServiceMock.GenerateToken mock is already set by ExpectParams functions") } mmGenerateToken.defaultExpectation.params = &AuthServiceMockGenerateTokenParams{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 } // ExpectUserParam1 sets up expected param user for AuthService.GenerateToken func (mmGenerateToken *mAuthServiceMockGenerateToken) ExpectUserParam1(user models.User) *mAuthServiceMockGenerateToken { if mmGenerateToken.mock.funcGenerateToken != nil { mmGenerateToken.mock.t.Fatalf("AuthServiceMock.GenerateToken mock is already set by Set") } if mmGenerateToken.defaultExpectation == nil { mmGenerateToken.defaultExpectation = &AuthServiceMockGenerateTokenExpectation{} } if mmGenerateToken.defaultExpectation.params != nil { mmGenerateToken.mock.t.Fatalf("AuthServiceMock.GenerateToken mock is already set by Expect") } if mmGenerateToken.defaultExpectation.paramPtrs == nil { mmGenerateToken.defaultExpectation.paramPtrs = &AuthServiceMockGenerateTokenParamPtrs{} } mmGenerateToken.defaultExpectation.paramPtrs.user = &user return mmGenerateToken } // Inspect accepts an inspector function that has same arguments as the AuthService.GenerateToken func (mmGenerateToken *mAuthServiceMockGenerateToken) Inspect(f func(user models.User)) *mAuthServiceMockGenerateToken { if mmGenerateToken.mock.inspectFuncGenerateToken != nil { mmGenerateToken.mock.t.Fatalf("Inspect function is already set for AuthServiceMock.GenerateToken") } mmGenerateToken.mock.inspectFuncGenerateToken = f return mmGenerateToken } // Return sets up results that will be returned by AuthService.GenerateToken func (mmGenerateToken *mAuthServiceMockGenerateToken) Return(s1 string, err error) *AuthServiceMock { if mmGenerateToken.mock.funcGenerateToken != nil { mmGenerateToken.mock.t.Fatalf("AuthServiceMock.GenerateToken mock is already set by Set") } if mmGenerateToken.defaultExpectation == nil { mmGenerateToken.defaultExpectation = &AuthServiceMockGenerateTokenExpectation{mock: mmGenerateToken.mock} } mmGenerateToken.defaultExpectation.results = &AuthServiceMockGenerateTokenResults{s1, err} return mmGenerateToken.mock } // Set uses given function f to mock the AuthService.GenerateToken method func (mmGenerateToken *mAuthServiceMockGenerateToken) Set(f func(user models.User) (s1 string, err error)) *AuthServiceMock { if mmGenerateToken.defaultExpectation != nil { mmGenerateToken.mock.t.Fatalf("Default expectation is already set for the AuthService.GenerateToken method") } if len(mmGenerateToken.expectations) > 0 { mmGenerateToken.mock.t.Fatalf("Some expectations are already set for the AuthService.GenerateToken method") } mmGenerateToken.mock.funcGenerateToken = f return mmGenerateToken.mock } // When sets expectation for the AuthService.GenerateToken which will trigger the result defined by the following // Then helper func (mmGenerateToken *mAuthServiceMockGenerateToken) When(user models.User) *AuthServiceMockGenerateTokenExpectation { if mmGenerateToken.mock.funcGenerateToken != nil { mmGenerateToken.mock.t.Fatalf("AuthServiceMock.GenerateToken mock is already set by Set") } expectation := &AuthServiceMockGenerateTokenExpectation{ mock: mmGenerateToken.mock, params: &AuthServiceMockGenerateTokenParams{user}, } mmGenerateToken.expectations = append(mmGenerateToken.expectations, expectation) return expectation } // Then sets up AuthService.GenerateToken return parameters for the expectation previously defined by the When method func (e *AuthServiceMockGenerateTokenExpectation) Then(s1 string, err error) *AuthServiceMock { e.results = &AuthServiceMockGenerateTokenResults{s1, err} return e.mock } // Times sets number of times AuthService.GenerateToken should be invoked func (mmGenerateToken *mAuthServiceMockGenerateToken) Times(n uint64) *mAuthServiceMockGenerateToken { if n == 0 { mmGenerateToken.mock.t.Fatalf("Times of AuthServiceMock.GenerateToken mock can not be zero") } mm_atomic.StoreUint64(&mmGenerateToken.expectedInvocations, n) return mmGenerateToken } func (mmGenerateToken *mAuthServiceMockGenerateToken) invocationsDone() bool { if len(mmGenerateToken.expectations) == 0 && mmGenerateToken.defaultExpectation == nil && mmGenerateToken.mock.funcGenerateToken == nil { return true } totalInvocations := mm_atomic.LoadUint64(&mmGenerateToken.mock.afterGenerateTokenCounter) expectedInvocations := mm_atomic.LoadUint64(&mmGenerateToken.expectedInvocations) return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) } // GenerateToken implements auth.AuthService func (mmGenerateToken *AuthServiceMock) 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 := AuthServiceMockGenerateTokenParams{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_want_ptrs := mmGenerateToken.GenerateTokenMock.defaultExpectation.paramPtrs mm_got := AuthServiceMockGenerateTokenParams{user} if mm_want_ptrs != nil { if mm_want_ptrs.user != nil && !minimock.Equal(*mm_want_ptrs.user, mm_got.user) { mmGenerateToken.t.Errorf("AuthServiceMock.GenerateToken got unexpected parameter user, want: %#v, got: %#v%s\n", *mm_want_ptrs.user, mm_got.user, minimock.Diff(*mm_want_ptrs.user, mm_got.user)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmGenerateToken.t.Errorf("AuthServiceMock.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 AuthServiceMock.GenerateToken") } return (*mm_results).s1, (*mm_results).err } if mmGenerateToken.funcGenerateToken != nil { return mmGenerateToken.funcGenerateToken(user) } mmGenerateToken.t.Fatalf("Unexpected call to AuthServiceMock.GenerateToken. %v", user) return } // GenerateTokenAfterCounter returns a count of finished AuthServiceMock.GenerateToken invocations func (mmGenerateToken *AuthServiceMock) GenerateTokenAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmGenerateToken.afterGenerateTokenCounter) } // GenerateTokenBeforeCounter returns a count of AuthServiceMock.GenerateToken invocations func (mmGenerateToken *AuthServiceMock) GenerateTokenBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmGenerateToken.beforeGenerateTokenCounter) } // Calls returns a list of arguments used in each call to AuthServiceMock.GenerateToken. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmGenerateToken *mAuthServiceMockGenerateToken) Calls() []*AuthServiceMockGenerateTokenParams { mmGenerateToken.mutex.RLock() argCopy := make([]*AuthServiceMockGenerateTokenParams, 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 *AuthServiceMock) MinimockGenerateTokenDone() bool { if m.GenerateTokenMock.optional { // Optional methods provide '0 or more' call count restriction. return true } for _, e := range m.GenerateTokenMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } return m.GenerateTokenMock.invocationsDone() } // MinimockGenerateTokenInspect logs each unmet expectation func (m *AuthServiceMock) MinimockGenerateTokenInspect() { for _, e := range m.GenerateTokenMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to AuthServiceMock.GenerateToken with params: %#v", *e.params) } } afterGenerateTokenCounter := mm_atomic.LoadUint64(&m.afterGenerateTokenCounter) // if default expectation was set then invocations count should be greater than zero if m.GenerateTokenMock.defaultExpectation != nil && afterGenerateTokenCounter < 1 { if m.GenerateTokenMock.defaultExpectation.params == nil { m.t.Error("Expected call to AuthServiceMock.GenerateToken") } else { m.t.Errorf("Expected call to AuthServiceMock.GenerateToken with params: %#v", *m.GenerateTokenMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcGenerateToken != nil && afterGenerateTokenCounter < 1 { m.t.Error("Expected call to AuthServiceMock.GenerateToken") } if !m.GenerateTokenMock.invocationsDone() && afterGenerateTokenCounter > 0 { m.t.Errorf("Expected %d calls to AuthServiceMock.GenerateToken but found %d calls", mm_atomic.LoadUint64(&m.GenerateTokenMock.expectedInvocations), afterGenerateTokenCounter) } } type mAuthServiceMockGetClaims struct { optional bool mock *AuthServiceMock defaultExpectation *AuthServiceMockGetClaimsExpectation expectations []*AuthServiceMockGetClaimsExpectation callArgs []*AuthServiceMockGetClaimsParams mutex sync.RWMutex expectedInvocations uint64 } // AuthServiceMockGetClaimsExpectation specifies expectation struct of the AuthService.GetClaims type AuthServiceMockGetClaimsExpectation struct { mock *AuthServiceMock params *AuthServiceMockGetClaimsParams paramPtrs *AuthServiceMockGetClaimsParamPtrs results *AuthServiceMockGetClaimsResults Counter uint64 } // AuthServiceMockGetClaimsParams contains parameters of the AuthService.GetClaims type AuthServiceMockGetClaimsParams struct { fctx *fiber.Ctx } // AuthServiceMockGetClaimsParamPtrs contains pointers to parameters of the AuthService.GetClaims type AuthServiceMockGetClaimsParamPtrs struct { fctx **fiber.Ctx } // AuthServiceMockGetClaimsResults contains results of the AuthService.GetClaims type AuthServiceMockGetClaimsResults struct { m1 jwt.MapClaims } // Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning // the test will fail minimock's automatic final call check if the mocked method was not called at least once. // Optional() makes method check to work in '0 or more' mode. // It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to // catch the problems when the expected method call is totally skipped during test run. func (mmGetClaims *mAuthServiceMockGetClaims) Optional() *mAuthServiceMockGetClaims { mmGetClaims.optional = true return mmGetClaims } // Expect sets up expected params for AuthService.GetClaims func (mmGetClaims *mAuthServiceMockGetClaims) Expect(fctx *fiber.Ctx) *mAuthServiceMockGetClaims { if mmGetClaims.mock.funcGetClaims != nil { mmGetClaims.mock.t.Fatalf("AuthServiceMock.GetClaims mock is already set by Set") } if mmGetClaims.defaultExpectation == nil { mmGetClaims.defaultExpectation = &AuthServiceMockGetClaimsExpectation{} } if mmGetClaims.defaultExpectation.paramPtrs != nil { mmGetClaims.mock.t.Fatalf("AuthServiceMock.GetClaims mock is already set by ExpectParams functions") } mmGetClaims.defaultExpectation.params = &AuthServiceMockGetClaimsParams{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 } // ExpectFctxParam1 sets up expected param fctx for AuthService.GetClaims func (mmGetClaims *mAuthServiceMockGetClaims) ExpectFctxParam1(fctx *fiber.Ctx) *mAuthServiceMockGetClaims { if mmGetClaims.mock.funcGetClaims != nil { mmGetClaims.mock.t.Fatalf("AuthServiceMock.GetClaims mock is already set by Set") } if mmGetClaims.defaultExpectation == nil { mmGetClaims.defaultExpectation = &AuthServiceMockGetClaimsExpectation{} } if mmGetClaims.defaultExpectation.params != nil { mmGetClaims.mock.t.Fatalf("AuthServiceMock.GetClaims mock is already set by Expect") } if mmGetClaims.defaultExpectation.paramPtrs == nil { mmGetClaims.defaultExpectation.paramPtrs = &AuthServiceMockGetClaimsParamPtrs{} } mmGetClaims.defaultExpectation.paramPtrs.fctx = &fctx return mmGetClaims } // Inspect accepts an inspector function that has same arguments as the AuthService.GetClaims func (mmGetClaims *mAuthServiceMockGetClaims) Inspect(f func(fctx *fiber.Ctx)) *mAuthServiceMockGetClaims { if mmGetClaims.mock.inspectFuncGetClaims != nil { mmGetClaims.mock.t.Fatalf("Inspect function is already set for AuthServiceMock.GetClaims") } mmGetClaims.mock.inspectFuncGetClaims = f return mmGetClaims } // Return sets up results that will be returned by AuthService.GetClaims func (mmGetClaims *mAuthServiceMockGetClaims) Return(m1 jwt.MapClaims) *AuthServiceMock { if mmGetClaims.mock.funcGetClaims != nil { mmGetClaims.mock.t.Fatalf("AuthServiceMock.GetClaims mock is already set by Set") } if mmGetClaims.defaultExpectation == nil { mmGetClaims.defaultExpectation = &AuthServiceMockGetClaimsExpectation{mock: mmGetClaims.mock} } mmGetClaims.defaultExpectation.results = &AuthServiceMockGetClaimsResults{m1} return mmGetClaims.mock } // Set uses given function f to mock the AuthService.GetClaims method func (mmGetClaims *mAuthServiceMockGetClaims) Set(f func(fctx *fiber.Ctx) (m1 jwt.MapClaims)) *AuthServiceMock { if mmGetClaims.defaultExpectation != nil { mmGetClaims.mock.t.Fatalf("Default expectation is already set for the AuthService.GetClaims method") } if len(mmGetClaims.expectations) > 0 { mmGetClaims.mock.t.Fatalf("Some expectations are already set for the AuthService.GetClaims method") } mmGetClaims.mock.funcGetClaims = f return mmGetClaims.mock } // When sets expectation for the AuthService.GetClaims which will trigger the result defined by the following // Then helper func (mmGetClaims *mAuthServiceMockGetClaims) When(fctx *fiber.Ctx) *AuthServiceMockGetClaimsExpectation { if mmGetClaims.mock.funcGetClaims != nil { mmGetClaims.mock.t.Fatalf("AuthServiceMock.GetClaims mock is already set by Set") } expectation := &AuthServiceMockGetClaimsExpectation{ mock: mmGetClaims.mock, params: &AuthServiceMockGetClaimsParams{fctx}, } mmGetClaims.expectations = append(mmGetClaims.expectations, expectation) return expectation } // Then sets up AuthService.GetClaims return parameters for the expectation previously defined by the When method func (e *AuthServiceMockGetClaimsExpectation) Then(m1 jwt.MapClaims) *AuthServiceMock { e.results = &AuthServiceMockGetClaimsResults{m1} return e.mock } // Times sets number of times AuthService.GetClaims should be invoked func (mmGetClaims *mAuthServiceMockGetClaims) Times(n uint64) *mAuthServiceMockGetClaims { if n == 0 { mmGetClaims.mock.t.Fatalf("Times of AuthServiceMock.GetClaims mock can not be zero") } mm_atomic.StoreUint64(&mmGetClaims.expectedInvocations, n) return mmGetClaims } func (mmGetClaims *mAuthServiceMockGetClaims) invocationsDone() bool { if len(mmGetClaims.expectations) == 0 && mmGetClaims.defaultExpectation == nil && mmGetClaims.mock.funcGetClaims == nil { return true } totalInvocations := mm_atomic.LoadUint64(&mmGetClaims.mock.afterGetClaimsCounter) expectedInvocations := mm_atomic.LoadUint64(&mmGetClaims.expectedInvocations) return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) } // GetClaims implements auth.AuthService func (mmGetClaims *AuthServiceMock) 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 := AuthServiceMockGetClaimsParams{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_want_ptrs := mmGetClaims.GetClaimsMock.defaultExpectation.paramPtrs mm_got := AuthServiceMockGetClaimsParams{fctx} if mm_want_ptrs != nil { if mm_want_ptrs.fctx != nil && !minimock.Equal(*mm_want_ptrs.fctx, mm_got.fctx) { mmGetClaims.t.Errorf("AuthServiceMock.GetClaims got unexpected parameter fctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.fctx, mm_got.fctx, minimock.Diff(*mm_want_ptrs.fctx, mm_got.fctx)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmGetClaims.t.Errorf("AuthServiceMock.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 AuthServiceMock.GetClaims") } return (*mm_results).m1 } if mmGetClaims.funcGetClaims != nil { return mmGetClaims.funcGetClaims(fctx) } mmGetClaims.t.Fatalf("Unexpected call to AuthServiceMock.GetClaims. %v", fctx) return } // GetClaimsAfterCounter returns a count of finished AuthServiceMock.GetClaims invocations func (mmGetClaims *AuthServiceMock) GetClaimsAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmGetClaims.afterGetClaimsCounter) } // GetClaimsBeforeCounter returns a count of AuthServiceMock.GetClaims invocations func (mmGetClaims *AuthServiceMock) GetClaimsBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmGetClaims.beforeGetClaimsCounter) } // Calls returns a list of arguments used in each call to AuthServiceMock.GetClaims. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmGetClaims *mAuthServiceMockGetClaims) Calls() []*AuthServiceMockGetClaimsParams { mmGetClaims.mutex.RLock() argCopy := make([]*AuthServiceMockGetClaimsParams, 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 *AuthServiceMock) MinimockGetClaimsDone() bool { if m.GetClaimsMock.optional { // Optional methods provide '0 or more' call count restriction. return true } for _, e := range m.GetClaimsMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } return m.GetClaimsMock.invocationsDone() } // MinimockGetClaimsInspect logs each unmet expectation func (m *AuthServiceMock) MinimockGetClaimsInspect() { for _, e := range m.GetClaimsMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to AuthServiceMock.GetClaims with params: %#v", *e.params) } } afterGetClaimsCounter := mm_atomic.LoadUint64(&m.afterGetClaimsCounter) // if default expectation was set then invocations count should be greater than zero if m.GetClaimsMock.defaultExpectation != nil && afterGetClaimsCounter < 1 { if m.GetClaimsMock.defaultExpectation.params == nil { m.t.Error("Expected call to AuthServiceMock.GetClaims") } else { m.t.Errorf("Expected call to AuthServiceMock.GetClaims with params: %#v", *m.GetClaimsMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcGetClaims != nil && afterGetClaimsCounter < 1 { m.t.Error("Expected call to AuthServiceMock.GetClaims") } if !m.GetClaimsMock.invocationsDone() && afterGetClaimsCounter > 0 { m.t.Errorf("Expected %d calls to AuthServiceMock.GetClaims but found %d calls", mm_atomic.LoadUint64(&m.GetClaimsMock.expectedInvocations), afterGetClaimsCounter) } } type mAuthServiceMockIsCorrectPassword struct { optional bool mock *AuthServiceMock defaultExpectation *AuthServiceMockIsCorrectPasswordExpectation expectations []*AuthServiceMockIsCorrectPasswordExpectation callArgs []*AuthServiceMockIsCorrectPasswordParams mutex sync.RWMutex expectedInvocations uint64 } // AuthServiceMockIsCorrectPasswordExpectation specifies expectation struct of the AuthService.IsCorrectPassword type AuthServiceMockIsCorrectPasswordExpectation struct { mock *AuthServiceMock params *AuthServiceMockIsCorrectPasswordParams paramPtrs *AuthServiceMockIsCorrectPasswordParamPtrs results *AuthServiceMockIsCorrectPasswordResults Counter uint64 } // AuthServiceMockIsCorrectPasswordParams contains parameters of the AuthService.IsCorrectPassword type AuthServiceMockIsCorrectPasswordParams struct { password string hash string } // AuthServiceMockIsCorrectPasswordParamPtrs contains pointers to parameters of the AuthService.IsCorrectPassword type AuthServiceMockIsCorrectPasswordParamPtrs struct { password *string hash *string } // AuthServiceMockIsCorrectPasswordResults contains results of the AuthService.IsCorrectPassword type AuthServiceMockIsCorrectPasswordResults struct { b1 bool } // Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning // the test will fail minimock's automatic final call check if the mocked method was not called at least once. // Optional() makes method check to work in '0 or more' mode. // It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to // catch the problems when the expected method call is totally skipped during test run. func (mmIsCorrectPassword *mAuthServiceMockIsCorrectPassword) Optional() *mAuthServiceMockIsCorrectPassword { mmIsCorrectPassword.optional = true return mmIsCorrectPassword } // Expect sets up expected params for AuthService.IsCorrectPassword func (mmIsCorrectPassword *mAuthServiceMockIsCorrectPassword) Expect(password string, hash string) *mAuthServiceMockIsCorrectPassword { if mmIsCorrectPassword.mock.funcIsCorrectPassword != nil { mmIsCorrectPassword.mock.t.Fatalf("AuthServiceMock.IsCorrectPassword mock is already set by Set") } if mmIsCorrectPassword.defaultExpectation == nil { mmIsCorrectPassword.defaultExpectation = &AuthServiceMockIsCorrectPasswordExpectation{} } if mmIsCorrectPassword.defaultExpectation.paramPtrs != nil { mmIsCorrectPassword.mock.t.Fatalf("AuthServiceMock.IsCorrectPassword mock is already set by ExpectParams functions") } mmIsCorrectPassword.defaultExpectation.params = &AuthServiceMockIsCorrectPasswordParams{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 } // ExpectPasswordParam1 sets up expected param password for AuthService.IsCorrectPassword func (mmIsCorrectPassword *mAuthServiceMockIsCorrectPassword) ExpectPasswordParam1(password string) *mAuthServiceMockIsCorrectPassword { if mmIsCorrectPassword.mock.funcIsCorrectPassword != nil { mmIsCorrectPassword.mock.t.Fatalf("AuthServiceMock.IsCorrectPassword mock is already set by Set") } if mmIsCorrectPassword.defaultExpectation == nil { mmIsCorrectPassword.defaultExpectation = &AuthServiceMockIsCorrectPasswordExpectation{} } if mmIsCorrectPassword.defaultExpectation.params != nil { mmIsCorrectPassword.mock.t.Fatalf("AuthServiceMock.IsCorrectPassword mock is already set by Expect") } if mmIsCorrectPassword.defaultExpectation.paramPtrs == nil { mmIsCorrectPassword.defaultExpectation.paramPtrs = &AuthServiceMockIsCorrectPasswordParamPtrs{} } mmIsCorrectPassword.defaultExpectation.paramPtrs.password = &password return mmIsCorrectPassword } // ExpectHashParam2 sets up expected param hash for AuthService.IsCorrectPassword func (mmIsCorrectPassword *mAuthServiceMockIsCorrectPassword) ExpectHashParam2(hash string) *mAuthServiceMockIsCorrectPassword { if mmIsCorrectPassword.mock.funcIsCorrectPassword != nil { mmIsCorrectPassword.mock.t.Fatalf("AuthServiceMock.IsCorrectPassword mock is already set by Set") } if mmIsCorrectPassword.defaultExpectation == nil { mmIsCorrectPassword.defaultExpectation = &AuthServiceMockIsCorrectPasswordExpectation{} } if mmIsCorrectPassword.defaultExpectation.params != nil { mmIsCorrectPassword.mock.t.Fatalf("AuthServiceMock.IsCorrectPassword mock is already set by Expect") } if mmIsCorrectPassword.defaultExpectation.paramPtrs == nil { mmIsCorrectPassword.defaultExpectation.paramPtrs = &AuthServiceMockIsCorrectPasswordParamPtrs{} } mmIsCorrectPassword.defaultExpectation.paramPtrs.hash = &hash return mmIsCorrectPassword } // Inspect accepts an inspector function that has same arguments as the AuthService.IsCorrectPassword func (mmIsCorrectPassword *mAuthServiceMockIsCorrectPassword) Inspect(f func(password string, hash string)) *mAuthServiceMockIsCorrectPassword { if mmIsCorrectPassword.mock.inspectFuncIsCorrectPassword != nil { mmIsCorrectPassword.mock.t.Fatalf("Inspect function is already set for AuthServiceMock.IsCorrectPassword") } mmIsCorrectPassword.mock.inspectFuncIsCorrectPassword = f return mmIsCorrectPassword } // Return sets up results that will be returned by AuthService.IsCorrectPassword func (mmIsCorrectPassword *mAuthServiceMockIsCorrectPassword) Return(b1 bool) *AuthServiceMock { if mmIsCorrectPassword.mock.funcIsCorrectPassword != nil { mmIsCorrectPassword.mock.t.Fatalf("AuthServiceMock.IsCorrectPassword mock is already set by Set") } if mmIsCorrectPassword.defaultExpectation == nil { mmIsCorrectPassword.defaultExpectation = &AuthServiceMockIsCorrectPasswordExpectation{mock: mmIsCorrectPassword.mock} } mmIsCorrectPassword.defaultExpectation.results = &AuthServiceMockIsCorrectPasswordResults{b1} return mmIsCorrectPassword.mock } // Set uses given function f to mock the AuthService.IsCorrectPassword method func (mmIsCorrectPassword *mAuthServiceMockIsCorrectPassword) Set(f func(password string, hash string) (b1 bool)) *AuthServiceMock { if mmIsCorrectPassword.defaultExpectation != nil { mmIsCorrectPassword.mock.t.Fatalf("Default expectation is already set for the AuthService.IsCorrectPassword method") } if len(mmIsCorrectPassword.expectations) > 0 { mmIsCorrectPassword.mock.t.Fatalf("Some expectations are already set for the AuthService.IsCorrectPassword method") } mmIsCorrectPassword.mock.funcIsCorrectPassword = f return mmIsCorrectPassword.mock } // When sets expectation for the AuthService.IsCorrectPassword which will trigger the result defined by the following // Then helper func (mmIsCorrectPassword *mAuthServiceMockIsCorrectPassword) When(password string, hash string) *AuthServiceMockIsCorrectPasswordExpectation { if mmIsCorrectPassword.mock.funcIsCorrectPassword != nil { mmIsCorrectPassword.mock.t.Fatalf("AuthServiceMock.IsCorrectPassword mock is already set by Set") } expectation := &AuthServiceMockIsCorrectPasswordExpectation{ mock: mmIsCorrectPassword.mock, params: &AuthServiceMockIsCorrectPasswordParams{password, hash}, } mmIsCorrectPassword.expectations = append(mmIsCorrectPassword.expectations, expectation) return expectation } // Then sets up AuthService.IsCorrectPassword return parameters for the expectation previously defined by the When method func (e *AuthServiceMockIsCorrectPasswordExpectation) Then(b1 bool) *AuthServiceMock { e.results = &AuthServiceMockIsCorrectPasswordResults{b1} return e.mock } // Times sets number of times AuthService.IsCorrectPassword should be invoked func (mmIsCorrectPassword *mAuthServiceMockIsCorrectPassword) Times(n uint64) *mAuthServiceMockIsCorrectPassword { if n == 0 { mmIsCorrectPassword.mock.t.Fatalf("Times of AuthServiceMock.IsCorrectPassword mock can not be zero") } mm_atomic.StoreUint64(&mmIsCorrectPassword.expectedInvocations, n) return mmIsCorrectPassword } func (mmIsCorrectPassword *mAuthServiceMockIsCorrectPassword) invocationsDone() bool { if len(mmIsCorrectPassword.expectations) == 0 && mmIsCorrectPassword.defaultExpectation == nil && mmIsCorrectPassword.mock.funcIsCorrectPassword == nil { return true } totalInvocations := mm_atomic.LoadUint64(&mmIsCorrectPassword.mock.afterIsCorrectPasswordCounter) expectedInvocations := mm_atomic.LoadUint64(&mmIsCorrectPassword.expectedInvocations) return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) } // IsCorrectPassword implements auth.AuthService func (mmIsCorrectPassword *AuthServiceMock) 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 := AuthServiceMockIsCorrectPasswordParams{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_want_ptrs := mmIsCorrectPassword.IsCorrectPasswordMock.defaultExpectation.paramPtrs mm_got := AuthServiceMockIsCorrectPasswordParams{password, hash} if mm_want_ptrs != nil { if mm_want_ptrs.password != nil && !minimock.Equal(*mm_want_ptrs.password, mm_got.password) { mmIsCorrectPassword.t.Errorf("AuthServiceMock.IsCorrectPassword got unexpected parameter password, want: %#v, got: %#v%s\n", *mm_want_ptrs.password, mm_got.password, minimock.Diff(*mm_want_ptrs.password, mm_got.password)) } if mm_want_ptrs.hash != nil && !minimock.Equal(*mm_want_ptrs.hash, mm_got.hash) { mmIsCorrectPassword.t.Errorf("AuthServiceMock.IsCorrectPassword got unexpected parameter hash, want: %#v, got: %#v%s\n", *mm_want_ptrs.hash, mm_got.hash, minimock.Diff(*mm_want_ptrs.hash, mm_got.hash)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmIsCorrectPassword.t.Errorf("AuthServiceMock.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 AuthServiceMock.IsCorrectPassword") } return (*mm_results).b1 } if mmIsCorrectPassword.funcIsCorrectPassword != nil { return mmIsCorrectPassword.funcIsCorrectPassword(password, hash) } mmIsCorrectPassword.t.Fatalf("Unexpected call to AuthServiceMock.IsCorrectPassword. %v %v", password, hash) return } // IsCorrectPasswordAfterCounter returns a count of finished AuthServiceMock.IsCorrectPassword invocations func (mmIsCorrectPassword *AuthServiceMock) IsCorrectPasswordAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmIsCorrectPassword.afterIsCorrectPasswordCounter) } // IsCorrectPasswordBeforeCounter returns a count of AuthServiceMock.IsCorrectPassword invocations func (mmIsCorrectPassword *AuthServiceMock) IsCorrectPasswordBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmIsCorrectPassword.beforeIsCorrectPasswordCounter) } // Calls returns a list of arguments used in each call to AuthServiceMock.IsCorrectPassword. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmIsCorrectPassword *mAuthServiceMockIsCorrectPassword) Calls() []*AuthServiceMockIsCorrectPasswordParams { mmIsCorrectPassword.mutex.RLock() argCopy := make([]*AuthServiceMockIsCorrectPasswordParams, 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 *AuthServiceMock) MinimockIsCorrectPasswordDone() bool { if m.IsCorrectPasswordMock.optional { // Optional methods provide '0 or more' call count restriction. return true } for _, e := range m.IsCorrectPasswordMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } return m.IsCorrectPasswordMock.invocationsDone() } // MinimockIsCorrectPasswordInspect logs each unmet expectation func (m *AuthServiceMock) MinimockIsCorrectPasswordInspect() { for _, e := range m.IsCorrectPasswordMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to AuthServiceMock.IsCorrectPassword with params: %#v", *e.params) } } afterIsCorrectPasswordCounter := mm_atomic.LoadUint64(&m.afterIsCorrectPasswordCounter) // if default expectation was set then invocations count should be greater than zero if m.IsCorrectPasswordMock.defaultExpectation != nil && afterIsCorrectPasswordCounter < 1 { if m.IsCorrectPasswordMock.defaultExpectation.params == nil { m.t.Error("Expected call to AuthServiceMock.IsCorrectPassword") } else { m.t.Errorf("Expected call to AuthServiceMock.IsCorrectPassword with params: %#v", *m.IsCorrectPasswordMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcIsCorrectPassword != nil && afterIsCorrectPasswordCounter < 1 { m.t.Error("Expected call to AuthServiceMock.IsCorrectPassword") } if !m.IsCorrectPasswordMock.invocationsDone() && afterIsCorrectPasswordCounter > 0 { m.t.Errorf("Expected %d calls to AuthServiceMock.IsCorrectPassword but found %d calls", mm_atomic.LoadUint64(&m.IsCorrectPasswordMock.expectedInvocations), afterIsCorrectPasswordCounter) } } // MinimockFinish checks that all mocked methods have been called the expected number of times func (m *AuthServiceMock) MinimockFinish() { m.finishOnce.Do(func() { if !m.minimockDone() { m.MinimockGenerateTokenInspect() m.MinimockGetClaimsInspect() m.MinimockIsCorrectPasswordInspect() } }) } // MinimockWait waits for all mocked methods to be called the expected number of times func (m *AuthServiceMock) 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 *AuthServiceMock) minimockDone() bool { done := true return done && m.MinimockGenerateTokenDone() && m.MinimockGetClaimsDone() && m.MinimockIsCorrectPasswordDone() }