petergtz / pegomock

Pegomock is a powerful, yet simple mocking framework for the Go programming language
Apache License 2.0
252 stars 28 forks source link

Suggestions for Duplicate Interface Names #96

Open jpopadak opened 4 years ago

jpopadak commented 4 years ago

Do you have any suggestions for duplicate interface names?

For example, I have this type:

type StructUnderTest struct {
    firstClient first.Client
    secondClient second.Client
}
package first

type Client interface {
    Method()
}
package second

type Client interface {
   Method()
   AnotherMethod()
}

Both first.Client and second.Client are named the same.

As a result, when I try to create the mocks, I get two files, both with NewMockClient() in them. Is there anyway I can specify a way to override the function name? Like NewMockFirstClient() and NewMockSecondClient()?

I can change the package, but then I get issues with Go (and Linters) complaining there is more than one package in the same folder.

jpopadak commented 4 years ago

Thanks to a coworker, just found this option on pegomock generate:

--mock-name=MOCK-NAME Struct name of the generated mock; defaults to the interface prefixed with Mock

Should be sufficient enough for what I am trying to do. :) Might be useful to have an example of this as well in the README.

petergtz commented 4 years ago

@jpopadak Glad you found the way to solve it.

In general, I avoided documenting CLI options that are more or less obvious from the CLI help to avoid repeating the description. For such options, the README specifically says:

For more flags, run:

   pegomock --help

If you feel like this is still worth being documented explicitly, I'd be happy to merge a PR ;-).