mock icon indicating copy to clipboard operation
mock copied to clipboard

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

Open AndrewDK opened this issue 2 years ago • 2 comments

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

AndrewDK avatar May 20 '22 15:05 AndrewDK

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

codyoss avatar May 26 '22 20:05 codyoss

This code is invalid, its bugs

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

junmaqiang avatar Jan 26 '23 06:01 junmaqiang