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

Mockery mistakenly imports internal packages when running the 'mockery' command #749

Closed
1 of 5 tasks
NawafSwe opened this issue Jan 20, 2024 · 2 comments
Closed
1 of 5 tasks

Comments

@NawafSwe
Copy link

Description

I am creating a mock for my Google Pub/Sub client to be tested without making actual calls to Google Pub/Sub. I am mocking an interface defined below.

package messaging

import (
	"context"
	"cloud.google.com/go/pubsub"
	"google.golang.org/grpc/status"
)

type MessageSender interface {
	PublishAsync(ctx context.Context, topicId string, msg *pubsub.Message)
}
type MessageService interface {
	MessageSender
	CreateSub(id string, topic *pubsub.Topic)
	CreateTopic(topic string) *pubsub.Topic
	GetSubscription(ctx context.Context, id string) (*pubsub.Subscription, error)
	CreateTopicWithSchema(topic string, tc pubsub.TopicConfig)
	GetTopic(ctx context.Context, topicId string) (*pubsub.Topic, error)
}

And here is my mockery config

with-expecter: true
packages:
  github.com/nawafswe/repoName/pkg/messaging:
    config:
    interfaces:
      MessageService:

Running the command mockery in the root directory successfully generates files for the mocked interfaces. However, the issue is that it is importing internal packages, as shown in the picture below.
Screenshot 2024-01-20 at 7 46 01 PM

Mockery Version

v2.40.1

Golang Version

1.21.6 darwin/arm64

Installation Method

  • Binary Distribution
  • Docker
  • brew
  • go install
  • Other: [specify]

Steps to Reproduce

  1. Run mockery
  2. File generated with wrong imports
  3. Running test cases will fail as shown below

Expected Behavior

The expected behavior is to import from a public package. I had to modify it to make it work, as shown below in the picture:

Screenshot 2024-01-20 at 7 59 08 PM

Actual Behavior

Importing from the incorrect location, as shown above, is not allowed. As a result, test cases won't run, as illustrated below:
Screenshot 2024-01-20 at 8 02 48 PM

Thanks, in advance for your help, and I hope I made it clear 🙏🏻

@LandonTClipp
Copy link
Collaborator

You want to use replacetypes: https://vektra.github.io/mockery/latest/features/#replace-types

Let me know if that helps.

@NawafSwe
Copy link
Author

It worked, thank you very much, sorry for the inconvenience 🙏🏻

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

2 participants