moq generates mocks with internal package imports
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 2.2k
- Forks
- 135
- Avg merge
- 11d 6h
- Merged PRs (30d)
- 1
Description
In some situations, moq generates mocks that try to import internal 3rd party packages. Minimal example below.
example.go
```go
package app
import (
"context"
pubsub_api "cloud.google.com/go/pubsub"
)
type IPubSubTopic interface {
Exists(ctx context.Context) (bool, error)
Publish(ctx context.Context, msg *pubsub_api.Message) *pubsub_api.PublishResult
}
```
Here pubsub_api is an explicit alias to the public package.
Generate mock:
```
moq -out example_mock.go . IPubSubTopic
```
example_mock.go
```go
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package app
import (
"cloud.google.com/go/internal/pubsub"
"context"
"sync"
)
// Ensure, that IPubSubTopicMock does implement IPubSubTopic.
// If this is not the case, regenerate this file with moq.
var _ IPubSubTopic = &IPubSubTopicMock{}
```
But the mock imports the internal pubsub package instead. I couldn't find any way to prevent it.
go version go1.15.6 linux/amd64
moq version: v0.2.3
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the provided example.go interface and the `moq -out example_mock.go . IPubSubTopic` command, then inspect the generated example_mock.go imports. Done means the generated mock preserves the public cloud.google.com/go/pubsub import and no longer references the internal package; verify the result with the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100