DEV Community

loading...

Feedback about the go-mock script that create mocks for all automatically and recursively detected Go interfaces

Tymoteusz Blazejczyk
Professional FPGA and Embedded Systems Design Engineer. Expert in a true modern FPGA development adopting the newest software development trends and patterns. Knowledge and experience in RTL/SW/FW dev
・1 min read

Recently I have working on a project that allow to work on Go projects out-of-box using a Docker image.

It contains preinstalled tools for developing, mocking, formatting, linting, building, testing and documenting Go projects.

For mocking Go interfaces, I'm using the standard and classic mockgen tool in reflect mode. One of annoying thing about that tool is command line invocations.

I have scripted that to automatically and recursively detect all Go interfaces. It excludes _test.go files, mocks directories and the package main.

Go module detection is based on the go env GOMOD command invocation. All mocks are generated under the mocks directory for given Go package.

For me it works well. But I may have miss something. And because of that, I want to ask you for a small feedback. In advance, I appreciate it for any comments :)

The go-mock script that covers this topic: https://gitlab.com/tymonx/docker-go/-/blob/master/scripts/go-mock

Project site: https://gitlab.com/tymonx/docker-go

I also hope, that it may be useful for someone ;)

Discussion (1)

Collapse
nicolasassi profile image
Nicolas Augusto Sassi

Your script is awesome! Thank you so much for sharing that