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

Failing to generate mocks on 1.13 #103

Closed
johanbrandhorst opened this issue Sep 17, 2019 · 6 comments · Fixed by #105
Closed

Failing to generate mocks on 1.13 #103

johanbrandhorst opened this issue Sep 17, 2019 · 6 comments · Fixed by #105

Comments

@johanbrandhorst
Copy link

This command works with go 1.12:

$ moq -out mocks/client.mock.go -pkg mocks ../../vendor/github.com/aws/aws-sdk-go-v2/service/acmpca/acmpcaiface ACMPCAAPI

but breaks badly with go 1.13:

$ moq -out mocks/client.mock.go -pkg mocks ../../vendor/github.com/aws/aws-sdk-go-v2/service/acmpca/acmpcaiface ACMPCAAPI
Couldn't load mock package: go [list -e -json -compiled -test=false -export=false -deps=false -find=true --]: exit status 1: build .: cannot find module for path .

moq [flags] destination interface [interface2 [interface3 [...]]]
  -out string
        output file (default stdout)
  -pkg string
        package name (default will infer)

Same version of moq in both cases, github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd, e.g., current master.

@johanbrandhorst johanbrandhorst changed the title -pkg flag failing with 1.13 Failing to generate mocks on 1.13 Sep 17, 2019
@johanbrandhorst
Copy link
Author

The examples are from running go generate in https://github.com/johanbrandhorst/certify/tree/master/issuers/aws. There seems to be something about the aws interface that breaks it.

@Agronis
Copy link

Agronis commented Sep 20, 2019

I might suggest importing the interface and assigning it to a new type local to that package, it is what I am doing with the /service/s3/s3iface interface

package main

import "github.com/aws/aws-sdk-go-v2/service/acmpca/acmpcaiface"

//go:generate moq -out s3_moq_test.go . MockAPI
type MockAPI = acmpcaiface.ClientAPI

Tested, and this generates with ease.

@johanbrandhorst
Copy link
Author

Cool, thanks for the workaround!

@fredbi
Copy link

fredbi commented Sep 21, 2019

@johanbrandhorst had the same problem, but it did work with go1.13 on local dev, while repeatedly failing on CI. My guess is that the version of "golang.org/x/tools" package is subtly modified (see also #98).

The problem appears specifically when using the -pkg option.

As a workaround for the "go list..." issue complaining that the mocked package is not here, I prepared an empty valid go file just for this to pass.

mkdir -p {mockpackage}
echo "package {mockpackage}" > {mockpackage}/{generated}.go

@johanbrandhorst
Copy link
Author

I might suggest importing the interface and assigning it to a new type local to that package, it is what I am doing with the /service/s3/s3iface interface

package main

import "github.com/aws/aws-sdk-go-v2/service/acmpca/acmpcaiface"

//go:generate moq -out s3_moq_test.go . MockAPI
type MockAPI = acmpcaiface.ClientAPI

This is unfortunately unacceptable as it changes the public API of the package. It seems I will have to keep using 1.12 for now.

@pdrum
Copy link
Contributor

pdrum commented Oct 3, 2019

I'm having the same issue

pdrum added a commit to pdrum/moq that referenced this issue Oct 3, 2019
pdrum added a commit to pdrum/moq that referenced this issue Oct 3, 2019
matryer pushed a commit that referenced this issue Nov 3, 2019
* Fix moq for go 1.13 and avoid creating empty directory

This fixes #103 and also fixes #102

* Update .travis.yml
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