Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moq should not follow type aliases to internal packages #214

Open
davidmdm opened this issue Mar 27, 2024 · 0 comments
Open

moq should not follow type aliases to internal packages #214

davidmdm opened this issue Mar 27, 2024 · 0 comments

Comments

@davidmdm
Copy link

Moq resolves type aliases which can lead to non-compilable code.

For example:

package main

import (
	"context"

	"cloud.google.com/go/pubsub"
)

//go:generate moq -out ./receiver_mock.go . Receiver
type Receiver interface {
	Receive(ctx context.Context, f func(context.Context, *pubsub.Message)) error
}

In the google pubsub package Message is declared as:

import (
  ipubsub "cloud.google.com/go/internal/pubsub"
)

...

type Message = ipubsub.Message

And this the code generated by moq resolves the type alias and produces:

package main

import (
	"cloud.google.com/go/internal/pubsub" // ERROR CANNOT COMPILE BECAUSE OF INTERNAL IMPORT
	"context"
	"sync"
)

// Ensure, that ReceiverMock does implement Receiver.
// If this is not the case, regenerate this file with moq.
var _ Receiver = &ReceiverMock{}

...

Ideally moq would generate the code using the non-internal import inferred from the type alias.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant