https://github.com/gamazic/stubgen
Go tool for generating stubs from interfaces
https://github.com/gamazic/stubgen
go stubs testing testing-tool
Last synced: about 1 month ago
JSON representation
Go tool for generating stubs from interfaces
- Host: GitHub
- URL: https://github.com/gamazic/stubgen
- Owner: Gamazic
- License: apache-2.0
- Created: 2024-02-15T18:21:03.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-17T11:40:12.000Z (over 2 years ago)
- Last Synced: 2025-01-02T21:48:44.576Z (over 1 year ago)
- Topics: go, stubs, testing, testing-tool
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](./example) directory.
Currently, the `stubgen` doesn't support generic interfaces.
## Installation
```shell
go install github.com/Gamazic/stubgen@latest
```
## Example
Have a Go module with the following content:
`mymodule.go`
```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:
```shell
stubgen --inp-file testdata/testfile.go
```
Result in console:
```go
// 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:
```shell
cat mymodule.go | stubgen
```
To save data in a file, use the `--out-file` argument:
```shell
stubgen --inp-file mymodule.go --out-file mymodule_stub.go
```
For more examples you can check [example](./example) directory or [testdata](./testdata) directory.