Skip to content

moq generates mocks with internal package imports #153

@d-lowl

Description

@d-lowl

In some situations, moq generates mocks that try to import internal 3rd party packages. Minimal example below.

example.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

// 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions