derision-test / go-mockgen

MIT License
58 stars 8 forks source link

Way to add mocks right next to the file they are defined in #12

Closed fr3fou closed 3 years ago

fr3fou commented 3 years ago

Continued from #11

I'm interested in the ability to do something along these lines

$ go-mockgen github.com/fr3fou/foo/bar --output-as-test 
$ cat bar/baz.go
package bar

type Baz interface {
    Bazing() string
}
$ cat bar/baz_mock_test.go
package baz_test

// Mock generated here
// ...
efritz commented 3 years ago

The package name in the mock here is different from the source. Did you mean to use bar or bar_test by chance, or should the package name also somehow match the generated struct?

fr3fou commented 3 years ago

The package name in the mock here is different from the source. Did you mean to use bar or bar_test by chance, or should the package name also somehow match the generated struct?

The second package should've been called baz_test; I edited my example

efritz commented 3 years ago

@fr3fou Sorry for the delay (I thought this would be harder due to mutually exclusive flags). See #14 for a sample implementation. I've added a --for-test flag that modifies the (supplied or inferred) filename and package names by appeding a _test suffix for both.

Is there any other behavior you'd like turned on by default when this flag is supplied?