2018-04-18 09:36:03 +02:00
|
|
|
// Code generated by moq; DO NOT EDIT.
|
2017-07-11 22:27:08 +02:00
|
|
|
// github.com/matryer/moq
|
|
|
|
|
2018-04-18 09:36:03 +02:00
|
|
|
package example
|
|
|
|
|
2017-07-11 22:27:08 +02:00
|
|
|
import (
|
|
|
|
"context"
|
2017-07-11 22:42:55 +02:00
|
|
|
"sync"
|
2017-07-11 22:27:08 +02:00
|
|
|
)
|
|
|
|
|
2018-06-04 14:22:28 +02:00
|
|
|
// Ensure, that PersonStoreMock does implement PersonStore.
|
|
|
|
// If this is not the case, regenerate this file with moq.
|
|
|
|
var _ PersonStore = &PersonStoreMock{}
|
|
|
|
|
2017-07-11 22:27:08 +02:00
|
|
|
// PersonStoreMock is a mock implementation of PersonStore.
|
|
|
|
//
|
Internal registry for disambiguated imports, vars (#141)
* Internal registry for disambiguated imports, vars
- Move functionality in the moq package partially into
internal/{registry,template}.
- Leverage registry to assign unique package and variable/method
parameter names. Use import aliases if present in interface source
package.
BREAKING CHANGE: When the interface definition does not mention the
parameter names, the field names in call info anonymous struct will be
different.
The new field names are generated using the type info (string -> s,
int -> n, chan int -> intCh, []MyType -> myTypes, map[string]int ->
stringToInt etc.).
For example, for a string parameter previously if the field name was
'In1', the new field could be 'S' or 'S1' (depends on number of
string method parameters).
* Refactor golden file tests to be table-driven
* Fix sync pkg alias handling for moq generation
* Improve, add tests (increase coverage)
* Use $.Foo in template, avoid declaring variables
$ is set to the data argument passed to Execute, that is, to the
starting value of dot.
Variables were declared to be able to refer to the parent context.
* Consistent template field formatting
* Use tabs in generated Godoc comments' example code
* Minor simplification
* go generate
* Fix conflict for generated param name of pointer type
Excellent work by @sudo-suhas.
2021-02-01 20:20:20 +01:00
|
|
|
// func TestSomethingThatUsesPersonStore(t *testing.T) {
|
2017-07-11 22:27:08 +02:00
|
|
|
//
|
Internal registry for disambiguated imports, vars (#141)
* Internal registry for disambiguated imports, vars
- Move functionality in the moq package partially into
internal/{registry,template}.
- Leverage registry to assign unique package and variable/method
parameter names. Use import aliases if present in interface source
package.
BREAKING CHANGE: When the interface definition does not mention the
parameter names, the field names in call info anonymous struct will be
different.
The new field names are generated using the type info (string -> s,
int -> n, chan int -> intCh, []MyType -> myTypes, map[string]int ->
stringToInt etc.).
For example, for a string parameter previously if the field name was
'In1', the new field could be 'S' or 'S1' (depends on number of
string method parameters).
* Refactor golden file tests to be table-driven
* Fix sync pkg alias handling for moq generation
* Improve, add tests (increase coverage)
* Use $.Foo in template, avoid declaring variables
$ is set to the data argument passed to Execute, that is, to the
starting value of dot.
Variables were declared to be able to refer to the parent context.
* Consistent template field formatting
* Use tabs in generated Godoc comments' example code
* Minor simplification
* go generate
* Fix conflict for generated param name of pointer type
Excellent work by @sudo-suhas.
2021-02-01 20:20:20 +01:00
|
|
|
// // make and configure a mocked PersonStore
|
|
|
|
// mockedPersonStore := &PersonStoreMock{
|
|
|
|
// CreateFunc: func(ctx context.Context, person *Person, confirm bool) error {
|
|
|
|
// panic("mock out the Create method")
|
|
|
|
// },
|
|
|
|
// GetFunc: func(ctx context.Context, id string) (*Person, error) {
|
|
|
|
// panic("mock out the Get method")
|
|
|
|
// },
|
|
|
|
// }
|
2017-07-11 22:27:08 +02:00
|
|
|
//
|
Internal registry for disambiguated imports, vars (#141)
* Internal registry for disambiguated imports, vars
- Move functionality in the moq package partially into
internal/{registry,template}.
- Leverage registry to assign unique package and variable/method
parameter names. Use import aliases if present in interface source
package.
BREAKING CHANGE: When the interface definition does not mention the
parameter names, the field names in call info anonymous struct will be
different.
The new field names are generated using the type info (string -> s,
int -> n, chan int -> intCh, []MyType -> myTypes, map[string]int ->
stringToInt etc.).
For example, for a string parameter previously if the field name was
'In1', the new field could be 'S' or 'S1' (depends on number of
string method parameters).
* Refactor golden file tests to be table-driven
* Fix sync pkg alias handling for moq generation
* Improve, add tests (increase coverage)
* Use $.Foo in template, avoid declaring variables
$ is set to the data argument passed to Execute, that is, to the
starting value of dot.
Variables were declared to be able to refer to the parent context.
* Consistent template field formatting
* Use tabs in generated Godoc comments' example code
* Minor simplification
* go generate
* Fix conflict for generated param name of pointer type
Excellent work by @sudo-suhas.
2021-02-01 20:20:20 +01:00
|
|
|
// // use mockedPersonStore in code that requires PersonStore
|
|
|
|
// // and then make assertions.
|
2017-07-11 22:42:55 +02:00
|
|
|
//
|
Internal registry for disambiguated imports, vars (#141)
* Internal registry for disambiguated imports, vars
- Move functionality in the moq package partially into
internal/{registry,template}.
- Leverage registry to assign unique package and variable/method
parameter names. Use import aliases if present in interface source
package.
BREAKING CHANGE: When the interface definition does not mention the
parameter names, the field names in call info anonymous struct will be
different.
The new field names are generated using the type info (string -> s,
int -> n, chan int -> intCh, []MyType -> myTypes, map[string]int ->
stringToInt etc.).
For example, for a string parameter previously if the field name was
'In1', the new field could be 'S' or 'S1' (depends on number of
string method parameters).
* Refactor golden file tests to be table-driven
* Fix sync pkg alias handling for moq generation
* Improve, add tests (increase coverage)
* Use $.Foo in template, avoid declaring variables
$ is set to the data argument passed to Execute, that is, to the
starting value of dot.
Variables were declared to be able to refer to the parent context.
* Consistent template field formatting
* Use tabs in generated Godoc comments' example code
* Minor simplification
* go generate
* Fix conflict for generated param name of pointer type
Excellent work by @sudo-suhas.
2021-02-01 20:20:20 +01:00
|
|
|
// }
|
2017-07-11 22:27:08 +02:00
|
|
|
type PersonStoreMock struct {
|
|
|
|
// CreateFunc mocks the Create method.
|
|
|
|
CreateFunc func(ctx context.Context, person *Person, confirm bool) error
|
|
|
|
|
|
|
|
// GetFunc mocks the Get method.
|
|
|
|
GetFunc func(ctx context.Context, id string) (*Person, error)
|
|
|
|
|
|
|
|
// calls tracks calls to the methods.
|
|
|
|
calls struct {
|
|
|
|
// Create holds details about calls to the Create method.
|
|
|
|
Create []struct {
|
|
|
|
// Ctx is the ctx argument value.
|
|
|
|
Ctx context.Context
|
|
|
|
// Person is the person argument value.
|
|
|
|
Person *Person
|
|
|
|
// Confirm is the confirm argument value.
|
|
|
|
Confirm bool
|
|
|
|
}
|
|
|
|
// Get holds details about calls to the Get method.
|
|
|
|
Get []struct {
|
|
|
|
// Ctx is the ctx argument value.
|
|
|
|
Ctx context.Context
|
2018-04-18 09:36:03 +02:00
|
|
|
// ID is the id argument value.
|
|
|
|
ID string
|
2017-07-11 22:27:08 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-16 13:25:11 +02:00
|
|
|
lockCreate sync.RWMutex
|
|
|
|
lockGet sync.RWMutex
|
2017-07-11 22:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create calls CreateFunc.
|
|
|
|
func (mock *PersonStoreMock) Create(ctx context.Context, person *Person, confirm bool) error {
|
|
|
|
if mock.CreateFunc == nil {
|
2018-06-05 15:28:15 +02:00
|
|
|
panic("PersonStoreMock.CreateFunc: method is nil but PersonStore.Create was just called")
|
2017-07-11 22:27:08 +02:00
|
|
|
}
|
|
|
|
callInfo := struct {
|
2017-07-11 22:42:55 +02:00
|
|
|
Ctx context.Context
|
|
|
|
Person *Person
|
2017-07-11 22:27:08 +02:00
|
|
|
Confirm bool
|
|
|
|
}{
|
2017-07-11 22:42:55 +02:00
|
|
|
Ctx: ctx,
|
|
|
|
Person: person,
|
2017-07-11 22:27:08 +02:00
|
|
|
Confirm: confirm,
|
|
|
|
}
|
2020-08-16 13:25:11 +02:00
|
|
|
mock.lockCreate.Lock()
|
2017-07-11 22:27:08 +02:00
|
|
|
mock.calls.Create = append(mock.calls.Create, callInfo)
|
2020-08-16 13:25:11 +02:00
|
|
|
mock.lockCreate.Unlock()
|
2017-07-11 22:27:08 +02:00
|
|
|
return mock.CreateFunc(ctx, person, confirm)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateCalls gets all the calls that were made to Create.
|
|
|
|
// Check the length with:
|
|
|
|
// len(mockedPersonStore.CreateCalls())
|
|
|
|
func (mock *PersonStoreMock) CreateCalls() []struct {
|
2017-07-11 22:42:55 +02:00
|
|
|
Ctx context.Context
|
|
|
|
Person *Person
|
|
|
|
Confirm bool
|
|
|
|
} {
|
2017-07-11 22:27:08 +02:00
|
|
|
var calls []struct {
|
2017-07-11 22:42:55 +02:00
|
|
|
Ctx context.Context
|
|
|
|
Person *Person
|
2017-07-11 22:27:08 +02:00
|
|
|
Confirm bool
|
|
|
|
}
|
2020-08-16 13:25:11 +02:00
|
|
|
mock.lockCreate.RLock()
|
2017-07-11 22:27:08 +02:00
|
|
|
calls = mock.calls.Create
|
2020-08-16 13:25:11 +02:00
|
|
|
mock.lockCreate.RUnlock()
|
2017-07-11 22:27:08 +02:00
|
|
|
return calls
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get calls GetFunc.
|
|
|
|
func (mock *PersonStoreMock) Get(ctx context.Context, id string) (*Person, error) {
|
|
|
|
if mock.GetFunc == nil {
|
2018-06-05 15:28:15 +02:00
|
|
|
panic("PersonStoreMock.GetFunc: method is nil but PersonStore.Get was just called")
|
2017-07-11 22:27:08 +02:00
|
|
|
}
|
|
|
|
callInfo := struct {
|
|
|
|
Ctx context.Context
|
2018-04-18 09:36:03 +02:00
|
|
|
ID string
|
2017-07-11 22:27:08 +02:00
|
|
|
}{
|
|
|
|
Ctx: ctx,
|
2018-04-18 09:36:03 +02:00
|
|
|
ID: id,
|
2017-07-11 22:27:08 +02:00
|
|
|
}
|
2020-08-16 13:25:11 +02:00
|
|
|
mock.lockGet.Lock()
|
2017-07-11 22:27:08 +02:00
|
|
|
mock.calls.Get = append(mock.calls.Get, callInfo)
|
2020-08-16 13:25:11 +02:00
|
|
|
mock.lockGet.Unlock()
|
2017-07-11 22:27:08 +02:00
|
|
|
return mock.GetFunc(ctx, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCalls gets all the calls that were made to Get.
|
|
|
|
// Check the length with:
|
|
|
|
// len(mockedPersonStore.GetCalls())
|
|
|
|
func (mock *PersonStoreMock) GetCalls() []struct {
|
2017-07-11 22:42:55 +02:00
|
|
|
Ctx context.Context
|
2018-04-18 09:36:03 +02:00
|
|
|
ID string
|
2017-07-11 22:42:55 +02:00
|
|
|
} {
|
2017-07-11 22:27:08 +02:00
|
|
|
var calls []struct {
|
|
|
|
Ctx context.Context
|
2018-04-18 09:36:03 +02:00
|
|
|
ID string
|
2017-07-11 22:27:08 +02:00
|
|
|
}
|
2020-08-16 13:25:11 +02:00
|
|
|
mock.lockGet.RLock()
|
2017-07-11 22:27:08 +02:00
|
|
|
calls = mock.calls.Get
|
2020-08-16 13:25:11 +02:00
|
|
|
mock.lockGet.RUnlock()
|
2017-07-11 22:27:08 +02:00
|
|
|
return calls
|
|
|
|
}
|