Gamazic / stubgen

Go tool for generating stubs from interfaces

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

stubgen

A Golang library for generating interface stubs. Stubs make it easy to test a project in a table-driven style.

For an example of an easy-to-test approach, refer to the example directory.

Currently, the stubgen doesn't support generic interfaces.

Installation

go install github.com/Gamazic/stubgen@latest

Example

Have a Go module with the following content:

mymodule.go

package testdata

type MyInterface interface {
	Func(int, bool) error
}

To generate a stub for the file, use the command with the --inp-file argument:

stubgen --inp-file testdata/testfile.go

Result in console:

// Code generated by stubgen; DO NOT EDIT.

package testdata

type StubMyInterface struct {
	FuncRes0 error
}

func (s StubMyInterface) Func(_ int, _ bool) error {
	return s.FuncRes0
}

Alternatively, you can provide source code from stdin:

cat mymodule.go | stubgen

To save data in a file, use the --out-file argument:

stubgen --inp-file mymodule.go --out-file mymodule_stub.go

For more examples you can check example directory or testdata directory.

About

Go tool for generating stubs from interfaces

License:Apache License 2.0


Languages

Language:Go 100.0%