Closed spolischook closed 1 year ago
Okay, so it seems like if the interface relates to the struct from the same package it will have "self include" issue in the mock.
For example code:
package something
//go:generate moq -pkg something -out ./doable_mock.go . DoableInterface:Mock
type DoableInterface interface {
Do() Response
}
type Response struct {
}
will generate the mock with self include:
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package something
import (
"github.com/spolischook/moqIssue/something" // <--- this is actually the issue!
"sync"
)
...
type Mock struct {
// DoFunc mocks the Do method.
DoFunc func() something.Response
...
Is this expected behavior? or what I'm doing wrong?
It happens because of -pkg something
parameter - without it, it works well
Somehow in the mock, moq generated import that import package itself So after the second generate command I've got:
An Interface used
Response
type as a returned value, and it's generated in mock asapi.Response
. If I remove import by hand and removeapi.
prefix from the type it works.