github.com/golang/mock@v1.6.0/mockgen/internal/tests/custom_package_name/README.md (about)

     1  # Tests for custom package names
     2  
     3  This directory contains test for mockgen generating mocks when imported package
     4  name does not match import path suffix. For example, package with name "client"
     5  is located under import path "github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1".
     6  
     7  Prior to this patch:
     8  
     9  ```bash
    10  $ go generate greeter/greeter.go
    11  2018/03/05 22:44:52 Loading input failed: greeter.go:17:11: failed parsing returns: greeter.go:17:14: unknown package "client"
    12  greeter/greeter.go:1: running "mockgen": exit status 1
    13  ```
    14  
    15  This can be fixed by manually providing `-imports` flag, like `-imports client=github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1`.
    16  But, mockgen should be able to automatically resolve package names in such situations.
    17  
    18  With this patch applied:
    19  
    20  ```bash
    21  $ go generate greeter/greeter.go
    22  $ echo $?
    23  0
    24  ```
    25  
    26  Mockgen runs successfully, produced output is equal to [greeter_mock_test.go](greeter/greeter_mock_test.go) content.