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

Mock generation with NATS leads to import errors (version: 2.7.5) #419

Closed
coco-moiny opened this issue Nov 9, 2021 · 5 comments · Fixed by #490
Closed

Mock generation with NATS leads to import errors (version: 2.7.5) #419

coco-moiny opened this issue Nov 9, 2021 · 5 comments · Fixed by #490

Comments

@coco-moiny
Copy link

coco-moiny commented Nov 9, 2021

As raised in the past, generating mocks with "github.com/nats-io/nats.go" creates import issues.
See here: #249 (comment)

What creates the issue on the NATS side is related to their change of repo, see here: go-kit/kit#940 (comment)

The issue still up on 2.7.5, is the -exclude option still on the roadmap to have this fixed?

Here is the import issue represented.

// Code generated by mockery 2.8.0. DO NOT EDIT.

package mocks

import (
	nats "github.com/nats-io/" <-- Should be: "github.com/nats-io/nats.go"
	mock "github.com/stretchr/testify/mock"
)

// NATSClient is an autogenerated mock type for the NATSClient type
type NATSClient struct {
	mock.Mock
}

// Close provides a mock function with given fields:
func (_m *NATSClient) Close() {
	_m.Called()
}

// GetConnection provides a mock function with given fields:
func (_m *NATSClient) GetConnection() *nats.Conn {
	ret := _m.Called()

	var r0 *nats.Conn
	if rf, ok := ret.Get(0).(func() *nats.Conn); ok {
		r0 = rf()
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(*nats.Conn)
		}
	}

	return r0
}
@tehsphinx
Copy link

Note: having the same issue with mockery v2.12.2

@LandonTClipp
Copy link
Collaborator

So there are a lot of places in the code that check if the import path has .go in it. If it finds that, it assumes the path is a file path instead of a URL. The solution probably lies somewhere in that logic. PRs are welcome!

@tehsphinx
Copy link

tehsphinx commented May 30, 2022

What was the intention of that logic? In what use case is a file given instead of a URL?

EDIT: for whoever looks at this, it'd be the key question to have an answer to. Knowing which case it would break removing that logic or knowing how to differentiate the cases.

@LandonTClipp
Copy link
Collaborator

I did not write the original implementation so I can't speak with authority, but the code works with this abstract notion of "paths" that can either be a URL or a file path. It determines which one it is using that logic above, so my guess is that logic is just broken for projects appended with .go.

@albinou
Copy link

albinou commented Jun 6, 2022

I am using mockery with go generate.

I don't provide a clean solution but I temporarily "fixed" this issue by using 2 go:generate annotations:

//go:generate mockery --name=MyInterface
//go:generate sed -ri "s|nats \"github.com/nats-io/\"|nats \"github.com/nats-io/nats.go\"|" mocks/MyInterface.go

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

Successfully merging a pull request may close this issue.

4 participants