Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a new flag that makes the generated constructor function private #42

Open
sakuradon99 opened this issue Jul 17, 2023 · 1 comment · May be fixed by #201
Open

Provide a new flag that makes the generated constructor function private #42

sakuradon99 opened this issue Jul 17, 2023 · 1 comment · May be fixed by #201
Labels
enhancement New feature or request

Comments

@sakuradon99
Copy link

In my code, there are some private interfaces that should only be accessed within the current package. However, when I use gomock to generate mock code, other packages can call NewmockXXX to create a mock of those interfaces, which is not what we expect. I would like to achieve a functionality similar to the following:

...
	private            = flag.Bool("private", false, "Generate private constructor functions for all mocks")
...
...
	newStr := "New"
	if *private {
		newStr = "new"
	}
	g.p("// "+newStr+"%v creates a new mock instance.", mockType)
	g.p("func "+newStr+"%v%v(ctrl *gomock.Controller) *%v%v {", mockType, longTp, mockType, shortTp)
	g.in()
...
@JacobOaks JacobOaks added the enhancement New feature or request label Aug 1, 2023
@tulzke
Copy link
Contributor

tulzke commented Nov 13, 2023

I see three use cases:

  1. Generate public mocks for all interfaces.
  2. Generate private mocks for all interfaces
  3. Generate public mocks for public interfaces, private for private ones.

Maybe it's better to make "private" a flag with multiple string values, like "exlude_interfaces" or "mock_names"?

@tulzke tulzke linked a pull request Sep 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants