// 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.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 auth.UserRepository type UserRepositoryMock struct { t minimock.Tester finishOnce sync.Once 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 } // NewUserRepositoryMock returns a mock for auth.UserRepository func NewUserRepositoryMock(t minimock.Tester) *UserRepositoryMock { m := &UserRepositoryMock{t: t} if controller, ok := t.(minimock.MockController); ok { controller.RegisterMocker(m) } m.GetMock = mUserRepositoryMockGet{mock: m} m.GetMock.callArgs = []*UserRepositoryMockGetParams{} t.Cleanup(m.MinimockFinish) return m } 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 auth.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) } } // 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.MinimockGetInspect() } }) } // 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.MinimockGetDone() }