805 lines
32 KiB
Go
805 lines
32 KiB
Go
// Code generated by http://github.com/gojuno/minimock (v3.4.7). DO NOT EDIT.
|
|
|
|
package mocks
|
|
|
|
//go:generate minimock -i git.techease.ru/Smart-search/smart-search-back/internal/repository.TokenUsageRepository -o token_usage_repository_mock.go -n TokenUsageRepositoryMock -p mocks
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
mm_atomic "sync/atomic"
|
|
mm_time "time"
|
|
|
|
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
|
"github.com/gojuno/minimock/v3"
|
|
"github.com/jackc/pgx/v5"
|
|
)
|
|
|
|
// TokenUsageRepositoryMock implements mm_repository.TokenUsageRepository
|
|
type TokenUsageRepositoryMock struct {
|
|
t minimock.Tester
|
|
finishOnce sync.Once
|
|
|
|
funcCreate func(ctx context.Context, usage *model.TokenUsage) (err error)
|
|
funcCreateOrigin string
|
|
inspectFuncCreate func(ctx context.Context, usage *model.TokenUsage)
|
|
afterCreateCounter uint64
|
|
beforeCreateCounter uint64
|
|
CreateMock mTokenUsageRepositoryMockCreate
|
|
|
|
funcCreateTx func(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage) (err error)
|
|
funcCreateTxOrigin string
|
|
inspectFuncCreateTx func(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage)
|
|
afterCreateTxCounter uint64
|
|
beforeCreateTxCounter uint64
|
|
CreateTxMock mTokenUsageRepositoryMockCreateTx
|
|
}
|
|
|
|
// NewTokenUsageRepositoryMock returns a mock for mm_repository.TokenUsageRepository
|
|
func NewTokenUsageRepositoryMock(t minimock.Tester) *TokenUsageRepositoryMock {
|
|
m := &TokenUsageRepositoryMock{t: t}
|
|
|
|
if controller, ok := t.(minimock.MockController); ok {
|
|
controller.RegisterMocker(m)
|
|
}
|
|
|
|
m.CreateMock = mTokenUsageRepositoryMockCreate{mock: m}
|
|
m.CreateMock.callArgs = []*TokenUsageRepositoryMockCreateParams{}
|
|
|
|
m.CreateTxMock = mTokenUsageRepositoryMockCreateTx{mock: m}
|
|
m.CreateTxMock.callArgs = []*TokenUsageRepositoryMockCreateTxParams{}
|
|
|
|
t.Cleanup(m.MinimockFinish)
|
|
|
|
return m
|
|
}
|
|
|
|
type mTokenUsageRepositoryMockCreate struct {
|
|
optional bool
|
|
mock *TokenUsageRepositoryMock
|
|
defaultExpectation *TokenUsageRepositoryMockCreateExpectation
|
|
expectations []*TokenUsageRepositoryMockCreateExpectation
|
|
|
|
callArgs []*TokenUsageRepositoryMockCreateParams
|
|
mutex sync.RWMutex
|
|
|
|
expectedInvocations uint64
|
|
expectedInvocationsOrigin string
|
|
}
|
|
|
|
// TokenUsageRepositoryMockCreateExpectation specifies expectation struct of the TokenUsageRepository.Create
|
|
type TokenUsageRepositoryMockCreateExpectation struct {
|
|
mock *TokenUsageRepositoryMock
|
|
params *TokenUsageRepositoryMockCreateParams
|
|
paramPtrs *TokenUsageRepositoryMockCreateParamPtrs
|
|
expectationOrigins TokenUsageRepositoryMockCreateExpectationOrigins
|
|
results *TokenUsageRepositoryMockCreateResults
|
|
returnOrigin string
|
|
Counter uint64
|
|
}
|
|
|
|
// TokenUsageRepositoryMockCreateParams contains parameters of the TokenUsageRepository.Create
|
|
type TokenUsageRepositoryMockCreateParams struct {
|
|
ctx context.Context
|
|
usage *model.TokenUsage
|
|
}
|
|
|
|
// TokenUsageRepositoryMockCreateParamPtrs contains pointers to parameters of the TokenUsageRepository.Create
|
|
type TokenUsageRepositoryMockCreateParamPtrs struct {
|
|
ctx *context.Context
|
|
usage **model.TokenUsage
|
|
}
|
|
|
|
// TokenUsageRepositoryMockCreateResults contains results of the TokenUsageRepository.Create
|
|
type TokenUsageRepositoryMockCreateResults struct {
|
|
err error
|
|
}
|
|
|
|
// TokenUsageRepositoryMockCreateOrigins contains origins of expectations of the TokenUsageRepository.Create
|
|
type TokenUsageRepositoryMockCreateExpectationOrigins struct {
|
|
origin string
|
|
originCtx string
|
|
originUsage string
|
|
}
|
|
|
|
// 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 (mmCreate *mTokenUsageRepositoryMockCreate) Optional() *mTokenUsageRepositoryMockCreate {
|
|
mmCreate.optional = true
|
|
return mmCreate
|
|
}
|
|
|
|
// Expect sets up expected params for TokenUsageRepository.Create
|
|
func (mmCreate *mTokenUsageRepositoryMockCreate) Expect(ctx context.Context, usage *model.TokenUsage) *mTokenUsageRepositoryMockCreate {
|
|
if mmCreate.mock.funcCreate != nil {
|
|
mmCreate.mock.t.Fatalf("TokenUsageRepositoryMock.Create mock is already set by Set")
|
|
}
|
|
|
|
if mmCreate.defaultExpectation == nil {
|
|
mmCreate.defaultExpectation = &TokenUsageRepositoryMockCreateExpectation{}
|
|
}
|
|
|
|
if mmCreate.defaultExpectation.paramPtrs != nil {
|
|
mmCreate.mock.t.Fatalf("TokenUsageRepositoryMock.Create mock is already set by ExpectParams functions")
|
|
}
|
|
|
|
mmCreate.defaultExpectation.params = &TokenUsageRepositoryMockCreateParams{ctx, usage}
|
|
mmCreate.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1)
|
|
for _, e := range mmCreate.expectations {
|
|
if minimock.Equal(e.params, mmCreate.defaultExpectation.params) {
|
|
mmCreate.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmCreate.defaultExpectation.params)
|
|
}
|
|
}
|
|
|
|
return mmCreate
|
|
}
|
|
|
|
// ExpectCtxParam1 sets up expected param ctx for TokenUsageRepository.Create
|
|
func (mmCreate *mTokenUsageRepositoryMockCreate) ExpectCtxParam1(ctx context.Context) *mTokenUsageRepositoryMockCreate {
|
|
if mmCreate.mock.funcCreate != nil {
|
|
mmCreate.mock.t.Fatalf("TokenUsageRepositoryMock.Create mock is already set by Set")
|
|
}
|
|
|
|
if mmCreate.defaultExpectation == nil {
|
|
mmCreate.defaultExpectation = &TokenUsageRepositoryMockCreateExpectation{}
|
|
}
|
|
|
|
if mmCreate.defaultExpectation.params != nil {
|
|
mmCreate.mock.t.Fatalf("TokenUsageRepositoryMock.Create mock is already set by Expect")
|
|
}
|
|
|
|
if mmCreate.defaultExpectation.paramPtrs == nil {
|
|
mmCreate.defaultExpectation.paramPtrs = &TokenUsageRepositoryMockCreateParamPtrs{}
|
|
}
|
|
mmCreate.defaultExpectation.paramPtrs.ctx = &ctx
|
|
mmCreate.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1)
|
|
|
|
return mmCreate
|
|
}
|
|
|
|
// ExpectUsageParam2 sets up expected param usage for TokenUsageRepository.Create
|
|
func (mmCreate *mTokenUsageRepositoryMockCreate) ExpectUsageParam2(usage *model.TokenUsage) *mTokenUsageRepositoryMockCreate {
|
|
if mmCreate.mock.funcCreate != nil {
|
|
mmCreate.mock.t.Fatalf("TokenUsageRepositoryMock.Create mock is already set by Set")
|
|
}
|
|
|
|
if mmCreate.defaultExpectation == nil {
|
|
mmCreate.defaultExpectation = &TokenUsageRepositoryMockCreateExpectation{}
|
|
}
|
|
|
|
if mmCreate.defaultExpectation.params != nil {
|
|
mmCreate.mock.t.Fatalf("TokenUsageRepositoryMock.Create mock is already set by Expect")
|
|
}
|
|
|
|
if mmCreate.defaultExpectation.paramPtrs == nil {
|
|
mmCreate.defaultExpectation.paramPtrs = &TokenUsageRepositoryMockCreateParamPtrs{}
|
|
}
|
|
mmCreate.defaultExpectation.paramPtrs.usage = &usage
|
|
mmCreate.defaultExpectation.expectationOrigins.originUsage = minimock.CallerInfo(1)
|
|
|
|
return mmCreate
|
|
}
|
|
|
|
// Inspect accepts an inspector function that has same arguments as the TokenUsageRepository.Create
|
|
func (mmCreate *mTokenUsageRepositoryMockCreate) Inspect(f func(ctx context.Context, usage *model.TokenUsage)) *mTokenUsageRepositoryMockCreate {
|
|
if mmCreate.mock.inspectFuncCreate != nil {
|
|
mmCreate.mock.t.Fatalf("Inspect function is already set for TokenUsageRepositoryMock.Create")
|
|
}
|
|
|
|
mmCreate.mock.inspectFuncCreate = f
|
|
|
|
return mmCreate
|
|
}
|
|
|
|
// Return sets up results that will be returned by TokenUsageRepository.Create
|
|
func (mmCreate *mTokenUsageRepositoryMockCreate) Return(err error) *TokenUsageRepositoryMock {
|
|
if mmCreate.mock.funcCreate != nil {
|
|
mmCreate.mock.t.Fatalf("TokenUsageRepositoryMock.Create mock is already set by Set")
|
|
}
|
|
|
|
if mmCreate.defaultExpectation == nil {
|
|
mmCreate.defaultExpectation = &TokenUsageRepositoryMockCreateExpectation{mock: mmCreate.mock}
|
|
}
|
|
mmCreate.defaultExpectation.results = &TokenUsageRepositoryMockCreateResults{err}
|
|
mmCreate.defaultExpectation.returnOrigin = minimock.CallerInfo(1)
|
|
return mmCreate.mock
|
|
}
|
|
|
|
// Set uses given function f to mock the TokenUsageRepository.Create method
|
|
func (mmCreate *mTokenUsageRepositoryMockCreate) Set(f func(ctx context.Context, usage *model.TokenUsage) (err error)) *TokenUsageRepositoryMock {
|
|
if mmCreate.defaultExpectation != nil {
|
|
mmCreate.mock.t.Fatalf("Default expectation is already set for the TokenUsageRepository.Create method")
|
|
}
|
|
|
|
if len(mmCreate.expectations) > 0 {
|
|
mmCreate.mock.t.Fatalf("Some expectations are already set for the TokenUsageRepository.Create method")
|
|
}
|
|
|
|
mmCreate.mock.funcCreate = f
|
|
mmCreate.mock.funcCreateOrigin = minimock.CallerInfo(1)
|
|
return mmCreate.mock
|
|
}
|
|
|
|
// When sets expectation for the TokenUsageRepository.Create which will trigger the result defined by the following
|
|
// Then helper
|
|
func (mmCreate *mTokenUsageRepositoryMockCreate) When(ctx context.Context, usage *model.TokenUsage) *TokenUsageRepositoryMockCreateExpectation {
|
|
if mmCreate.mock.funcCreate != nil {
|
|
mmCreate.mock.t.Fatalf("TokenUsageRepositoryMock.Create mock is already set by Set")
|
|
}
|
|
|
|
expectation := &TokenUsageRepositoryMockCreateExpectation{
|
|
mock: mmCreate.mock,
|
|
params: &TokenUsageRepositoryMockCreateParams{ctx, usage},
|
|
expectationOrigins: TokenUsageRepositoryMockCreateExpectationOrigins{origin: minimock.CallerInfo(1)},
|
|
}
|
|
mmCreate.expectations = append(mmCreate.expectations, expectation)
|
|
return expectation
|
|
}
|
|
|
|
// Then sets up TokenUsageRepository.Create return parameters for the expectation previously defined by the When method
|
|
func (e *TokenUsageRepositoryMockCreateExpectation) Then(err error) *TokenUsageRepositoryMock {
|
|
e.results = &TokenUsageRepositoryMockCreateResults{err}
|
|
return e.mock
|
|
}
|
|
|
|
// Times sets number of times TokenUsageRepository.Create should be invoked
|
|
func (mmCreate *mTokenUsageRepositoryMockCreate) Times(n uint64) *mTokenUsageRepositoryMockCreate {
|
|
if n == 0 {
|
|
mmCreate.mock.t.Fatalf("Times of TokenUsageRepositoryMock.Create mock can not be zero")
|
|
}
|
|
mm_atomic.StoreUint64(&mmCreate.expectedInvocations, n)
|
|
mmCreate.expectedInvocationsOrigin = minimock.CallerInfo(1)
|
|
return mmCreate
|
|
}
|
|
|
|
func (mmCreate *mTokenUsageRepositoryMockCreate) invocationsDone() bool {
|
|
if len(mmCreate.expectations) == 0 && mmCreate.defaultExpectation == nil && mmCreate.mock.funcCreate == nil {
|
|
return true
|
|
}
|
|
|
|
totalInvocations := mm_atomic.LoadUint64(&mmCreate.mock.afterCreateCounter)
|
|
expectedInvocations := mm_atomic.LoadUint64(&mmCreate.expectedInvocations)
|
|
|
|
return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
|
|
}
|
|
|
|
// Create implements mm_repository.TokenUsageRepository
|
|
func (mmCreate *TokenUsageRepositoryMock) Create(ctx context.Context, usage *model.TokenUsage) (err error) {
|
|
mm_atomic.AddUint64(&mmCreate.beforeCreateCounter, 1)
|
|
defer mm_atomic.AddUint64(&mmCreate.afterCreateCounter, 1)
|
|
|
|
mmCreate.t.Helper()
|
|
|
|
if mmCreate.inspectFuncCreate != nil {
|
|
mmCreate.inspectFuncCreate(ctx, usage)
|
|
}
|
|
|
|
mm_params := TokenUsageRepositoryMockCreateParams{ctx, usage}
|
|
|
|
// Record call args
|
|
mmCreate.CreateMock.mutex.Lock()
|
|
mmCreate.CreateMock.callArgs = append(mmCreate.CreateMock.callArgs, &mm_params)
|
|
mmCreate.CreateMock.mutex.Unlock()
|
|
|
|
for _, e := range mmCreate.CreateMock.expectations {
|
|
if minimock.Equal(*e.params, mm_params) {
|
|
mm_atomic.AddUint64(&e.Counter, 1)
|
|
return e.results.err
|
|
}
|
|
}
|
|
|
|
if mmCreate.CreateMock.defaultExpectation != nil {
|
|
mm_atomic.AddUint64(&mmCreate.CreateMock.defaultExpectation.Counter, 1)
|
|
mm_want := mmCreate.CreateMock.defaultExpectation.params
|
|
mm_want_ptrs := mmCreate.CreateMock.defaultExpectation.paramPtrs
|
|
|
|
mm_got := TokenUsageRepositoryMockCreateParams{ctx, usage}
|
|
|
|
if mm_want_ptrs != nil {
|
|
|
|
if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
|
|
mmCreate.t.Errorf("TokenUsageRepositoryMock.Create got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
|
mmCreate.CreateMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
|
|
}
|
|
|
|
if mm_want_ptrs.usage != nil && !minimock.Equal(*mm_want_ptrs.usage, mm_got.usage) {
|
|
mmCreate.t.Errorf("TokenUsageRepositoryMock.Create got unexpected parameter usage, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
|
mmCreate.CreateMock.defaultExpectation.expectationOrigins.originUsage, *mm_want_ptrs.usage, mm_got.usage, minimock.Diff(*mm_want_ptrs.usage, mm_got.usage))
|
|
}
|
|
|
|
} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
|
|
mmCreate.t.Errorf("TokenUsageRepositoryMock.Create got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
|
mmCreate.CreateMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
|
|
}
|
|
|
|
mm_results := mmCreate.CreateMock.defaultExpectation.results
|
|
if mm_results == nil {
|
|
mmCreate.t.Fatal("No results are set for the TokenUsageRepositoryMock.Create")
|
|
}
|
|
return (*mm_results).err
|
|
}
|
|
if mmCreate.funcCreate != nil {
|
|
return mmCreate.funcCreate(ctx, usage)
|
|
}
|
|
mmCreate.t.Fatalf("Unexpected call to TokenUsageRepositoryMock.Create. %v %v", ctx, usage)
|
|
return
|
|
}
|
|
|
|
// CreateAfterCounter returns a count of finished TokenUsageRepositoryMock.Create invocations
|
|
func (mmCreate *TokenUsageRepositoryMock) CreateAfterCounter() uint64 {
|
|
return mm_atomic.LoadUint64(&mmCreate.afterCreateCounter)
|
|
}
|
|
|
|
// CreateBeforeCounter returns a count of TokenUsageRepositoryMock.Create invocations
|
|
func (mmCreate *TokenUsageRepositoryMock) CreateBeforeCounter() uint64 {
|
|
return mm_atomic.LoadUint64(&mmCreate.beforeCreateCounter)
|
|
}
|
|
|
|
// Calls returns a list of arguments used in each call to TokenUsageRepositoryMock.Create.
|
|
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
|
|
func (mmCreate *mTokenUsageRepositoryMockCreate) Calls() []*TokenUsageRepositoryMockCreateParams {
|
|
mmCreate.mutex.RLock()
|
|
|
|
argCopy := make([]*TokenUsageRepositoryMockCreateParams, len(mmCreate.callArgs))
|
|
copy(argCopy, mmCreate.callArgs)
|
|
|
|
mmCreate.mutex.RUnlock()
|
|
|
|
return argCopy
|
|
}
|
|
|
|
// MinimockCreateDone returns true if the count of the Create invocations corresponds
|
|
// the number of defined expectations
|
|
func (m *TokenUsageRepositoryMock) MinimockCreateDone() bool {
|
|
if m.CreateMock.optional {
|
|
// Optional methods provide '0 or more' call count restriction.
|
|
return true
|
|
}
|
|
|
|
for _, e := range m.CreateMock.expectations {
|
|
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return m.CreateMock.invocationsDone()
|
|
}
|
|
|
|
// MinimockCreateInspect logs each unmet expectation
|
|
func (m *TokenUsageRepositoryMock) MinimockCreateInspect() {
|
|
for _, e := range m.CreateMock.expectations {
|
|
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
|
m.t.Errorf("Expected call to TokenUsageRepositoryMock.Create at\n%s with params: %#v", e.expectationOrigins.origin, *e.params)
|
|
}
|
|
}
|
|
|
|
afterCreateCounter := mm_atomic.LoadUint64(&m.afterCreateCounter)
|
|
// if default expectation was set then invocations count should be greater than zero
|
|
if m.CreateMock.defaultExpectation != nil && afterCreateCounter < 1 {
|
|
if m.CreateMock.defaultExpectation.params == nil {
|
|
m.t.Errorf("Expected call to TokenUsageRepositoryMock.Create at\n%s", m.CreateMock.defaultExpectation.returnOrigin)
|
|
} else {
|
|
m.t.Errorf("Expected call to TokenUsageRepositoryMock.Create at\n%s with params: %#v", m.CreateMock.defaultExpectation.expectationOrigins.origin, *m.CreateMock.defaultExpectation.params)
|
|
}
|
|
}
|
|
// if func was set then invocations count should be greater than zero
|
|
if m.funcCreate != nil && afterCreateCounter < 1 {
|
|
m.t.Errorf("Expected call to TokenUsageRepositoryMock.Create at\n%s", m.funcCreateOrigin)
|
|
}
|
|
|
|
if !m.CreateMock.invocationsDone() && afterCreateCounter > 0 {
|
|
m.t.Errorf("Expected %d calls to TokenUsageRepositoryMock.Create at\n%s but found %d calls",
|
|
mm_atomic.LoadUint64(&m.CreateMock.expectedInvocations), m.CreateMock.expectedInvocationsOrigin, afterCreateCounter)
|
|
}
|
|
}
|
|
|
|
type mTokenUsageRepositoryMockCreateTx struct {
|
|
optional bool
|
|
mock *TokenUsageRepositoryMock
|
|
defaultExpectation *TokenUsageRepositoryMockCreateTxExpectation
|
|
expectations []*TokenUsageRepositoryMockCreateTxExpectation
|
|
|
|
callArgs []*TokenUsageRepositoryMockCreateTxParams
|
|
mutex sync.RWMutex
|
|
|
|
expectedInvocations uint64
|
|
expectedInvocationsOrigin string
|
|
}
|
|
|
|
// TokenUsageRepositoryMockCreateTxExpectation specifies expectation struct of the TokenUsageRepository.CreateTx
|
|
type TokenUsageRepositoryMockCreateTxExpectation struct {
|
|
mock *TokenUsageRepositoryMock
|
|
params *TokenUsageRepositoryMockCreateTxParams
|
|
paramPtrs *TokenUsageRepositoryMockCreateTxParamPtrs
|
|
expectationOrigins TokenUsageRepositoryMockCreateTxExpectationOrigins
|
|
results *TokenUsageRepositoryMockCreateTxResults
|
|
returnOrigin string
|
|
Counter uint64
|
|
}
|
|
|
|
// TokenUsageRepositoryMockCreateTxParams contains parameters of the TokenUsageRepository.CreateTx
|
|
type TokenUsageRepositoryMockCreateTxParams struct {
|
|
ctx context.Context
|
|
tx pgx.Tx
|
|
usage *model.TokenUsage
|
|
}
|
|
|
|
// TokenUsageRepositoryMockCreateTxParamPtrs contains pointers to parameters of the TokenUsageRepository.CreateTx
|
|
type TokenUsageRepositoryMockCreateTxParamPtrs struct {
|
|
ctx *context.Context
|
|
tx *pgx.Tx
|
|
usage **model.TokenUsage
|
|
}
|
|
|
|
// TokenUsageRepositoryMockCreateTxResults contains results of the TokenUsageRepository.CreateTx
|
|
type TokenUsageRepositoryMockCreateTxResults struct {
|
|
err error
|
|
}
|
|
|
|
// TokenUsageRepositoryMockCreateTxOrigins contains origins of expectations of the TokenUsageRepository.CreateTx
|
|
type TokenUsageRepositoryMockCreateTxExpectationOrigins struct {
|
|
origin string
|
|
originCtx string
|
|
originTx string
|
|
originUsage string
|
|
}
|
|
|
|
// 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 (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Optional() *mTokenUsageRepositoryMockCreateTx {
|
|
mmCreateTx.optional = true
|
|
return mmCreateTx
|
|
}
|
|
|
|
// Expect sets up expected params for TokenUsageRepository.CreateTx
|
|
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Expect(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage) *mTokenUsageRepositoryMockCreateTx {
|
|
if mmCreateTx.mock.funcCreateTx != nil {
|
|
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Set")
|
|
}
|
|
|
|
if mmCreateTx.defaultExpectation == nil {
|
|
mmCreateTx.defaultExpectation = &TokenUsageRepositoryMockCreateTxExpectation{}
|
|
}
|
|
|
|
if mmCreateTx.defaultExpectation.paramPtrs != nil {
|
|
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by ExpectParams functions")
|
|
}
|
|
|
|
mmCreateTx.defaultExpectation.params = &TokenUsageRepositoryMockCreateTxParams{ctx, tx, usage}
|
|
mmCreateTx.defaultExpectation.expectationOrigins.origin = minimock.CallerInfo(1)
|
|
for _, e := range mmCreateTx.expectations {
|
|
if minimock.Equal(e.params, mmCreateTx.defaultExpectation.params) {
|
|
mmCreateTx.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmCreateTx.defaultExpectation.params)
|
|
}
|
|
}
|
|
|
|
return mmCreateTx
|
|
}
|
|
|
|
// ExpectCtxParam1 sets up expected param ctx for TokenUsageRepository.CreateTx
|
|
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) ExpectCtxParam1(ctx context.Context) *mTokenUsageRepositoryMockCreateTx {
|
|
if mmCreateTx.mock.funcCreateTx != nil {
|
|
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Set")
|
|
}
|
|
|
|
if mmCreateTx.defaultExpectation == nil {
|
|
mmCreateTx.defaultExpectation = &TokenUsageRepositoryMockCreateTxExpectation{}
|
|
}
|
|
|
|
if mmCreateTx.defaultExpectation.params != nil {
|
|
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Expect")
|
|
}
|
|
|
|
if mmCreateTx.defaultExpectation.paramPtrs == nil {
|
|
mmCreateTx.defaultExpectation.paramPtrs = &TokenUsageRepositoryMockCreateTxParamPtrs{}
|
|
}
|
|
mmCreateTx.defaultExpectation.paramPtrs.ctx = &ctx
|
|
mmCreateTx.defaultExpectation.expectationOrigins.originCtx = minimock.CallerInfo(1)
|
|
|
|
return mmCreateTx
|
|
}
|
|
|
|
// ExpectTxParam2 sets up expected param tx for TokenUsageRepository.CreateTx
|
|
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) ExpectTxParam2(tx pgx.Tx) *mTokenUsageRepositoryMockCreateTx {
|
|
if mmCreateTx.mock.funcCreateTx != nil {
|
|
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Set")
|
|
}
|
|
|
|
if mmCreateTx.defaultExpectation == nil {
|
|
mmCreateTx.defaultExpectation = &TokenUsageRepositoryMockCreateTxExpectation{}
|
|
}
|
|
|
|
if mmCreateTx.defaultExpectation.params != nil {
|
|
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Expect")
|
|
}
|
|
|
|
if mmCreateTx.defaultExpectation.paramPtrs == nil {
|
|
mmCreateTx.defaultExpectation.paramPtrs = &TokenUsageRepositoryMockCreateTxParamPtrs{}
|
|
}
|
|
mmCreateTx.defaultExpectation.paramPtrs.tx = &tx
|
|
mmCreateTx.defaultExpectation.expectationOrigins.originTx = minimock.CallerInfo(1)
|
|
|
|
return mmCreateTx
|
|
}
|
|
|
|
// ExpectUsageParam3 sets up expected param usage for TokenUsageRepository.CreateTx
|
|
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) ExpectUsageParam3(usage *model.TokenUsage) *mTokenUsageRepositoryMockCreateTx {
|
|
if mmCreateTx.mock.funcCreateTx != nil {
|
|
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Set")
|
|
}
|
|
|
|
if mmCreateTx.defaultExpectation == nil {
|
|
mmCreateTx.defaultExpectation = &TokenUsageRepositoryMockCreateTxExpectation{}
|
|
}
|
|
|
|
if mmCreateTx.defaultExpectation.params != nil {
|
|
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Expect")
|
|
}
|
|
|
|
if mmCreateTx.defaultExpectation.paramPtrs == nil {
|
|
mmCreateTx.defaultExpectation.paramPtrs = &TokenUsageRepositoryMockCreateTxParamPtrs{}
|
|
}
|
|
mmCreateTx.defaultExpectation.paramPtrs.usage = &usage
|
|
mmCreateTx.defaultExpectation.expectationOrigins.originUsage = minimock.CallerInfo(1)
|
|
|
|
return mmCreateTx
|
|
}
|
|
|
|
// Inspect accepts an inspector function that has same arguments as the TokenUsageRepository.CreateTx
|
|
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Inspect(f func(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage)) *mTokenUsageRepositoryMockCreateTx {
|
|
if mmCreateTx.mock.inspectFuncCreateTx != nil {
|
|
mmCreateTx.mock.t.Fatalf("Inspect function is already set for TokenUsageRepositoryMock.CreateTx")
|
|
}
|
|
|
|
mmCreateTx.mock.inspectFuncCreateTx = f
|
|
|
|
return mmCreateTx
|
|
}
|
|
|
|
// Return sets up results that will be returned by TokenUsageRepository.CreateTx
|
|
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Return(err error) *TokenUsageRepositoryMock {
|
|
if mmCreateTx.mock.funcCreateTx != nil {
|
|
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Set")
|
|
}
|
|
|
|
if mmCreateTx.defaultExpectation == nil {
|
|
mmCreateTx.defaultExpectation = &TokenUsageRepositoryMockCreateTxExpectation{mock: mmCreateTx.mock}
|
|
}
|
|
mmCreateTx.defaultExpectation.results = &TokenUsageRepositoryMockCreateTxResults{err}
|
|
mmCreateTx.defaultExpectation.returnOrigin = minimock.CallerInfo(1)
|
|
return mmCreateTx.mock
|
|
}
|
|
|
|
// Set uses given function f to mock the TokenUsageRepository.CreateTx method
|
|
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Set(f func(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage) (err error)) *TokenUsageRepositoryMock {
|
|
if mmCreateTx.defaultExpectation != nil {
|
|
mmCreateTx.mock.t.Fatalf("Default expectation is already set for the TokenUsageRepository.CreateTx method")
|
|
}
|
|
|
|
if len(mmCreateTx.expectations) > 0 {
|
|
mmCreateTx.mock.t.Fatalf("Some expectations are already set for the TokenUsageRepository.CreateTx method")
|
|
}
|
|
|
|
mmCreateTx.mock.funcCreateTx = f
|
|
mmCreateTx.mock.funcCreateTxOrigin = minimock.CallerInfo(1)
|
|
return mmCreateTx.mock
|
|
}
|
|
|
|
// When sets expectation for the TokenUsageRepository.CreateTx which will trigger the result defined by the following
|
|
// Then helper
|
|
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) When(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage) *TokenUsageRepositoryMockCreateTxExpectation {
|
|
if mmCreateTx.mock.funcCreateTx != nil {
|
|
mmCreateTx.mock.t.Fatalf("TokenUsageRepositoryMock.CreateTx mock is already set by Set")
|
|
}
|
|
|
|
expectation := &TokenUsageRepositoryMockCreateTxExpectation{
|
|
mock: mmCreateTx.mock,
|
|
params: &TokenUsageRepositoryMockCreateTxParams{ctx, tx, usage},
|
|
expectationOrigins: TokenUsageRepositoryMockCreateTxExpectationOrigins{origin: minimock.CallerInfo(1)},
|
|
}
|
|
mmCreateTx.expectations = append(mmCreateTx.expectations, expectation)
|
|
return expectation
|
|
}
|
|
|
|
// Then sets up TokenUsageRepository.CreateTx return parameters for the expectation previously defined by the When method
|
|
func (e *TokenUsageRepositoryMockCreateTxExpectation) Then(err error) *TokenUsageRepositoryMock {
|
|
e.results = &TokenUsageRepositoryMockCreateTxResults{err}
|
|
return e.mock
|
|
}
|
|
|
|
// Times sets number of times TokenUsageRepository.CreateTx should be invoked
|
|
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Times(n uint64) *mTokenUsageRepositoryMockCreateTx {
|
|
if n == 0 {
|
|
mmCreateTx.mock.t.Fatalf("Times of TokenUsageRepositoryMock.CreateTx mock can not be zero")
|
|
}
|
|
mm_atomic.StoreUint64(&mmCreateTx.expectedInvocations, n)
|
|
mmCreateTx.expectedInvocationsOrigin = minimock.CallerInfo(1)
|
|
return mmCreateTx
|
|
}
|
|
|
|
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) invocationsDone() bool {
|
|
if len(mmCreateTx.expectations) == 0 && mmCreateTx.defaultExpectation == nil && mmCreateTx.mock.funcCreateTx == nil {
|
|
return true
|
|
}
|
|
|
|
totalInvocations := mm_atomic.LoadUint64(&mmCreateTx.mock.afterCreateTxCounter)
|
|
expectedInvocations := mm_atomic.LoadUint64(&mmCreateTx.expectedInvocations)
|
|
|
|
return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
|
|
}
|
|
|
|
// CreateTx implements mm_repository.TokenUsageRepository
|
|
func (mmCreateTx *TokenUsageRepositoryMock) CreateTx(ctx context.Context, tx pgx.Tx, usage *model.TokenUsage) (err error) {
|
|
mm_atomic.AddUint64(&mmCreateTx.beforeCreateTxCounter, 1)
|
|
defer mm_atomic.AddUint64(&mmCreateTx.afterCreateTxCounter, 1)
|
|
|
|
mmCreateTx.t.Helper()
|
|
|
|
if mmCreateTx.inspectFuncCreateTx != nil {
|
|
mmCreateTx.inspectFuncCreateTx(ctx, tx, usage)
|
|
}
|
|
|
|
mm_params := TokenUsageRepositoryMockCreateTxParams{ctx, tx, usage}
|
|
|
|
// Record call args
|
|
mmCreateTx.CreateTxMock.mutex.Lock()
|
|
mmCreateTx.CreateTxMock.callArgs = append(mmCreateTx.CreateTxMock.callArgs, &mm_params)
|
|
mmCreateTx.CreateTxMock.mutex.Unlock()
|
|
|
|
for _, e := range mmCreateTx.CreateTxMock.expectations {
|
|
if minimock.Equal(*e.params, mm_params) {
|
|
mm_atomic.AddUint64(&e.Counter, 1)
|
|
return e.results.err
|
|
}
|
|
}
|
|
|
|
if mmCreateTx.CreateTxMock.defaultExpectation != nil {
|
|
mm_atomic.AddUint64(&mmCreateTx.CreateTxMock.defaultExpectation.Counter, 1)
|
|
mm_want := mmCreateTx.CreateTxMock.defaultExpectation.params
|
|
mm_want_ptrs := mmCreateTx.CreateTxMock.defaultExpectation.paramPtrs
|
|
|
|
mm_got := TokenUsageRepositoryMockCreateTxParams{ctx, tx, usage}
|
|
|
|
if mm_want_ptrs != nil {
|
|
|
|
if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) {
|
|
mmCreateTx.t.Errorf("TokenUsageRepositoryMock.CreateTx got unexpected parameter ctx, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
|
mmCreateTx.CreateTxMock.defaultExpectation.expectationOrigins.originCtx, *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx))
|
|
}
|
|
|
|
if mm_want_ptrs.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) {
|
|
mmCreateTx.t.Errorf("TokenUsageRepositoryMock.CreateTx got unexpected parameter tx, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
|
mmCreateTx.CreateTxMock.defaultExpectation.expectationOrigins.originTx, *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx))
|
|
}
|
|
|
|
if mm_want_ptrs.usage != nil && !minimock.Equal(*mm_want_ptrs.usage, mm_got.usage) {
|
|
mmCreateTx.t.Errorf("TokenUsageRepositoryMock.CreateTx got unexpected parameter usage, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
|
mmCreateTx.CreateTxMock.defaultExpectation.expectationOrigins.originUsage, *mm_want_ptrs.usage, mm_got.usage, minimock.Diff(*mm_want_ptrs.usage, mm_got.usage))
|
|
}
|
|
|
|
} else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
|
|
mmCreateTx.t.Errorf("TokenUsageRepositoryMock.CreateTx got unexpected parameters, expected at\n%s:\nwant: %#v\n got: %#v%s\n",
|
|
mmCreateTx.CreateTxMock.defaultExpectation.expectationOrigins.origin, *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
|
|
}
|
|
|
|
mm_results := mmCreateTx.CreateTxMock.defaultExpectation.results
|
|
if mm_results == nil {
|
|
mmCreateTx.t.Fatal("No results are set for the TokenUsageRepositoryMock.CreateTx")
|
|
}
|
|
return (*mm_results).err
|
|
}
|
|
if mmCreateTx.funcCreateTx != nil {
|
|
return mmCreateTx.funcCreateTx(ctx, tx, usage)
|
|
}
|
|
mmCreateTx.t.Fatalf("Unexpected call to TokenUsageRepositoryMock.CreateTx. %v %v %v", ctx, tx, usage)
|
|
return
|
|
}
|
|
|
|
// CreateTxAfterCounter returns a count of finished TokenUsageRepositoryMock.CreateTx invocations
|
|
func (mmCreateTx *TokenUsageRepositoryMock) CreateTxAfterCounter() uint64 {
|
|
return mm_atomic.LoadUint64(&mmCreateTx.afterCreateTxCounter)
|
|
}
|
|
|
|
// CreateTxBeforeCounter returns a count of TokenUsageRepositoryMock.CreateTx invocations
|
|
func (mmCreateTx *TokenUsageRepositoryMock) CreateTxBeforeCounter() uint64 {
|
|
return mm_atomic.LoadUint64(&mmCreateTx.beforeCreateTxCounter)
|
|
}
|
|
|
|
// Calls returns a list of arguments used in each call to TokenUsageRepositoryMock.CreateTx.
|
|
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
|
|
func (mmCreateTx *mTokenUsageRepositoryMockCreateTx) Calls() []*TokenUsageRepositoryMockCreateTxParams {
|
|
mmCreateTx.mutex.RLock()
|
|
|
|
argCopy := make([]*TokenUsageRepositoryMockCreateTxParams, len(mmCreateTx.callArgs))
|
|
copy(argCopy, mmCreateTx.callArgs)
|
|
|
|
mmCreateTx.mutex.RUnlock()
|
|
|
|
return argCopy
|
|
}
|
|
|
|
// MinimockCreateTxDone returns true if the count of the CreateTx invocations corresponds
|
|
// the number of defined expectations
|
|
func (m *TokenUsageRepositoryMock) MinimockCreateTxDone() bool {
|
|
if m.CreateTxMock.optional {
|
|
// Optional methods provide '0 or more' call count restriction.
|
|
return true
|
|
}
|
|
|
|
for _, e := range m.CreateTxMock.expectations {
|
|
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return m.CreateTxMock.invocationsDone()
|
|
}
|
|
|
|
// MinimockCreateTxInspect logs each unmet expectation
|
|
func (m *TokenUsageRepositoryMock) MinimockCreateTxInspect() {
|
|
for _, e := range m.CreateTxMock.expectations {
|
|
if mm_atomic.LoadUint64(&e.Counter) < 1 {
|
|
m.t.Errorf("Expected call to TokenUsageRepositoryMock.CreateTx at\n%s with params: %#v", e.expectationOrigins.origin, *e.params)
|
|
}
|
|
}
|
|
|
|
afterCreateTxCounter := mm_atomic.LoadUint64(&m.afterCreateTxCounter)
|
|
// if default expectation was set then invocations count should be greater than zero
|
|
if m.CreateTxMock.defaultExpectation != nil && afterCreateTxCounter < 1 {
|
|
if m.CreateTxMock.defaultExpectation.params == nil {
|
|
m.t.Errorf("Expected call to TokenUsageRepositoryMock.CreateTx at\n%s", m.CreateTxMock.defaultExpectation.returnOrigin)
|
|
} else {
|
|
m.t.Errorf("Expected call to TokenUsageRepositoryMock.CreateTx at\n%s with params: %#v", m.CreateTxMock.defaultExpectation.expectationOrigins.origin, *m.CreateTxMock.defaultExpectation.params)
|
|
}
|
|
}
|
|
// if func was set then invocations count should be greater than zero
|
|
if m.funcCreateTx != nil && afterCreateTxCounter < 1 {
|
|
m.t.Errorf("Expected call to TokenUsageRepositoryMock.CreateTx at\n%s", m.funcCreateTxOrigin)
|
|
}
|
|
|
|
if !m.CreateTxMock.invocationsDone() && afterCreateTxCounter > 0 {
|
|
m.t.Errorf("Expected %d calls to TokenUsageRepositoryMock.CreateTx at\n%s but found %d calls",
|
|
mm_atomic.LoadUint64(&m.CreateTxMock.expectedInvocations), m.CreateTxMock.expectedInvocationsOrigin, afterCreateTxCounter)
|
|
}
|
|
}
|
|
|
|
// MinimockFinish checks that all mocked methods have been called the expected number of times
|
|
func (m *TokenUsageRepositoryMock) MinimockFinish() {
|
|
m.finishOnce.Do(func() {
|
|
if !m.minimockDone() {
|
|
m.MinimockCreateInspect()
|
|
|
|
m.MinimockCreateTxInspect()
|
|
}
|
|
})
|
|
}
|
|
|
|
// MinimockWait waits for all mocked methods to be called the expected number of times
|
|
func (m *TokenUsageRepositoryMock) 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 *TokenUsageRepositoryMock) minimockDone() bool {
|
|
done := true
|
|
return done &&
|
|
m.MinimockCreateDone() &&
|
|
m.MinimockCreateTxDone()
|
|
}
|