gojuno/minimock

generating a file that doesn't compile

Closed this issue · 3 comments

ovesh commented

Minimock is generating a file that doesn't compile:
go run github.com/gojuno/minimock/v3/cmd/minimock -g -i k8s.io/client-go/kubernetes/typed/core/v1.ServiceInterface

The generated file is referencing a package (restclient) that isn't being imported.

minimock version: v3.0.9
k8s.io/client-go version: v0.21.3

ovesh commented

ServiceInterface is embedding another interface ServiceExpansion which is bringing in an extra function ProxyGet. The package for the return type for that function (k8s.io/client-go/rest) isn't being imported.

ovesh commented

This is actually a bug in github.com/hexdigest/gowrap, at least in v1.1.8 (confirmed that the bug is still there in newer versions). Specifically, the list of import added here doesn't contain the extra import needed for the return value for an embedded Interface brought in from another file.

The code assumes that adding all the imports from the source file where the interface is defined is sufficient. Unfortunately there's no easy fix for this. We could try and find the file where any embedded interface is defined and add all the imports from there, but

  1. The embedded interface might be defined in a completely different module
  2. Adding all the imports from that file might result in adding unused imports.

Hey, I'm unable to reproduce this because k8s.io/client-go/kubernetes/typed/core/v1.ServiceInterface is gone forever I guess.

Feel free to re-open if you find another way to repro this.