traefik / mocktail

Naive code generator that creates mock implementation using testify.mock

Home Page:https://traefik.io/blog/mocktail-the-mock-generator-for-strongly-typed-mocks/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[feature request] allow specifying interfaces to be mocked via mocktail argument (vs mock_test.go)

tigerinus opened this issue · comments

In our project, we use a codegen https://github.com/deepmap/oapi-codegen to generate client under a path ./codegen and this path is ignored in .gitignore (for obvious reason - the code is generated on the fly per build)

The codegen automatiically creates a ClientInterface interface, e.g.

// The interface specification for the client above.
type ClientInterface interface {
	// SubscribeActionWS request
	SubscribeActionWS(ctx context.Context, sourceId SourceID, params *SubscribeActionWSParams, reqEditors ...RequestEditorFn) (*http.Response, error)

	// TriggerAction request with any body
	TriggerActionWithBody(ctx context.Context, sourceId SourceID, name ActionName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	TriggerAction(ctx context.Context, sourceId SourceID, name ActionName, body TriggerActionJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	// GetActionTypes request
	GetActionTypes(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

	// RegisterActionTypes request with any body
	RegisterActionTypesWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	RegisterActionTypes(ctx context.Context, body RegisterActionTypesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

Because ./codegen is ignored, to use mocktail we will have to inconveniently create a mock_test.go as part of the build process before calling mocktail.

It'd be nice to allow passing ClientInterface (together with package name/path) via mocktail arguments. E.g.

mocktail --interface ./codegen#ClientInterface