Skip to content

Gamazic/stubgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.