matryer / moq

Interface mocking tool for go generate
http://bit.ly/meetmoq
MIT License
2k stars 127 forks source link

Failing to generate mocks on 1.13 #103

Closed johanbrandhorst closed 5 years ago

johanbrandhorst commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

Cool, thanks for the workaround!

fredbi commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

I'm having the same issue