Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Does -imports work? Package alias is inconsistent, and -imports does not fix it. #646

Open
AndrewDK opened this issue May 20, 2022 · 2 comments · Fixed by uber-go/mock#41

Comments

@AndrewDK
Copy link

Actual behavior A clear and concise description of what the bug is.

The package alias produced by mockgen is variable for the same inputs. Specifically, sometimes we see
extract "github.com/codeclysm/extract/v3"
and others we see
v3 "github.com/codeclysm/extract/v3"
Also, using -imports extract=github.com/codeclysm/extract/v3 does not have any effect on the output.

Expected behavior A clear and concise description of what you expected to happen.

I expect the same inputs to product the same outputs.
I expect -imports to determine the package alias.

To Reproduce Steps to reproduce the behavior

  1. This program creates a mock file with no mention of cheesecake, as expected. Am I using -imports correctly, and is that the effect it's supposed to have?
package main

import (
	"context"
	"io"

	"github.com/codeclysm/extract/v3"
)

//go:generate go run github.com/golang/mock/mockgen -destination=mock_if.go -package main -source ./gomocktest.go -imports cheesecake=github.com/codeclysm/extract/v3

type IF interface {
	ExtractGz(ctx context.Context, body io.Reader, location string, renamer extract.Renamer) error
	ExtractZip(ctx context.Context, body io.Reader, location string, renamer extract.Renamer) error
}

func main() {
	print("hello world")
}

Additional Information

  • gomock mode (reflect or source): Source, run from go generate although running directly has the same output.
  • gomock version or git ref: github.com/golang/mock v1.6.0
  • golang version: 1.17

Triage Notes for the Maintainers

@codyoss
Copy link
Member

codyoss commented May 26, 2022

It seems like there is at least one or two bugs here. Needs further investigation, happy to take contributions.

@junmaqiang
Copy link

This code is invalid, its bugs

-imports cheesecake=github.com/codeclysm/extract/v3

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants