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.
This commit is contained in:
Suhas Karanth
2021-02-02 00:50:20 +05:30
committed by GitHub
parent b052143b5a
commit 2ae606f132
37 changed files with 2078 additions and 683 deletions

View File

@@ -14,22 +14,22 @@ var _ PersonStore = &PersonStoreMock{}
// PersonStoreMock is a mock implementation of PersonStore.
//
// func TestSomethingThatUsesPersonStore(t *testing.T) {
// func TestSomethingThatUsesPersonStore(t *testing.T) {
//
// // 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")
// },
// }
// // 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")
// },
// }
//
// // use mockedPersonStore in code that requires PersonStore
// // and then make assertions.
// // use mockedPersonStore in code that requires PersonStore
// // and then make assertions.
//
// }
// }
type PersonStoreMock struct {
// CreateFunc mocks the Create method.
CreateFunc func(ctx context.Context, person *Person, confirm bool) error