// 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/user.UserRepository -o user_repository_minimock.go -n UserRepositoryMock -p mocks import ( "context" "sync" mm_atomic "sync/atomic" mm_time "time" "git.dmitriygnatenko.ru/dima/homethings/internal/models" "github.com/gojuno/minimock/v3" ) // UserRepositoryMock implements user.UserRepository type UserRepositoryMock struct { t minimock.Tester finishOnce sync.Once funcAdd func(ctx context.Context, username string, password string) (i1 int, err error) inspectFuncAdd func(ctx context.Context, username string, password string) afterAddCounter uint64 beforeAddCounter uint64 AddMock mUserRepositoryMockAdd funcGet func(ctx context.Context, username string) (up1 *models.User, err error) inspectFuncGet func(ctx context.Context, username string) afterGetCounter uint64 beforeGetCounter uint64 GetMock mUserRepositoryMockGet funcUpdate func(ctx context.Context, req models.UpdateUserRequest) (err error) inspectFuncUpdate func(ctx context.Context, req models.UpdateUserRequest) afterUpdateCounter uint64 beforeUpdateCounter uint64 UpdateMock mUserRepositoryMockUpdate } // NewUserRepositoryMock returns a mock for user.UserRepository func NewUserRepositoryMock(t minimock.Tester) *UserRepositoryMock { m := &UserRepositoryMock{t: t} if controller, ok := t.(minimock.MockController); ok { controller.RegisterMocker(m) } m.AddMock = mUserRepositoryMockAdd{mock: m} m.AddMock.callArgs = []*UserRepositoryMockAddParams{} m.GetMock = mUserRepositoryMockGet{mock: m} m.GetMock.callArgs = []*UserRepositoryMockGetParams{} m.UpdateMock = mUserRepositoryMockUpdate{mock: m} m.UpdateMock.callArgs = []*UserRepositoryMockUpdateParams{} t.Cleanup(m.MinimockFinish) return m } type mUserRepositoryMockAdd struct { optional bool mock *UserRepositoryMock defaultExpectation *UserRepositoryMockAddExpectation expectations []*UserRepositoryMockAddExpectation callArgs []*UserRepositoryMockAddParams mutex sync.RWMutex expectedInvocations uint64 } // UserRepositoryMockAddExpectation specifies expectation struct of the UserRepository.Add type UserRepositoryMockAddExpectation struct { mock *UserRepositoryMock params *UserRepositoryMockAddParams paramPtrs *UserRepositoryMockAddParamPtrs results *UserRepositoryMockAddResults Counter uint64 } // UserRepositoryMockAddParams contains parameters of the UserRepository.Add type UserRepositoryMockAddParams struct { ctx context.Context username string password string } // UserRepositoryMockAddParamPtrs contains pointers to parameters of the UserRepository.Add type UserRepositoryMockAddParamPtrs struct { ctx *context.Context username *string password *string } // UserRepositoryMockAddResults contains results of the UserRepository.Add type UserRepositoryMockAddResults struct { i1 int 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 (mmAdd *mUserRepositoryMockAdd) Optional() *mUserRepositoryMockAdd { mmAdd.optional = true return mmAdd } // Expect sets up expected params for UserRepository.Add func (mmAdd *mUserRepositoryMockAdd) Expect(ctx context.Context, username string, password string) *mUserRepositoryMockAdd { if mmAdd.mock.funcAdd != nil { mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Set") } if mmAdd.defaultExpectation == nil { mmAdd.defaultExpectation = &UserRepositoryMockAddExpectation{} } if mmAdd.defaultExpectation.paramPtrs != nil { mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by ExpectParams functions") } mmAdd.defaultExpectation.params = &UserRepositoryMockAddParams{ctx, username, password} for _, e := range mmAdd.expectations { if minimock.Equal(e.params, mmAdd.defaultExpectation.params) { mmAdd.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmAdd.defaultExpectation.params) } } return mmAdd } // ExpectCtxParam1 sets up expected param ctx for UserRepository.Add func (mmAdd *mUserRepositoryMockAdd) ExpectCtxParam1(ctx context.Context) *mUserRepositoryMockAdd { if mmAdd.mock.funcAdd != nil { mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Set") } if mmAdd.defaultExpectation == nil { mmAdd.defaultExpectation = &UserRepositoryMockAddExpectation{} } if mmAdd.defaultExpectation.params != nil { mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Expect") } if mmAdd.defaultExpectation.paramPtrs == nil { mmAdd.defaultExpectation.paramPtrs = &UserRepositoryMockAddParamPtrs{} } mmAdd.defaultExpectation.paramPtrs.ctx = &ctx return mmAdd } // ExpectUsernameParam2 sets up expected param username for UserRepository.Add func (mmAdd *mUserRepositoryMockAdd) ExpectUsernameParam2(username string) *mUserRepositoryMockAdd { if mmAdd.mock.funcAdd != nil { mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Set") } if mmAdd.defaultExpectation == nil { mmAdd.defaultExpectation = &UserRepositoryMockAddExpectation{} } if mmAdd.defaultExpectation.params != nil { mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Expect") } if mmAdd.defaultExpectation.paramPtrs == nil { mmAdd.defaultExpectation.paramPtrs = &UserRepositoryMockAddParamPtrs{} } mmAdd.defaultExpectation.paramPtrs.username = &username return mmAdd } // ExpectPasswordParam3 sets up expected param password for UserRepository.Add func (mmAdd *mUserRepositoryMockAdd) ExpectPasswordParam3(password string) *mUserRepositoryMockAdd { if mmAdd.mock.funcAdd != nil { mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Set") } if mmAdd.defaultExpectation == nil { mmAdd.defaultExpectation = &UserRepositoryMockAddExpectation{} } if mmAdd.defaultExpectation.params != nil { mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Expect") } if mmAdd.defaultExpectation.paramPtrs == nil { mmAdd.defaultExpectation.paramPtrs = &UserRepositoryMockAddParamPtrs{} } mmAdd.defaultExpectation.paramPtrs.password = &password return mmAdd } // Inspect accepts an inspector function that has same arguments as the UserRepository.Add func (mmAdd *mUserRepositoryMockAdd) Inspect(f func(ctx context.Context, username string, password string)) *mUserRepositoryMockAdd { if mmAdd.mock.inspectFuncAdd != nil { mmAdd.mock.t.Fatalf("Inspect function is already set for UserRepositoryMock.Add") } mmAdd.mock.inspectFuncAdd = f return mmAdd } // Return sets up results that will be returned by UserRepository.Add func (mmAdd *mUserRepositoryMockAdd) Return(i1 int, err error) *UserRepositoryMock { if mmAdd.mock.funcAdd != nil { mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Set") } if mmAdd.defaultExpectation == nil { mmAdd.defaultExpectation = &UserRepositoryMockAddExpectation{mock: mmAdd.mock} } mmAdd.defaultExpectation.results = &UserRepositoryMockAddResults{i1, err} return mmAdd.mock } // Set uses given function f to mock the UserRepository.Add method func (mmAdd *mUserRepositoryMockAdd) Set(f func(ctx context.Context, username string, password string) (i1 int, err error)) *UserRepositoryMock { if mmAdd.defaultExpectation != nil { mmAdd.mock.t.Fatalf("Default expectation is already set for the UserRepository.Add method") } if len(mmAdd.expectations) > 0 { mmAdd.mock.t.Fatalf("Some expectations are already set for the UserRepository.Add method") } mmAdd.mock.funcAdd = f return mmAdd.mock } // When sets expectation for the UserRepository.Add which will trigger the result defined by the following // Then helper func (mmAdd *mUserRepositoryMockAdd) When(ctx context.Context, username string, password string) *UserRepositoryMockAddExpectation { if mmAdd.mock.funcAdd != nil { mmAdd.mock.t.Fatalf("UserRepositoryMock.Add mock is already set by Set") } expectation := &UserRepositoryMockAddExpectation{ mock: mmAdd.mock, params: &UserRepositoryMockAddParams{ctx, username, password}, } mmAdd.expectations = append(mmAdd.expectations, expectation) return expectation } // Then sets up UserRepository.Add return parameters for the expectation previously defined by the When method func (e *UserRepositoryMockAddExpectation) Then(i1 int, err error) *UserRepositoryMock { e.results = &UserRepositoryMockAddResults{i1, err} return e.mock } // Times sets number of times UserRepository.Add should be invoked func (mmAdd *mUserRepositoryMockAdd) Times(n uint64) *mUserRepositoryMockAdd { if n == 0 { mmAdd.mock.t.Fatalf("Times of UserRepositoryMock.Add mock can not be zero") } mm_atomic.StoreUint64(&mmAdd.expectedInvocations, n) return mmAdd } func (mmAdd *mUserRepositoryMockAdd) invocationsDone() bool { if len(mmAdd.expectations) == 0 && mmAdd.defaultExpectation == nil && mmAdd.mock.funcAdd == nil { return true } totalInvocations := mm_atomic.LoadUint64(&mmAdd.mock.afterAddCounter) expectedInvocations := mm_atomic.LoadUint64(&mmAdd.expectedInvocations) return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) } // Add implements user.UserRepository func (mmAdd *UserRepositoryMock) Add(ctx context.Context, username string, password string) (i1 int, err error) { mm_atomic.AddUint64(&mmAdd.beforeAddCounter, 1) defer mm_atomic.AddUint64(&mmAdd.afterAddCounter, 1) if mmAdd.inspectFuncAdd != nil { mmAdd.inspectFuncAdd(ctx, username, password) } mm_params := UserRepositoryMockAddParams{ctx, username, password} // Record call args mmAdd.AddMock.mutex.Lock() mmAdd.AddMock.callArgs = append(mmAdd.AddMock.callArgs, &mm_params) mmAdd.AddMock.mutex.Unlock() for _, e := range mmAdd.AddMock.expectations { if minimock.Equal(*e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return e.results.i1, e.results.err } } if mmAdd.AddMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmAdd.AddMock.defaultExpectation.Counter, 1) mm_want := mmAdd.AddMock.defaultExpectation.params mm_want_ptrs := mmAdd.AddMock.defaultExpectation.paramPtrs mm_got := UserRepositoryMockAddParams{ctx, username, password} if mm_want_ptrs != nil { if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { mmAdd.t.Errorf("UserRepositoryMock.Add got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) } if mm_want_ptrs.username != nil && !minimock.Equal(*mm_want_ptrs.username, mm_got.username) { mmAdd.t.Errorf("UserRepositoryMock.Add got unexpected parameter username, want: %#v, got: %#v%s\n", *mm_want_ptrs.username, mm_got.username, minimock.Diff(*mm_want_ptrs.username, mm_got.username)) } if mm_want_ptrs.password != nil && !minimock.Equal(*mm_want_ptrs.password, mm_got.password) { mmAdd.t.Errorf("UserRepositoryMock.Add 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)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmAdd.t.Errorf("UserRepositoryMock.Add got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } mm_results := mmAdd.AddMock.defaultExpectation.results if mm_results == nil { mmAdd.t.Fatal("No results are set for the UserRepositoryMock.Add") } return (*mm_results).i1, (*mm_results).err } if mmAdd.funcAdd != nil { return mmAdd.funcAdd(ctx, username, password) } mmAdd.t.Fatalf("Unexpected call to UserRepositoryMock.Add. %v %v %v", ctx, username, password) return } // AddAfterCounter returns a count of finished UserRepositoryMock.Add invocations func (mmAdd *UserRepositoryMock) AddAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmAdd.afterAddCounter) } // AddBeforeCounter returns a count of UserRepositoryMock.Add invocations func (mmAdd *UserRepositoryMock) AddBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmAdd.beforeAddCounter) } // Calls returns a list of arguments used in each call to UserRepositoryMock.Add. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmAdd *mUserRepositoryMockAdd) Calls() []*UserRepositoryMockAddParams { mmAdd.mutex.RLock() argCopy := make([]*UserRepositoryMockAddParams, len(mmAdd.callArgs)) copy(argCopy, mmAdd.callArgs) mmAdd.mutex.RUnlock() return argCopy } // MinimockAddDone returns true if the count of the Add invocations corresponds // the number of defined expectations func (m *UserRepositoryMock) MinimockAddDone() bool { if m.AddMock.optional { // Optional methods provide '0 or more' call count restriction. return true } for _, e := range m.AddMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } return m.AddMock.invocationsDone() } // MinimockAddInspect logs each unmet expectation func (m *UserRepositoryMock) MinimockAddInspect() { for _, e := range m.AddMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to UserRepositoryMock.Add with params: %#v", *e.params) } } afterAddCounter := mm_atomic.LoadUint64(&m.afterAddCounter) // if default expectation was set then invocations count should be greater than zero if m.AddMock.defaultExpectation != nil && afterAddCounter < 1 { if m.AddMock.defaultExpectation.params == nil { m.t.Error("Expected call to UserRepositoryMock.Add") } else { m.t.Errorf("Expected call to UserRepositoryMock.Add with params: %#v", *m.AddMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcAdd != nil && afterAddCounter < 1 { m.t.Error("Expected call to UserRepositoryMock.Add") } if !m.AddMock.invocationsDone() && afterAddCounter > 0 { m.t.Errorf("Expected %d calls to UserRepositoryMock.Add but found %d calls", mm_atomic.LoadUint64(&m.AddMock.expectedInvocations), afterAddCounter) } } type mUserRepositoryMockGet struct { optional bool mock *UserRepositoryMock defaultExpectation *UserRepositoryMockGetExpectation expectations []*UserRepositoryMockGetExpectation callArgs []*UserRepositoryMockGetParams mutex sync.RWMutex expectedInvocations uint64 } // UserRepositoryMockGetExpectation specifies expectation struct of the UserRepository.Get type UserRepositoryMockGetExpectation struct { mock *UserRepositoryMock params *UserRepositoryMockGetParams paramPtrs *UserRepositoryMockGetParamPtrs results *UserRepositoryMockGetResults Counter uint64 } // UserRepositoryMockGetParams contains parameters of the UserRepository.Get type UserRepositoryMockGetParams struct { ctx context.Context username string } // UserRepositoryMockGetParamPtrs contains pointers to parameters of the UserRepository.Get type UserRepositoryMockGetParamPtrs struct { ctx *context.Context username *string } // UserRepositoryMockGetResults contains results of the UserRepository.Get type UserRepositoryMockGetResults struct { up1 *models.User 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 (mmGet *mUserRepositoryMockGet) Optional() *mUserRepositoryMockGet { mmGet.optional = true return mmGet } // Expect sets up expected params for UserRepository.Get func (mmGet *mUserRepositoryMockGet) Expect(ctx context.Context, username string) *mUserRepositoryMockGet { if mmGet.mock.funcGet != nil { mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set") } if mmGet.defaultExpectation == nil { mmGet.defaultExpectation = &UserRepositoryMockGetExpectation{} } if mmGet.defaultExpectation.paramPtrs != nil { mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by ExpectParams functions") } mmGet.defaultExpectation.params = &UserRepositoryMockGetParams{ctx, username} for _, e := range mmGet.expectations { if minimock.Equal(e.params, mmGet.defaultExpectation.params) { mmGet.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGet.defaultExpectation.params) } } return mmGet } // ExpectCtxParam1 sets up expected param ctx for UserRepository.Get func (mmGet *mUserRepositoryMockGet) ExpectCtxParam1(ctx context.Context) *mUserRepositoryMockGet { if mmGet.mock.funcGet != nil { mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set") } if mmGet.defaultExpectation == nil { mmGet.defaultExpectation = &UserRepositoryMockGetExpectation{} } if mmGet.defaultExpectation.params != nil { mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Expect") } if mmGet.defaultExpectation.paramPtrs == nil { mmGet.defaultExpectation.paramPtrs = &UserRepositoryMockGetParamPtrs{} } mmGet.defaultExpectation.paramPtrs.ctx = &ctx return mmGet } // ExpectUsernameParam2 sets up expected param username for UserRepository.Get func (mmGet *mUserRepositoryMockGet) ExpectUsernameParam2(username string) *mUserRepositoryMockGet { if mmGet.mock.funcGet != nil { mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set") } if mmGet.defaultExpectation == nil { mmGet.defaultExpectation = &UserRepositoryMockGetExpectation{} } if mmGet.defaultExpectation.params != nil { mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Expect") } if mmGet.defaultExpectation.paramPtrs == nil { mmGet.defaultExpectation.paramPtrs = &UserRepositoryMockGetParamPtrs{} } mmGet.defaultExpectation.paramPtrs.username = &username return mmGet } // Inspect accepts an inspector function that has same arguments as the UserRepository.Get func (mmGet *mUserRepositoryMockGet) Inspect(f func(ctx context.Context, username string)) *mUserRepositoryMockGet { if mmGet.mock.inspectFuncGet != nil { mmGet.mock.t.Fatalf("Inspect function is already set for UserRepositoryMock.Get") } mmGet.mock.inspectFuncGet = f return mmGet } // Return sets up results that will be returned by UserRepository.Get func (mmGet *mUserRepositoryMockGet) Return(up1 *models.User, err error) *UserRepositoryMock { if mmGet.mock.funcGet != nil { mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set") } if mmGet.defaultExpectation == nil { mmGet.defaultExpectation = &UserRepositoryMockGetExpectation{mock: mmGet.mock} } mmGet.defaultExpectation.results = &UserRepositoryMockGetResults{up1, err} return mmGet.mock } // Set uses given function f to mock the UserRepository.Get method func (mmGet *mUserRepositoryMockGet) Set(f func(ctx context.Context, username string) (up1 *models.User, err error)) *UserRepositoryMock { if mmGet.defaultExpectation != nil { mmGet.mock.t.Fatalf("Default expectation is already set for the UserRepository.Get method") } if len(mmGet.expectations) > 0 { mmGet.mock.t.Fatalf("Some expectations are already set for the UserRepository.Get method") } mmGet.mock.funcGet = f return mmGet.mock } // When sets expectation for the UserRepository.Get which will trigger the result defined by the following // Then helper func (mmGet *mUserRepositoryMockGet) When(ctx context.Context, username string) *UserRepositoryMockGetExpectation { if mmGet.mock.funcGet != nil { mmGet.mock.t.Fatalf("UserRepositoryMock.Get mock is already set by Set") } expectation := &UserRepositoryMockGetExpectation{ mock: mmGet.mock, params: &UserRepositoryMockGetParams{ctx, username}, } mmGet.expectations = append(mmGet.expectations, expectation) return expectation } // Then sets up UserRepository.Get return parameters for the expectation previously defined by the When method func (e *UserRepositoryMockGetExpectation) Then(up1 *models.User, err error) *UserRepositoryMock { e.results = &UserRepositoryMockGetResults{up1, err} return e.mock } // Times sets number of times UserRepository.Get should be invoked func (mmGet *mUserRepositoryMockGet) Times(n uint64) *mUserRepositoryMockGet { if n == 0 { mmGet.mock.t.Fatalf("Times of UserRepositoryMock.Get mock can not be zero") } mm_atomic.StoreUint64(&mmGet.expectedInvocations, n) return mmGet } func (mmGet *mUserRepositoryMockGet) invocationsDone() bool { if len(mmGet.expectations) == 0 && mmGet.defaultExpectation == nil && mmGet.mock.funcGet == nil { return true } totalInvocations := mm_atomic.LoadUint64(&mmGet.mock.afterGetCounter) expectedInvocations := mm_atomic.LoadUint64(&mmGet.expectedInvocations) return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) } // Get implements user.UserRepository func (mmGet *UserRepositoryMock) Get(ctx context.Context, username string) (up1 *models.User, err error) { mm_atomic.AddUint64(&mmGet.beforeGetCounter, 1) defer mm_atomic.AddUint64(&mmGet.afterGetCounter, 1) if mmGet.inspectFuncGet != nil { mmGet.inspectFuncGet(ctx, username) } mm_params := UserRepositoryMockGetParams{ctx, username} // Record call args mmGet.GetMock.mutex.Lock() mmGet.GetMock.callArgs = append(mmGet.GetMock.callArgs, &mm_params) mmGet.GetMock.mutex.Unlock() for _, e := range mmGet.GetMock.expectations { if minimock.Equal(*e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return e.results.up1, e.results.err } } if mmGet.GetMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmGet.GetMock.defaultExpectation.Counter, 1) mm_want := mmGet.GetMock.defaultExpectation.params mm_want_ptrs := mmGet.GetMock.defaultExpectation.paramPtrs mm_got := UserRepositoryMockGetParams{ctx, username} if mm_want_ptrs != nil { if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { mmGet.t.Errorf("UserRepositoryMock.Get got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) } if mm_want_ptrs.username != nil && !minimock.Equal(*mm_want_ptrs.username, mm_got.username) { mmGet.t.Errorf("UserRepositoryMock.Get got unexpected parameter username, want: %#v, got: %#v%s\n", *mm_want_ptrs.username, mm_got.username, minimock.Diff(*mm_want_ptrs.username, mm_got.username)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmGet.t.Errorf("UserRepositoryMock.Get got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } mm_results := mmGet.GetMock.defaultExpectation.results if mm_results == nil { mmGet.t.Fatal("No results are set for the UserRepositoryMock.Get") } return (*mm_results).up1, (*mm_results).err } if mmGet.funcGet != nil { return mmGet.funcGet(ctx, username) } mmGet.t.Fatalf("Unexpected call to UserRepositoryMock.Get. %v %v", ctx, username) return } // GetAfterCounter returns a count of finished UserRepositoryMock.Get invocations func (mmGet *UserRepositoryMock) GetAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmGet.afterGetCounter) } // GetBeforeCounter returns a count of UserRepositoryMock.Get invocations func (mmGet *UserRepositoryMock) GetBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmGet.beforeGetCounter) } // Calls returns a list of arguments used in each call to UserRepositoryMock.Get. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmGet *mUserRepositoryMockGet) Calls() []*UserRepositoryMockGetParams { mmGet.mutex.RLock() argCopy := make([]*UserRepositoryMockGetParams, len(mmGet.callArgs)) copy(argCopy, mmGet.callArgs) mmGet.mutex.RUnlock() return argCopy } // MinimockGetDone returns true if the count of the Get invocations corresponds // the number of defined expectations func (m *UserRepositoryMock) MinimockGetDone() bool { if m.GetMock.optional { // Optional methods provide '0 or more' call count restriction. return true } for _, e := range m.GetMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } return m.GetMock.invocationsDone() } // MinimockGetInspect logs each unmet expectation func (m *UserRepositoryMock) MinimockGetInspect() { for _, e := range m.GetMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to UserRepositoryMock.Get with params: %#v", *e.params) } } afterGetCounter := mm_atomic.LoadUint64(&m.afterGetCounter) // if default expectation was set then invocations count should be greater than zero if m.GetMock.defaultExpectation != nil && afterGetCounter < 1 { if m.GetMock.defaultExpectation.params == nil { m.t.Error("Expected call to UserRepositoryMock.Get") } else { m.t.Errorf("Expected call to UserRepositoryMock.Get with params: %#v", *m.GetMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcGet != nil && afterGetCounter < 1 { m.t.Error("Expected call to UserRepositoryMock.Get") } if !m.GetMock.invocationsDone() && afterGetCounter > 0 { m.t.Errorf("Expected %d calls to UserRepositoryMock.Get but found %d calls", mm_atomic.LoadUint64(&m.GetMock.expectedInvocations), afterGetCounter) } } type mUserRepositoryMockUpdate struct { optional bool mock *UserRepositoryMock defaultExpectation *UserRepositoryMockUpdateExpectation expectations []*UserRepositoryMockUpdateExpectation callArgs []*UserRepositoryMockUpdateParams mutex sync.RWMutex expectedInvocations uint64 } // UserRepositoryMockUpdateExpectation specifies expectation struct of the UserRepository.Update type UserRepositoryMockUpdateExpectation struct { mock *UserRepositoryMock params *UserRepositoryMockUpdateParams paramPtrs *UserRepositoryMockUpdateParamPtrs results *UserRepositoryMockUpdateResults Counter uint64 } // UserRepositoryMockUpdateParams contains parameters of the UserRepository.Update type UserRepositoryMockUpdateParams struct { ctx context.Context req models.UpdateUserRequest } // UserRepositoryMockUpdateParamPtrs contains pointers to parameters of the UserRepository.Update type UserRepositoryMockUpdateParamPtrs struct { ctx *context.Context req *models.UpdateUserRequest } // UserRepositoryMockUpdateResults contains results of the UserRepository.Update type UserRepositoryMockUpdateResults struct { 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 (mmUpdate *mUserRepositoryMockUpdate) Optional() *mUserRepositoryMockUpdate { mmUpdate.optional = true return mmUpdate } // Expect sets up expected params for UserRepository.Update func (mmUpdate *mUserRepositoryMockUpdate) Expect(ctx context.Context, req models.UpdateUserRequest) *mUserRepositoryMockUpdate { if mmUpdate.mock.funcUpdate != nil { mmUpdate.mock.t.Fatalf("UserRepositoryMock.Update mock is already set by Set") } if mmUpdate.defaultExpectation == nil { mmUpdate.defaultExpectation = &UserRepositoryMockUpdateExpectation{} } if mmUpdate.defaultExpectation.paramPtrs != nil { mmUpdate.mock.t.Fatalf("UserRepositoryMock.Update mock is already set by ExpectParams functions") } mmUpdate.defaultExpectation.params = &UserRepositoryMockUpdateParams{ctx, req} for _, e := range mmUpdate.expectations { if minimock.Equal(e.params, mmUpdate.defaultExpectation.params) { mmUpdate.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmUpdate.defaultExpectation.params) } } return mmUpdate } // ExpectCtxParam1 sets up expected param ctx for UserRepository.Update func (mmUpdate *mUserRepositoryMockUpdate) ExpectCtxParam1(ctx context.Context) *mUserRepositoryMockUpdate { if mmUpdate.mock.funcUpdate != nil { mmUpdate.mock.t.Fatalf("UserRepositoryMock.Update mock is already set by Set") } if mmUpdate.defaultExpectation == nil { mmUpdate.defaultExpectation = &UserRepositoryMockUpdateExpectation{} } if mmUpdate.defaultExpectation.params != nil { mmUpdate.mock.t.Fatalf("UserRepositoryMock.Update mock is already set by Expect") } if mmUpdate.defaultExpectation.paramPtrs == nil { mmUpdate.defaultExpectation.paramPtrs = &UserRepositoryMockUpdateParamPtrs{} } mmUpdate.defaultExpectation.paramPtrs.ctx = &ctx return mmUpdate } // ExpectReqParam2 sets up expected param req for UserRepository.Update func (mmUpdate *mUserRepositoryMockUpdate) ExpectReqParam2(req models.UpdateUserRequest) *mUserRepositoryMockUpdate { if mmUpdate.mock.funcUpdate != nil { mmUpdate.mock.t.Fatalf("UserRepositoryMock.Update mock is already set by Set") } if mmUpdate.defaultExpectation == nil { mmUpdate.defaultExpectation = &UserRepositoryMockUpdateExpectation{} } if mmUpdate.defaultExpectation.params != nil { mmUpdate.mock.t.Fatalf("UserRepositoryMock.Update mock is already set by Expect") } if mmUpdate.defaultExpectation.paramPtrs == nil { mmUpdate.defaultExpectation.paramPtrs = &UserRepositoryMockUpdateParamPtrs{} } mmUpdate.defaultExpectation.paramPtrs.req = &req return mmUpdate } // Inspect accepts an inspector function that has same arguments as the UserRepository.Update func (mmUpdate *mUserRepositoryMockUpdate) Inspect(f func(ctx context.Context, req models.UpdateUserRequest)) *mUserRepositoryMockUpdate { if mmUpdate.mock.inspectFuncUpdate != nil { mmUpdate.mock.t.Fatalf("Inspect function is already set for UserRepositoryMock.Update") } mmUpdate.mock.inspectFuncUpdate = f return mmUpdate } // Return sets up results that will be returned by UserRepository.Update func (mmUpdate *mUserRepositoryMockUpdate) Return(err error) *UserRepositoryMock { if mmUpdate.mock.funcUpdate != nil { mmUpdate.mock.t.Fatalf("UserRepositoryMock.Update mock is already set by Set") } if mmUpdate.defaultExpectation == nil { mmUpdate.defaultExpectation = &UserRepositoryMockUpdateExpectation{mock: mmUpdate.mock} } mmUpdate.defaultExpectation.results = &UserRepositoryMockUpdateResults{err} return mmUpdate.mock } // Set uses given function f to mock the UserRepository.Update method func (mmUpdate *mUserRepositoryMockUpdate) Set(f func(ctx context.Context, req models.UpdateUserRequest) (err error)) *UserRepositoryMock { if mmUpdate.defaultExpectation != nil { mmUpdate.mock.t.Fatalf("Default expectation is already set for the UserRepository.Update method") } if len(mmUpdate.expectations) > 0 { mmUpdate.mock.t.Fatalf("Some expectations are already set for the UserRepository.Update method") } mmUpdate.mock.funcUpdate = f return mmUpdate.mock } // When sets expectation for the UserRepository.Update which will trigger the result defined by the following // Then helper func (mmUpdate *mUserRepositoryMockUpdate) When(ctx context.Context, req models.UpdateUserRequest) *UserRepositoryMockUpdateExpectation { if mmUpdate.mock.funcUpdate != nil { mmUpdate.mock.t.Fatalf("UserRepositoryMock.Update mock is already set by Set") } expectation := &UserRepositoryMockUpdateExpectation{ mock: mmUpdate.mock, params: &UserRepositoryMockUpdateParams{ctx, req}, } mmUpdate.expectations = append(mmUpdate.expectations, expectation) return expectation } // Then sets up UserRepository.Update return parameters for the expectation previously defined by the When method func (e *UserRepositoryMockUpdateExpectation) Then(err error) *UserRepositoryMock { e.results = &UserRepositoryMockUpdateResults{err} return e.mock } // Times sets number of times UserRepository.Update should be invoked func (mmUpdate *mUserRepositoryMockUpdate) Times(n uint64) *mUserRepositoryMockUpdate { if n == 0 { mmUpdate.mock.t.Fatalf("Times of UserRepositoryMock.Update mock can not be zero") } mm_atomic.StoreUint64(&mmUpdate.expectedInvocations, n) return mmUpdate } func (mmUpdate *mUserRepositoryMockUpdate) invocationsDone() bool { if len(mmUpdate.expectations) == 0 && mmUpdate.defaultExpectation == nil && mmUpdate.mock.funcUpdate == nil { return true } totalInvocations := mm_atomic.LoadUint64(&mmUpdate.mock.afterUpdateCounter) expectedInvocations := mm_atomic.LoadUint64(&mmUpdate.expectedInvocations) return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) } // Update implements user.UserRepository func (mmUpdate *UserRepositoryMock) Update(ctx context.Context, req models.UpdateUserRequest) (err error) { mm_atomic.AddUint64(&mmUpdate.beforeUpdateCounter, 1) defer mm_atomic.AddUint64(&mmUpdate.afterUpdateCounter, 1) if mmUpdate.inspectFuncUpdate != nil { mmUpdate.inspectFuncUpdate(ctx, req) } mm_params := UserRepositoryMockUpdateParams{ctx, req} // Record call args mmUpdate.UpdateMock.mutex.Lock() mmUpdate.UpdateMock.callArgs = append(mmUpdate.UpdateMock.callArgs, &mm_params) mmUpdate.UpdateMock.mutex.Unlock() for _, e := range mmUpdate.UpdateMock.expectations { if minimock.Equal(*e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return e.results.err } } if mmUpdate.UpdateMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmUpdate.UpdateMock.defaultExpectation.Counter, 1) mm_want := mmUpdate.UpdateMock.defaultExpectation.params mm_want_ptrs := mmUpdate.UpdateMock.defaultExpectation.paramPtrs mm_got := UserRepositoryMockUpdateParams{ctx, req} if mm_want_ptrs != nil { if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { mmUpdate.t.Errorf("UserRepositoryMock.Update got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) } if mm_want_ptrs.req != nil && !minimock.Equal(*mm_want_ptrs.req, mm_got.req) { mmUpdate.t.Errorf("UserRepositoryMock.Update got unexpected parameter req, want: %#v, got: %#v%s\n", *mm_want_ptrs.req, mm_got.req, minimock.Diff(*mm_want_ptrs.req, mm_got.req)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmUpdate.t.Errorf("UserRepositoryMock.Update got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } mm_results := mmUpdate.UpdateMock.defaultExpectation.results if mm_results == nil { mmUpdate.t.Fatal("No results are set for the UserRepositoryMock.Update") } return (*mm_results).err } if mmUpdate.funcUpdate != nil { return mmUpdate.funcUpdate(ctx, req) } mmUpdate.t.Fatalf("Unexpected call to UserRepositoryMock.Update. %v %v", ctx, req) return } // UpdateAfterCounter returns a count of finished UserRepositoryMock.Update invocations func (mmUpdate *UserRepositoryMock) UpdateAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmUpdate.afterUpdateCounter) } // UpdateBeforeCounter returns a count of UserRepositoryMock.Update invocations func (mmUpdate *UserRepositoryMock) UpdateBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmUpdate.beforeUpdateCounter) } // Calls returns a list of arguments used in each call to UserRepositoryMock.Update. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmUpdate *mUserRepositoryMockUpdate) Calls() []*UserRepositoryMockUpdateParams { mmUpdate.mutex.RLock() argCopy := make([]*UserRepositoryMockUpdateParams, len(mmUpdate.callArgs)) copy(argCopy, mmUpdate.callArgs) mmUpdate.mutex.RUnlock() return argCopy } // MinimockUpdateDone returns true if the count of the Update invocations corresponds // the number of defined expectations func (m *UserRepositoryMock) MinimockUpdateDone() bool { if m.UpdateMock.optional { // Optional methods provide '0 or more' call count restriction. return true } for _, e := range m.UpdateMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } return m.UpdateMock.invocationsDone() } // MinimockUpdateInspect logs each unmet expectation func (m *UserRepositoryMock) MinimockUpdateInspect() { for _, e := range m.UpdateMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to UserRepositoryMock.Update with params: %#v", *e.params) } } afterUpdateCounter := mm_atomic.LoadUint64(&m.afterUpdateCounter) // if default expectation was set then invocations count should be greater than zero if m.UpdateMock.defaultExpectation != nil && afterUpdateCounter < 1 { if m.UpdateMock.defaultExpectation.params == nil { m.t.Error("Expected call to UserRepositoryMock.Update") } else { m.t.Errorf("Expected call to UserRepositoryMock.Update with params: %#v", *m.UpdateMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcUpdate != nil && afterUpdateCounter < 1 { m.t.Error("Expected call to UserRepositoryMock.Update") } if !m.UpdateMock.invocationsDone() && afterUpdateCounter > 0 { m.t.Errorf("Expected %d calls to UserRepositoryMock.Update but found %d calls", mm_atomic.LoadUint64(&m.UpdateMock.expectedInvocations), afterUpdateCounter) } } // MinimockFinish checks that all mocked methods have been called the expected number of times func (m *UserRepositoryMock) MinimockFinish() { m.finishOnce.Do(func() { if !m.minimockDone() { m.MinimockAddInspect() m.MinimockGetInspect() m.MinimockUpdateInspect() } }) } // MinimockWait waits for all mocked methods to be called the expected number of times func (m *UserRepositoryMock) 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 *UserRepositoryMock) minimockDone() bool { done := true return done && m.MinimockAddDone() && m.MinimockGetDone() && m.MinimockUpdateDone() }