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

"could not import" #81

Closed
atombender opened this issue May 21, 2016 · 10 comments
Closed

"could not import" #81

atombender opened this issue May 21, 2016 · 10 comments

Comments

@atombender
Copy link
Contributor

$ mockery -name=Client -case=underscore
Error parsing file:  client_test.go:14:2: could not import github.com/stretchr/testify/assert (can't find import: github.com/t11e/go-pebbleclient/vendor/github.com/stretchr/testify/assert)
Error parsing file:  client_test.go:14:2: could not import github.com/stretchr/testify/assert (can't find import: github.com/t11e/go-pebbleclient/vendor/github.com/stretchr/testify/assert)
Error parsing file:  client_test.go:14:2: could not import github.com/stretchr/testify/assert (can't find import: github.com/t11e/go-pebbleclient/vendor/github.com/stretchr/testify/assert)
Error parsing file:  client_test.go:14:2: could not import github.com/stretchr/testify/assert (can't find import: github.com/t11e/go-pebbleclient/vendor/github.com/stretchr/testify/assert)
Error parsing file:  client_test.go:14:2: could not import github.com/stretchr/testify/assert (can't find import: github.com/t11e/go-pebbleclient/vendor/github.com/stretchr/testify/assert)
Error parsing file:  client_test.go:14:2: could not import github.com/stretchr/testify/assert (can't find import: github.com/t11e/go-pebbleclient/vendor/github.com/stretchr/testify/assert)
Error parsing file:  client_test.go:14:2: could not import github.com/stretchr/testify/assert (can't find import: github.com/t11e/go-pebbleclient/vendor/github.com/stretchr/testify/assert)
Error parsing file:  client_test.go:14:2: could not import github.com/stretchr/testify/assert (can't find import: github.com/t11e/go-pebbleclient/vendor/github.com/stretchr/testify/assert)
Unable to find Client in any go files under this path
exit status 1

$ ls vendor/github.com/stretchr/testify/assert   
assertion_forward.go       assertions.go       doc.go     forward_assertions.go       http_assertions.go
assertion_forward.go.tmpl  assertions_test.go  errors.go  forward_assertions_test.go  http_assertions_test.go

$ pwd
/Users/alex/.go/src/github.com/t11e/go-pebbleclient

$ echo $GOPATH
/Users/alex/.go

Works with every other project I have, just not exactly this one. The project compiles and tests fine, there's nothing unusual about it. Same versions of Mockery and Testify, too.

@deadok22
Copy link

Same problem here. Reverting to 47a058062601e235731714f89d7ec95c1ec47a5e worked for me.

@janeczku
Copy link

Same problem here.

@joshk0
Copy link
Contributor

joshk0 commented Jun 2, 2016

For those trying to cope with the new version, I found that you need to go install any dependent package for the mock's target package. In the OP's example, you would have to go install github.com/stretchr/testify/assert first.

@jameshartig
Copy link

It looks like b0804d5de476de92a560fa451fa56167806ccdb6 broke it. If I checkout the commit before that, it works fine but anything including that commit breaks.

@atombender
Copy link
Contributor Author

It does look like @joshk0 is right, and that mockery doesn't understand vendor. I think he means go get, not go install, though.

@jameshartig
Copy link

The error is coming from https://github.com/vektra/mockery/blob/master/mockery/parse.go#L67. And that comment above that block makes me think that it requires pkg files for the package for it to work which is why go install works.

@atombender
Copy link
Contributor Author

atombender commented Jun 3, 2016

Ah yes, I remember now — go/types apparently only works with installed packages. The Atom package go-plus had this same issue (syntax linting would only work if you installed your project, which is of course nonsensical).

@jameshartig
Copy link

Looks like golang/go#11415 recommends to use golang.org/x/tools/go/loader instead of go/types.

@etamponi
Copy link

The same issue holds for me, I had to revert to 47a0580 as suggested in #81 (comment)

@wingsofovnia
Copy link

Workaround:

cd $GOPATH/src/github.com/vektra/mockery/
git checkout 47a058062601e235731714f89d7ec95c1ec47a5e
go get -u github.com/vektra/errors
go install -a github.com/vektra/mockery/.../

Thanks @deadok22

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

7 participants