diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b5e2c25b..4b806221 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ jobs: test: strategy: matrix: - go-version: [1.15.x, 1.18.x] + go-version: [1.19.x, 1.20.x] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: @@ -30,7 +30,7 @@ jobs: - name: Install mockgen run: | - go install github.com/golang/mock/mockgen + go install go.uber.org/mock/mockgen - name: Run test script run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c12995e2..fe7357b0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,7 @@ First off, thank you for taking an interest to contribute to this project! ## Opening issues -When opening a [new issue](https://github.com/golang/mock/issues/new/choose) +When opening a [new issue](https://github.com/uber/mock/issues/new/choose) please: 1. Make sure there are not other open/closed issues asking/reporting/requesting diff --git a/MAINTAINERS b/MAINTAINERS new file mode 100644 index 00000000..a6d9819d --- /dev/null +++ b/MAINTAINERS @@ -0,0 +1,5 @@ +# This is the current list of maintainers to Uber's fork of gomock repository. + +Sung Yoon Whang +Ryan Hang +Zhongpeng Lin diff --git a/README.md b/README.md index a4213e50..13791d33 100644 --- a/README.md +++ b/README.md @@ -6,30 +6,21 @@ gomock is a mocking framework for the [Go programming language][golang]. It integrates well with Go's built-in `testing` package, but can be used in other contexts too. -## Installation +This project originates from Google's `golang/mock` repo. Unfortunately Google +no longer maintains this project, and given the heavy usage of gomock project +within Uber, we've decided to fork and maintain this going forward at Uber. -Once you have [installed Go][golang-install], install the `mockgen` tool. +Contributions are welcome in the form of GitHub issue or PR! -**Note**: If you have not done so already be sure to add `$GOPATH/bin` to your -`PATH`. +## Status -To get the latest released version use: +This project is still WIP. We will be tagging a release shortly, in early July. -### Go version < 1.16 +## Supported Go Versions -```bash -GO111MODULE=on go get github.com/golang/mock/mockgen@v1.6.0 -``` - -### Go 1.16+ - -```bash -go install github.com/golang/mock/mockgen@v1.6.0 -``` - -If you use `mockgen` in your CI pipeline, it may be more appropriate to fixate -on a specific mockgen version. You should try to keep the library in sync with -the version of mockgen used to generate your mocks. +go.uber.org/mock supports all Go versions supported by the official +[Go Release Policy](https://go.dev/doc/devel/release#policy). That is, +the two most recent releases of Go. ## Running mockgen @@ -250,28 +241,7 @@ If the received value is `3`, then it will be printed as `03`. [golang]: http://golang.org/ [golang-install]: http://golang.org/doc/install.html#releases -[gomock-reference]: https://pkg.go.dev/github.com/golang/mock/gomock -[ci-badge]: https://github.com/golang/mock/actions/workflows/test.yaml/badge.svg -[ci-runs]: https://github.com/golang/mock/actions -[reference-badge]: https://pkg.go.dev/badge/github.com/golang/mock.svg -[reference]: https://pkg.go.dev/github.com/golang/mock - -## Debugging Errors - -### reflect vendoring error - -```text -cannot find package "." -... github.com/golang/mock/mockgen/model -``` - -If you come across this error while using reflect mode and vendoring -dependencies there are three workarounds you can choose from: - -1. Use source mode. -2. Include an empty import `import _ "github.com/golang/mock/mockgen/model"`. -3. Add `--build_flags=--mod=mod` to your mockgen command. - -This error is due to changes in default behavior of the `go` command in more -recent versions. More details can be found in -[#494](https://github.com/golang/mock/issues/494). +[ci-badge]: https://github.com/uber/mock/actions/workflows/test.yaml/badge.svg +[ci-runs]: https://github.com/uber/mock/actions +[reference-badge]: https://pkg.go.dev/badge/github.com/uber/mock.svg +[reference]: https://pkg.go.dev/github.com/uber/mock diff --git a/go.mod b/go.mod index d920e36f..ccc412f0 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,14 @@ -module github.com/golang/mock +module go.uber.org/mock + +go 1.18 require ( golang.org/x/mod v0.5.1 golang.org/x/tools v0.1.8 ) -go 1.15 +require ( + github.com/yuin/goldmark v1.4.1 // indirect + golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect +) diff --git a/go.sum b/go.sum index 5ae13f0c..62558136 100644 --- a/go.sum +++ b/go.sum @@ -1,29 +1,10 @@ github.com/yuin/goldmark v1.4.1 h1:/vn0k+RBvwlxEmP5E7SZMqNxPhfMVFEJiykr15/0XKM= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.8 h1:P1HhGGuLW4aAclzjtmJdf0mJOjVUZUzOTqkAkWL+l6w= golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/gomock/controller_test.go b/gomock/controller_test.go index 921a51f8..69477238 100644 --- a/gomock/controller_test.go +++ b/gomock/controller_test.go @@ -21,7 +21,7 @@ import ( "strings" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) type ErrorReporter struct { diff --git a/gomock/example_test.go b/gomock/example_test.go index 0d938847..fee83324 100644 --- a/gomock/example_test.go +++ b/gomock/example_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) type Foo interface { diff --git a/gomock/internal/mock_gomock/mock_matcher.go b/gomock/internal/mock_gomock/mock_matcher.go index f4a6d526..6ba1f204 100644 --- a/gomock/internal/mock_gomock/mock_matcher.go +++ b/gomock/internal/mock_gomock/mock_matcher.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/gomock (interfaces: Matcher) +// Source: go.uber.org/mock/gomock (interfaces: Matcher) // Package mock_gomock is a generated GoMock package. package mock_gomock @@ -7,7 +7,7 @@ package mock_gomock import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockMatcher is a mock of Matcher interface. diff --git a/gomock/matchers_test.go b/gomock/matchers_test.go index 61bc1993..5868c407 100644 --- a/gomock/matchers_test.go +++ b/gomock/matchers_test.go @@ -14,7 +14,7 @@ package gomock_test -//go:generate mockgen -destination internal/mock_gomock/mock_matcher.go github.com/golang/mock/gomock Matcher +//go:generate mockgen -destination internal/mock_gomock/mock_matcher.go go.uber.org/mock/gomock Matcher import ( "context" @@ -22,8 +22,8 @@ import ( "reflect" "testing" - "github.com/golang/mock/gomock" - "github.com/golang/mock/gomock/internal/mock_gomock" + "go.uber.org/mock/gomock" + "go.uber.org/mock/gomock/internal/mock_gomock" ) type A []string diff --git a/gomock/mock_test.go b/gomock/mock_test.go index 4f1cfa91..03c5fd1b 100644 --- a/gomock/mock_test.go +++ b/gomock/mock_test.go @@ -7,7 +7,7 @@ package gomock_test import ( reflect "reflect" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) // MockFoo is a mock of Foo interface. diff --git a/mockgen/generic_go118.go b/mockgen/generic_go118.go index b29db9a8..917a15e8 100644 --- a/mockgen/generic_go118.go +++ b/mockgen/generic_go118.go @@ -14,7 +14,7 @@ import ( "go/ast" "strings" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" ) func getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field { diff --git a/mockgen/generic_notgo118.go b/mockgen/generic_notgo118.go index 8fe48c17..b608438c 100644 --- a/mockgen/generic_notgo118.go +++ b/mockgen/generic_notgo118.go @@ -20,7 +20,7 @@ package main import ( "go/ast" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" ) func getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field { diff --git a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport.go b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport.go index 288ab5d9..f49532df 100644 --- a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport.go +++ b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport.go @@ -5,7 +5,7 @@ package bugreport import ( "log" - "github.com/golang/mock/mockgen/internal/tests/aux_imports_embedded_interface/faux" + "go.uber.org/mock/mockgen/internal/tests/aux_imports_embedded_interface/faux" ) // Source is an interface w/ an embedded foreign interface diff --git a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go index 26a80d65..ea51e2ae 100644 --- a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go +++ b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go @@ -7,8 +7,8 @@ package bugreport import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - faux "github.com/golang/mock/mockgen/internal/tests/aux_imports_embedded_interface/faux" + gomock "go.uber.org/mock/gomock" + faux "go.uber.org/mock/mockgen/internal/tests/aux_imports_embedded_interface/faux" ) // MockSource is a mock of Source interface. diff --git a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_test.go b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_test.go index acfca322..cef03ed0 100644 --- a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_test.go +++ b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_test.go @@ -3,7 +3,7 @@ package bugreport import ( "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) // TestValidInterface assesses whether or not the generated mock is valid diff --git a/mockgen/internal/tests/const_array_length/mock.go b/mockgen/internal/tests/const_array_length/mock.go index 2591361c..b39fe8c1 100644 --- a/mockgen/internal/tests/const_array_length/mock.go +++ b/mockgen/internal/tests/const_array_length/mock.go @@ -7,7 +7,7 @@ package const_length import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockI is a mock of I interface. diff --git a/mockgen/internal/tests/copyright_file/mock.go b/mockgen/internal/tests/copyright_file/mock.go index 3cfabcfa..cb773191 100644 --- a/mockgen/internal/tests/copyright_file/mock.go +++ b/mockgen/internal/tests/copyright_file/mock.go @@ -12,7 +12,7 @@ package empty_interface import ( - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockEmpty is a mock of Empty interface. diff --git a/mockgen/internal/tests/custom_package_name/greeter/greeter.go b/mockgen/internal/tests/custom_package_name/greeter/greeter.go index fd2eee0b..7bb4d99b 100644 --- a/mockgen/internal/tests/custom_package_name/greeter/greeter.go +++ b/mockgen/internal/tests/custom_package_name/greeter/greeter.go @@ -7,10 +7,10 @@ import ( "fmt" // non-matching import suffix and package name - "github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1" + "go.uber.org/mock/mockgen/internal/tests/custom_package_name/client/v1" // matching import suffix and package name - "github.com/golang/mock/mockgen/internal/tests/custom_package_name/validator" + "go.uber.org/mock/mockgen/internal/tests/custom_package_name/validator" ) type InputMaker interface { diff --git a/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go b/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go index c0fe30c2..2b020ebb 100644 --- a/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go +++ b/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go @@ -7,8 +7,8 @@ package greeter import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - client "github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1" + gomock "go.uber.org/mock/gomock" + client "go.uber.org/mock/mockgen/internal/tests/custom_package_name/client/v1" ) // MockInputMaker is a mock of InputMaker interface. diff --git a/mockgen/internal/tests/custom_package_name/greeter/greeter_test.go b/mockgen/internal/tests/custom_package_name/greeter/greeter_test.go index a64d677c..b34d05fb 100644 --- a/mockgen/internal/tests/custom_package_name/greeter/greeter_test.go +++ b/mockgen/internal/tests/custom_package_name/greeter/greeter_test.go @@ -3,8 +3,8 @@ package greeter import ( "testing" - "github.com/golang/mock/gomock" - "github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1" + "go.uber.org/mock/gomock" + "go.uber.org/mock/mockgen/internal/tests/custom_package_name/client/v1" ) func TestGreeter_Greet(t *testing.T) { diff --git a/mockgen/internal/tests/dot_imports/mock.go b/mockgen/internal/tests/dot_imports/mock.go index 6e46eab9..dffee9dd 100644 --- a/mockgen/internal/tests/dot_imports/mock.go +++ b/mockgen/internal/tests/dot_imports/mock.go @@ -10,7 +10,7 @@ import ( . "net/http" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockWithDotImports is a mock of WithDotImports interface. diff --git a/mockgen/internal/tests/empty_interface/mock.go b/mockgen/internal/tests/empty_interface/mock.go index bffcf8ea..13b9f30c 100644 --- a/mockgen/internal/tests/empty_interface/mock.go +++ b/mockgen/internal/tests/empty_interface/mock.go @@ -5,7 +5,7 @@ package empty_interface import ( - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockEmpty is a mock of Empty interface. diff --git a/mockgen/internal/tests/extra_import/mock.go b/mockgen/internal/tests/extra_import/mock.go index d8b0928e..d3f6c530 100644 --- a/mockgen/internal/tests/extra_import/mock.go +++ b/mockgen/internal/tests/extra_import/mock.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/mockgen/internal/tests/extra_import (interfaces: Foo) +// Source: go.uber.org/mock/mockgen/internal/tests/extra_import (interfaces: Foo) // Package extra_import is a generated GoMock package. package extra_import @@ -7,7 +7,7 @@ package extra_import import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockFoo is a mock of Foo interface. diff --git a/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go b/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go index 8eca8644..e1882739 100644 --- a/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go +++ b/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go @@ -7,7 +7,7 @@ package bugreport import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockExample is a mock of Example interface. diff --git a/mockgen/internal/tests/generated_identifier_conflict/bugreport_test.go b/mockgen/internal/tests/generated_identifier_conflict/bugreport_test.go index 3ca9807d..3b53248a 100644 --- a/mockgen/internal/tests/generated_identifier_conflict/bugreport_test.go +++ b/mockgen/internal/tests/generated_identifier_conflict/bugreport_test.go @@ -1,7 +1,7 @@ package bugreport import ( - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" "testing" ) diff --git a/mockgen/internal/tests/generics/external.go b/mockgen/internal/tests/generics/external.go index ec5032aa..68b2d4b3 100644 --- a/mockgen/internal/tests/generics/external.go +++ b/mockgen/internal/tests/generics/external.go @@ -1,7 +1,7 @@ package generics import ( - "github.com/golang/mock/mockgen/internal/tests/generics/other" + "go.uber.org/mock/mockgen/internal/tests/generics/other" "golang.org/x/exp/constraints" ) diff --git a/mockgen/internal/tests/generics/generics.go b/mockgen/internal/tests/generics/generics.go index 0b389622..647a6fca 100644 --- a/mockgen/internal/tests/generics/generics.go +++ b/mockgen/internal/tests/generics/generics.go @@ -1,6 +1,6 @@ package generics -import "github.com/golang/mock/mockgen/internal/tests/generics/other" +import "go.uber.org/mock/mockgen/internal/tests/generics/other" //go:generate mockgen --source=generics.go --destination=source/mock_generics_test.go --package source ////go:generate mockgen --destination=reflect/mock_test.go --package reflect . Bar,Bar2 diff --git a/mockgen/internal/tests/generics/source/mock_external_test.go b/mockgen/internal/tests/generics/source/mock_external_test.go index aab22749..32a876b8 100644 --- a/mockgen/internal/tests/generics/source/mock_external_test.go +++ b/mockgen/internal/tests/generics/source/mock_external_test.go @@ -7,9 +7,9 @@ package source import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - generics "github.com/golang/mock/mockgen/internal/tests/generics" - other "github.com/golang/mock/mockgen/internal/tests/generics/other" + gomock "go.uber.org/mock/gomock" + generics "go.uber.org/mock/mockgen/internal/tests/generics" + other "go.uber.org/mock/mockgen/internal/tests/generics/other" constraints "golang.org/x/exp/constraints" ) diff --git a/mockgen/internal/tests/generics/source/mock_generics_test.go b/mockgen/internal/tests/generics/source/mock_generics_test.go index 0223e311..ad343407 100644 --- a/mockgen/internal/tests/generics/source/mock_generics_test.go +++ b/mockgen/internal/tests/generics/source/mock_generics_test.go @@ -7,9 +7,9 @@ package source import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - generics "github.com/golang/mock/mockgen/internal/tests/generics" - other "github.com/golang/mock/mockgen/internal/tests/generics/other" + gomock "go.uber.org/mock/gomock" + generics "go.uber.org/mock/mockgen/internal/tests/generics" + other "go.uber.org/mock/mockgen/internal/tests/generics/other" ) // MockBar is a mock of Bar interface. diff --git a/mockgen/internal/tests/import_embedded_interface/bugreport.go b/mockgen/internal/tests/import_embedded_interface/bugreport.go index 798d138e..0fedd7ef 100644 --- a/mockgen/internal/tests/import_embedded_interface/bugreport.go +++ b/mockgen/internal/tests/import_embedded_interface/bugreport.go @@ -19,8 +19,8 @@ package bugreport import ( "log" - "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/ersatz" - "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/faux" + "go.uber.org/mock/mockgen/internal/tests/import_embedded_interface/ersatz" + "go.uber.org/mock/mockgen/internal/tests/import_embedded_interface/faux" ) // Source is an interface w/ an embedded foreign interface diff --git a/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go b/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go index c060f8eb..2c482f57 100644 --- a/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go +++ b/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go @@ -7,9 +7,9 @@ package bugreport import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - ersatz "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/ersatz" - ersatz0 "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/other/ersatz" + gomock "go.uber.org/mock/gomock" + ersatz "go.uber.org/mock/mockgen/internal/tests/import_embedded_interface/ersatz" + ersatz0 "go.uber.org/mock/mockgen/internal/tests/import_embedded_interface/other/ersatz" ) // MockSource is a mock of Source interface. diff --git a/mockgen/internal/tests/import_embedded_interface/bugreport_test.go b/mockgen/internal/tests/import_embedded_interface/bugreport_test.go index 5915cbe1..6e6d095f 100644 --- a/mockgen/internal/tests/import_embedded_interface/bugreport_test.go +++ b/mockgen/internal/tests/import_embedded_interface/bugreport_test.go @@ -16,7 +16,7 @@ package bugreport import ( "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) // TestValidInterface assesses whether or not the generated mock is valid diff --git a/mockgen/internal/tests/import_embedded_interface/faux/conflict.go b/mockgen/internal/tests/import_embedded_interface/faux/conflict.go index 27803dd6..9fbe0c64 100644 --- a/mockgen/internal/tests/import_embedded_interface/faux/conflict.go +++ b/mockgen/internal/tests/import_embedded_interface/faux/conflict.go @@ -13,7 +13,7 @@ // limitations under the License. package faux -import "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/other/log" +import "go.uber.org/mock/mockgen/internal/tests/import_embedded_interface/other/log" func Conflict1() { log.Foo() diff --git a/mockgen/internal/tests/import_embedded_interface/faux/faux.go b/mockgen/internal/tests/import_embedded_interface/faux/faux.go index e1d66988..d81f66b2 100644 --- a/mockgen/internal/tests/import_embedded_interface/faux/faux.go +++ b/mockgen/internal/tests/import_embedded_interface/faux/faux.go @@ -16,7 +16,7 @@ package faux import ( "log" - "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/other/ersatz" + "go.uber.org/mock/mockgen/internal/tests/import_embedded_interface/other/ersatz" ) type Foreign interface { diff --git a/mockgen/internal/tests/import_embedded_interface/net_mock.go b/mockgen/internal/tests/import_embedded_interface/net_mock.go index 07792a6d..401529de 100644 --- a/mockgen/internal/tests/import_embedded_interface/net_mock.go +++ b/mockgen/internal/tests/import_embedded_interface/net_mock.go @@ -8,7 +8,7 @@ import ( http "net/http" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockNet is a mock of Net interface. diff --git a/mockgen/internal/tests/import_embedded_interface/net_test.go b/mockgen/internal/tests/import_embedded_interface/net_test.go index 381f7de3..9a19cebf 100644 --- a/mockgen/internal/tests/import_embedded_interface/net_test.go +++ b/mockgen/internal/tests/import_embedded_interface/net_test.go @@ -16,7 +16,7 @@ package bugreport import ( "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) // TestValidInterface assesses whether or not the generated mock is valid diff --git a/mockgen/internal/tests/import_source/definition/source_mock.go b/mockgen/internal/tests/import_source/definition/source_mock.go index b3d58d76..52a1be6a 100644 --- a/mockgen/internal/tests/import_source/definition/source_mock.go +++ b/mockgen/internal/tests/import_source/definition/source_mock.go @@ -7,7 +7,7 @@ package source import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockS is a mock of S interface. diff --git a/mockgen/internal/tests/import_source/source_mock.go b/mockgen/internal/tests/import_source/source_mock.go index 46677a31..1309a43c 100644 --- a/mockgen/internal/tests/import_source/source_mock.go +++ b/mockgen/internal/tests/import_source/source_mock.go @@ -7,8 +7,8 @@ package mock_source import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - source "github.com/golang/mock/mockgen/internal/tests/import_source/definition" + gomock "go.uber.org/mock/gomock" + source "go.uber.org/mock/mockgen/internal/tests/import_source/definition" ) // MockS is a mock of S interface. diff --git a/mockgen/internal/tests/internal_pkg/generate.go b/mockgen/internal/tests/internal_pkg/generate.go index 4e0a0cca..3e3e17fb 100644 --- a/mockgen/internal/tests/internal_pkg/generate.go +++ b/mockgen/internal/tests/internal_pkg/generate.go @@ -1,4 +1,4 @@ package test -//go:generate mockgen -destination subdir/internal/pkg/reflect_output/mock.go github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg Intf +//go:generate mockgen -destination subdir/internal/pkg/reflect_output/mock.go go.uber.org/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg Intf //go:generate mockgen -source subdir/internal/pkg/input.go -destination subdir/internal/pkg/source_output/mock.go diff --git a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go index 967c4b59..76892c1d 100644 --- a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go +++ b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg (interfaces: Intf) +// Source: go.uber.org/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg (interfaces: Intf) // Package mock_pkg is a generated GoMock package. package mock_pkg @@ -7,8 +7,8 @@ package mock_pkg import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - pkg "github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg" + gomock "go.uber.org/mock/gomock" + pkg "go.uber.org/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg" ) // MockIntf is a mock of Intf interface. diff --git a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go index 2e61bae4..3cf24f83 100644 --- a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go +++ b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go @@ -7,8 +7,8 @@ package mock_pkg import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - pkg "github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg" + gomock "go.uber.org/mock/gomock" + pkg "go.uber.org/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg" ) // MockArg is a mock of Arg interface. diff --git a/mockgen/internal/tests/missing_import/output/source_mock.go b/mockgen/internal/tests/missing_import/output/source_mock.go index 082d10bc..34f979de 100644 --- a/mockgen/internal/tests/missing_import/output/source_mock.go +++ b/mockgen/internal/tests/missing_import/output/source_mock.go @@ -7,8 +7,8 @@ package source import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - source "github.com/golang/mock/mockgen/internal/tests/missing_import/source" + gomock "go.uber.org/mock/gomock" + source "go.uber.org/mock/mockgen/internal/tests/missing_import/source" ) // MockBar is a mock of Bar interface. diff --git a/mockgen/internal/tests/mock_in_test_package/mock_test.go b/mockgen/internal/tests/mock_in_test_package/mock_test.go index 08bc27b0..13fc8120 100644 --- a/mockgen/internal/tests/mock_in_test_package/mock_test.go +++ b/mockgen/internal/tests/mock_in_test_package/mock_test.go @@ -7,8 +7,8 @@ package users_test import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - users "github.com/golang/mock/mockgen/internal/tests/mock_in_test_package" + gomock "go.uber.org/mock/gomock" + users "go.uber.org/mock/mockgen/internal/tests/mock_in_test_package" ) // MockFinder is a mock of Finder interface. diff --git a/mockgen/internal/tests/overlapping_methods/mock.go b/mockgen/internal/tests/overlapping_methods/mock.go index 20cbc397..1882380a 100644 --- a/mockgen/internal/tests/overlapping_methods/mock.go +++ b/mockgen/internal/tests/overlapping_methods/mock.go @@ -7,7 +7,7 @@ package overlap import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockReadWriteCloser is a mock of ReadWriteCloser interface. diff --git a/mockgen/internal/tests/overlapping_methods/overlap.go b/mockgen/internal/tests/overlapping_methods/overlap.go index 82ff012e..b2625b14 100644 --- a/mockgen/internal/tests/overlapping_methods/overlap.go +++ b/mockgen/internal/tests/overlapping_methods/overlap.go @@ -1,6 +1,6 @@ package overlap -//go:generate mockgen -package overlap -destination mock.go -source overlap.go -aux_files github.com/golang/mock/mockgen/internal/tests/overlapping_methods=interfaces.go +//go:generate mockgen -package overlap -destination mock.go -source overlap.go -aux_files go.uber.org/mock/mockgen/internal/tests/overlapping_methods=interfaces.go type ReadWriteCloser interface { ReadCloser diff --git a/mockgen/internal/tests/overlapping_methods/overlap_test.go b/mockgen/internal/tests/overlapping_methods/overlap_test.go index fdd9ba73..0bb8a3dd 100644 --- a/mockgen/internal/tests/overlapping_methods/overlap_test.go +++ b/mockgen/internal/tests/overlapping_methods/overlap_test.go @@ -4,7 +4,7 @@ import ( "errors" "testing" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // TestValidInterface assesses whether or not the generated mock is valid diff --git a/mockgen/internal/tests/panicing_test/mock_test.go b/mockgen/internal/tests/panicing_test/mock_test.go index 5c7ef668..265227b1 100644 --- a/mockgen/internal/tests/panicing_test/mock_test.go +++ b/mockgen/internal/tests/panicing_test/mock_test.go @@ -7,7 +7,7 @@ package paniccode import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockFoo is a mock of Foo interface. diff --git a/mockgen/internal/tests/panicing_test/panic_test.go b/mockgen/internal/tests/panicing_test/panic_test.go index 3e630f34..436ce8e3 100644 --- a/mockgen/internal/tests/panicing_test/panic_test.go +++ b/mockgen/internal/tests/panicing_test/panic_test.go @@ -20,7 +20,7 @@ package paniccode import ( "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func TestDanger_Panics_Explicit(t *testing.T) { diff --git a/mockgen/internal/tests/parenthesized_parameter_type/mock.go b/mockgen/internal/tests/parenthesized_parameter_type/mock.go index 911df8d8..ff4fc309 100644 --- a/mockgen/internal/tests/parenthesized_parameter_type/mock.go +++ b/mockgen/internal/tests/parenthesized_parameter_type/mock.go @@ -5,7 +5,7 @@ package parenthesized_parameter_type import ( - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" reflect "reflect" ) diff --git a/mockgen/internal/tests/self_package/mock.go b/mockgen/internal/tests/self_package/mock.go index 72e2cfa8..66004296 100644 --- a/mockgen/internal/tests/self_package/mock.go +++ b/mockgen/internal/tests/self_package/mock.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/mockgen/internal/tests/self_package (interfaces: Methods) +// Source: go.uber.org/mock/mockgen/internal/tests/self_package (interfaces: Methods) // Package core is a generated GoMock package. package core @@ -7,7 +7,7 @@ package core import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockMethods is a mock of Methods interface. diff --git a/mockgen/internal/tests/self_package/types.go b/mockgen/internal/tests/self_package/types.go index bf1bc766..9cc8630f 100644 --- a/mockgen/internal/tests/self_package/types.go +++ b/mockgen/internal/tests/self_package/types.go @@ -1,6 +1,6 @@ package core -//go:generate mockgen -package core -self_package github.com/golang/mock/mockgen/internal/tests/self_package -destination mock.go github.com/golang/mock/mockgen/internal/tests/self_package Methods +//go:generate mockgen -package core -self_package go.uber.org/mock/mockgen/internal/tests/self_package -destination mock.go go.uber.org/mock/mockgen/internal/tests/self_package Methods type Info struct{} diff --git a/mockgen/internal/tests/struct_return/mock.go b/mockgen/internal/tests/struct_return/mock.go new file mode 100644 index 00000000..f494aef0 --- /dev/null +++ b/mockgen/internal/tests/struct_return/mock.go @@ -0,0 +1,58 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/golang/mock/mockgen/internal/tests/struct_return (interfaces: Foo) + +// Package struct_return is a generated GoMock package. +package struct_return + +import ( + reflect "reflect" + + gomock "github.com/golang/mock/gomock" +) + +// MockFoo is a mock of Foo interface. +type MockFoo struct { + ctrl *gomock.Controller + recorder *MockFooMockRecorder +} + +// MockFooMockRecorder is the mock recorder for MockFoo. +type MockFooMockRecorder struct { + mock *MockFoo +} + +// NewMockFoo creates a new mock instance. +func NewMockFoo(ctrl *gomock.Controller) *MockFoo { + mock := &MockFoo{ctrl: ctrl} + mock.recorder = &MockFooMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockFoo) EXPECT() *MockFooMockRecorder { + return m.recorder +} + +// Bar mocks base method. +func (m *MockFoo) Bar() struct { + Value string + Nested struct { + Value int + } +} { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Bar") + ret0, _ := ret[0].(struct { + Value string + Nested struct { + Value int + } + }) + return ret0 +} + +// Bar indicates an expected call of Bar. +func (mr *MockFooMockRecorder) Bar() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Bar", reflect.TypeOf((*MockFoo)(nil).Bar)) +} diff --git a/mockgen/internal/tests/struct_return/struct_return.go b/mockgen/internal/tests/struct_return/struct_return.go new file mode 100644 index 00000000..f9080cfc --- /dev/null +++ b/mockgen/internal/tests/struct_return/struct_return.go @@ -0,0 +1,17 @@ +// Package extra_import makes sure output does not import it. See #515. +package struct_return + +//go:generate mockgen -destination mock.go -package struct_return . Foo + +type Message struct { + Text string +} + +type Foo interface { + Bar() struct { + Value string + Nested struct { + Value int + } + } +} diff --git a/mockgen/internal/tests/test_package/mock_test.go b/mockgen/internal/tests/test_package/mock_test.go index b357165b..05e66d29 100644 --- a/mockgen/internal/tests/test_package/mock_test.go +++ b/mockgen/internal/tests/test_package/mock_test.go @@ -7,7 +7,7 @@ package users_test import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockFinder is a mock of Finder interface. diff --git a/mockgen/internal/tests/unexported_method/bugreport_mock.go b/mockgen/internal/tests/unexported_method/bugreport_mock.go index d52d06ec..305902e4 100644 --- a/mockgen/internal/tests/unexported_method/bugreport_mock.go +++ b/mockgen/internal/tests/unexported_method/bugreport_mock.go @@ -7,7 +7,7 @@ package bugreport import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockExample is a mock of Example interface. diff --git a/mockgen/internal/tests/unexported_method/bugreport_test.go b/mockgen/internal/tests/unexported_method/bugreport_test.go index d428fb4c..b3286852 100644 --- a/mockgen/internal/tests/unexported_method/bugreport_test.go +++ b/mockgen/internal/tests/unexported_method/bugreport_test.go @@ -3,7 +3,7 @@ package bugreport import ( "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func TestCallExample(t *testing.T) { diff --git a/mockgen/internal/tests/vendor_dep/doc.go b/mockgen/internal/tests/vendor_dep/doc.go index 29e424c8..de3e785e 100644 --- a/mockgen/internal/tests/vendor_dep/doc.go +++ b/mockgen/internal/tests/vendor_dep/doc.go @@ -1,4 +1,4 @@ package vendor_dep -//go:generate mockgen -package vendor_dep -destination mock.go github.com/golang/mock/mockgen/internal/tests/vendor_dep VendorsDep +//go:generate mockgen -package vendor_dep -destination mock.go go.uber.org/mock/mockgen/internal/tests/vendor_dep VendorsDep //go:generate mockgen -destination source_mock_package/mock.go -source=vendor_dep.go diff --git a/mockgen/internal/tests/vendor_dep/mock.go b/mockgen/internal/tests/vendor_dep/mock.go index 4900ac08..62c55c63 100644 --- a/mockgen/internal/tests/vendor_dep/mock.go +++ b/mockgen/internal/tests/vendor_dep/mock.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/mockgen/internal/tests/vendor_dep (interfaces: VendorsDep) +// Source: go.uber.org/mock/mockgen/internal/tests/vendor_dep (interfaces: VendorsDep) // Package vendor_dep is a generated GoMock package. package vendor_dep @@ -7,7 +7,7 @@ package vendor_dep import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" present "golang.org/x/tools/present" ) diff --git a/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go b/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go index b02a0489..c3f76d79 100644 --- a/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go +++ b/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go @@ -7,7 +7,7 @@ package mock_vendor_dep import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" present "golang.org/x/tools/present" ) diff --git a/mockgen/internal/tests/vendor_pkg/mock.go b/mockgen/internal/tests/vendor_pkg/mock.go index f0a41968..53cc47d1 100644 --- a/mockgen/internal/tests/vendor_pkg/mock.go +++ b/mockgen/internal/tests/vendor_pkg/mock.go @@ -7,7 +7,7 @@ package vendor_pkg import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockElem is a mock of Elem interface. diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index 79cb921c..031b4eaa 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -37,14 +37,14 @@ import ( "strings" "unicode" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" "golang.org/x/mod/modfile" toolsimports "golang.org/x/tools/imports" ) const ( - gomockImportPath = "github.com/golang/mock/gomock" + gomockImportPath = "go.uber.org/mock/gomock" ) var ( diff --git a/mockgen/mockgen_test.go b/mockgen/mockgen_test.go index 55566001..58209471 100644 --- a/mockgen/mockgen_test.go +++ b/mockgen/mockgen_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" ) func TestMakeArgString(t *testing.T) { diff --git a/mockgen/model/model.go b/mockgen/model/model.go index 94d7f4ba..61795123 100644 --- a/mockgen/model/model.go +++ b/mockgen/model/model.go @@ -24,7 +24,7 @@ import ( ) // pkgPath is the importable path for package model -const pkgPath = "github.com/golang/mock/mockgen/model" +const pkgPath = "go.uber.org/mock/mockgen/model" // Package is a Go package. It may be a subset. type Package struct { @@ -148,6 +148,7 @@ type Type interface { func init() { gob.Register(&ArrayType{}) + gob.Register(&StructType{}) gob.Register(&ChanType{}) gob.Register(&FuncType{}) gob.Register(&MapType{}) @@ -160,7 +161,7 @@ func init() { // For a non-pointer type, gob.Register will try to get package full path by // calling rt.PkgPath() for a name to register. If your project has vendor // directory, it is possible that PkgPath will get a path like this: - // ../../../vendor/github.com/golang/mock/mockgen/model + // ../../../vendor/go.uber.org/mock/mockgen/model gob.RegisterName(pkgPath+".PredeclaredType", PredeclaredType("")) } @@ -180,6 +181,32 @@ func (at *ArrayType) String(pm map[string]string, pkgOverride string) string { func (at *ArrayType) addImports(im map[string]bool) { at.Type.addImports(im) } +type NamedField struct { + Name string + Type Type +} + +type StructType struct { + Fields []NamedField +} + +func (s *StructType) String( + pm map[string]string, + pkgOverride string, +) string { + parts := []string{"struct {"} + for _, f := range s.Fields { + part := fmt.Sprintf("%s %s", f.Name, f.Type.String(pm, pkgOverride)) + parts = append(parts, part) + } + parts = append(parts, "}") + return strings.Join(parts, "\n") +} + +func (s *StructType) addImports(im map[string]bool) { + return +} + // ChanType is a channel type. type ChanType struct { Dir ChanDir // 0, 1 or 2 @@ -494,9 +521,24 @@ func typeFromType(t reflect.Type) (Type, error) { if t.NumField() == 0 { return PredeclaredType("struct{}"), nil } + fields := make([]NamedField, 0, t.NumField()) + for i := 0; i < t.NumField(); i++ { + iField := t.Field(i) + iType, err := typeFromType(iField.Type) + if err != nil { + return nil, err + } + fields = append(fields, NamedField{ + Name: iField.Name, + Type: iType, + }) + } + return &StructType{ + Fields: fields, + }, nil } - // TODO: Struct, UnsafePointer + // TODO: UnsafePointer return nil, fmt.Errorf("can't yet turn %v (%v) into a model.Type", t, t.Kind()) } diff --git a/mockgen/parse.go b/mockgen/parse.go index 21c0d70a..0e11dc0a 100644 --- a/mockgen/parse.go +++ b/mockgen/parse.go @@ -33,7 +33,7 @@ import ( "strconv" "strings" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" ) var ( @@ -536,7 +536,13 @@ func (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]bool) (m return &model.PointerType{Type: t}, nil case *ast.StructType: if v.Fields != nil && len(v.Fields.List) > 0 { - return nil, p.errorf(v.Pos(), "can't handle non-empty unnamed struct types") + fields, err := p.parseStructFields(pkg, v.Fields, tps) + if err != nil { + return nil, err + } + return &model.StructType{ + Fields: fields, + }, nil } return model.PredeclaredType("struct{}"), nil case *ast.ParenExpr: @@ -595,6 +601,25 @@ func (p *fileParser) parseArrayLength(expr ast.Expr) (string, error) { } } +func (p *fileParser) parseStructFields( + pkg string, + fields *ast.FieldList, + tps map[string]bool, +) ([]model.NamedField, error) { + out := make([]model.NamedField, 0, fields.NumFields()) + for i := 0; i < fields.NumFields(); i++ { + typ, err := p.parseType(pkg, fields.List[i].Type, tps) + if err != nil { + return nil, err + } + out = append(out, model.NamedField{ + Name: fields.List[i].Names[0].Name, + Type: typ, + }) + } + return out, nil +} + // importsOfFile returns a map of package name to import path // of the imports in file. func importsOfFile(file *ast.File) (normalImports map[string]importedPackage, dotImports []string) { diff --git a/mockgen/parse_test.go b/mockgen/parse_test.go index 82c831f3..3c4ba4cf 100644 --- a/mockgen/parse_test.go +++ b/mockgen/parse_test.go @@ -50,7 +50,7 @@ func TestFileParser_ParsePackage(t *testing.T) { importedInterfaces: newInterfaceCache(), } - newP, err := p.parsePackage("github.com/golang/mock/mockgen/internal/tests/custom_package_name/greeter") + newP, err := p.parsePackage("go.uber.org/mock/mockgen/internal/tests/custom_package_name/greeter") if err != nil { t.Fatalf("Unexpected error: %v", err) } @@ -84,7 +84,7 @@ func checkGreeterImports(t *testing.T, imports map[string]importedPackage) { if validatorPackage, ok := imports["validator"]; !ok { t.Errorf("Expected imports to have key \"fmt\"") } else { - expectedValidatorPackage := "github.com/golang/mock/mockgen/internal/tests/custom_package_name/validator" + expectedValidatorPackage := "go.uber.org/mock/mockgen/internal/tests/custom_package_name/validator" if validatorPackage.Path() != expectedValidatorPackage { t.Errorf("Expected validator key to have value %s but got %s", expectedValidatorPackage, validatorPackage.Path()) } @@ -94,7 +94,7 @@ func checkGreeterImports(t *testing.T, imports map[string]importedPackage) { if clientPackage, ok := imports["client"]; !ok { t.Errorf("Expected imports to have key \"client\"") } else { - expectedClientPackage := "github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1" + expectedClientPackage := "go.uber.org/mock/mockgen/internal/tests/custom_package_name/client/v1" if clientPackage.Path() != expectedClientPackage { t.Errorf("Expected client key to have value %s but got %s", expectedClientPackage, clientPackage.Path()) } diff --git a/mockgen/reflect.go b/mockgen/reflect.go index 4f86a151..bcb1319d 100644 --- a/mockgen/reflect.go +++ b/mockgen/reflect.go @@ -32,7 +32,7 @@ import ( "strings" "text/template" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" ) var ( @@ -169,8 +169,8 @@ func runInDir(program []byte, dir string) (*model.Package, error) { if err := cmd.Run(); err != nil { sErr := buf.String() if strings.Contains(sErr, `cannot find package "."`) && - strings.Contains(sErr, "github.com/golang/mock/mockgen/model") { - fmt.Fprint(os.Stderr, "Please reference the steps in the README to fix this error:\n\thttps://github.com/golang/mock#reflect-vendoring-error.\n") + strings.Contains(sErr, "go.uber.org/mock/mockgen/model") { + fmt.Fprint(os.Stderr, "Please reference the steps in the README to fix this error:\n\thttps://go.uber.org/mock#reflect-vendoring-error.\n") return nil, err } return nil, err @@ -198,7 +198,7 @@ import ( "path" "reflect" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" pkg_ {{printf "%q" .ImportPath}} ) diff --git a/sample/concurrent/concurrent.go b/sample/concurrent/concurrent.go index 1fb943a4..d1ebda90 100644 --- a/sample/concurrent/concurrent.go +++ b/sample/concurrent/concurrent.go @@ -1,7 +1,7 @@ // Package concurrent demonstrates how to use gomock with goroutines. package concurrent -//go:generate mockgen -destination mock/concurrent_mock.go github.com/golang/mock/sample/concurrent Math +//go:generate mockgen -destination mock/concurrent_mock.go go.uber.org/mock/sample/concurrent Math type Math interface { Sum(a, b int) int diff --git a/sample/concurrent/concurrent_test.go b/sample/concurrent/concurrent_test.go index 878ac427..4c4ae279 100644 --- a/sample/concurrent/concurrent_test.go +++ b/sample/concurrent/concurrent_test.go @@ -5,9 +5,9 @@ import ( "context" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" - mock "github.com/golang/mock/sample/concurrent/mock" + mock "go.uber.org/mock/sample/concurrent/mock" ) func call(ctx context.Context, m Math) (int, error) { diff --git a/sample/concurrent/mock/concurrent_mock.go b/sample/concurrent/mock/concurrent_mock.go index 301a5bf3..055fde70 100644 --- a/sample/concurrent/mock/concurrent_mock.go +++ b/sample/concurrent/mock/concurrent_mock.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/sample/concurrent (interfaces: Math) +// Source: go.uber.org/mock/sample/concurrent (interfaces: Math) // Package mock_concurrent is a generated GoMock package. package mock_concurrent @@ -7,7 +7,7 @@ package mock_concurrent import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockMath is a mock of Math interface. diff --git a/sample/mock_user_test.go b/sample/mock_user_test.go index 1e630d2e..a67005c0 100644 --- a/sample/mock_user_test.go +++ b/sample/mock_user_test.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/sample (interfaces: Index,Embed,Embedded) +// Source: go.uber.org/mock/sample (interfaces: Index,Embed,Embedded) // Package user_test is a generated GoMock package. package user_test @@ -14,11 +14,11 @@ import ( reflect "reflect" template0 "text/template" - gomock "github.com/golang/mock/gomock" - imp1 "github.com/golang/mock/sample/imp1" - imp2 "github.com/golang/mock/sample/imp2" - imp3 "github.com/golang/mock/sample/imp3" - imp_four "github.com/golang/mock/sample/imp4" + gomock "go.uber.org/mock/gomock" + imp1 "go.uber.org/mock/sample/imp1" + imp2 "go.uber.org/mock/sample/imp2" + imp3 "go.uber.org/mock/sample/imp3" + imp_four "go.uber.org/mock/sample/imp4" ) // MockIndex is a mock of Index interface. @@ -56,6 +56,32 @@ func (mr *MockIndexMockRecorder) Anon(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Anon", reflect.TypeOf((*MockIndex)(nil).Anon), arg0) } +// AnonStructReturn mocks base method. +func (m *MockIndex) AnonStructReturn() struct { + ValueA string + ValueB imp1.Imp1 + Nested struct { + Value int + } +} { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AnonStructReturn") + ret0, _ := ret[0].(struct { + ValueA string + ValueB imp1.Imp1 + Nested struct { + Value int + } + }) + return ret0 +} + +// AnonStructReturn indicates an expected call of AnonStructReturn. +func (mr *MockIndexMockRecorder) AnonStructReturn() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AnonStructReturn", reflect.TypeOf((*MockIndex)(nil).AnonStructReturn)) +} + // Chan mocks base method. func (m *MockIndex) Chan(arg0 chan int, arg1 chan<- hash.Hash) { m.ctrl.T.Helper() diff --git a/sample/user.go b/sample/user.go index adb041e1..2776c2f7 100644 --- a/sample/user.go +++ b/sample/user.go @@ -1,32 +1,29 @@ // Package user is an example package with an interface. package user -//go:generate mockgen -destination mock_user_test.go -package user_test github.com/golang/mock/sample Index,Embed,Embedded +//go:generate mockgen -destination mock_user_test.go -package user_test go.uber.org/mock/sample Index,Embed,Embedded // Random bunch of imports to test mockgen. import ( - "io" - btz "bytes" "hash" + // Two imports with the same base name. + t1 "html/template" + "io" "log" "net" "net/http" - - // Two imports with the same base name. - t1 "html/template" - t2 "text/template" - "github.com/golang/mock/sample/imp1" + "go.uber.org/mock/sample/imp1" // Dependencies outside the standard library. - renamed2 "github.com/golang/mock/sample/imp2" + renamed2 "go.uber.org/mock/sample/imp2" - . "github.com/golang/mock/sample/imp3" + . "go.uber.org/mock/sample/imp3" - imp_four "github.com/golang/mock/sample/imp4" + imp_four "go.uber.org/mock/sample/imp4" ) // calls itself "imp_four" @@ -46,6 +43,14 @@ type Index interface { // A method with an anonymous argument. Anon(string) + // A method with an anoymous struct return + AnonStructReturn() struct { + ValueA string + ValueB imp1.Imp1 + Nested struct { + Value int + } + } // Methods using foreign types outside the standard library. ForeignOne(imp1.Imp1) diff --git a/sample/user_test.go b/sample/user_test.go index 35cfa0f1..4c7d93c8 100644 --- a/sample/user_test.go +++ b/sample/user_test.go @@ -4,9 +4,9 @@ package user_test import ( "testing" - "github.com/golang/mock/gomock" - user "github.com/golang/mock/sample" - "github.com/golang/mock/sample/imp1" + "go.uber.org/mock/gomock" + user "go.uber.org/mock/sample" + "go.uber.org/mock/sample/imp1" ) func TestRemember(t *testing.T) {