Skip to content

tiriplicamihai/fixture-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fixture-generator

fixture-generator provides an easy way to generate fixtures for Go structs. It aims to reduce the time one spends writing tests. It works using a "best effort" approach - if we can't generate data for a field then ignore it and return a partally complete fixture.

I do have more time to spend on this project so if you have suggestions or any kind of feedback I am more than happy to hear it and implement it as soon as possible.

Installation

go get github.com/tiriplicamihai/fixture-generator/.../, then $GOPATH/bin/fixturegen

Examples

Consider we have the next struct:

package test

type Person struct {
        Name             string
        Age              int
        Friends          []string
}

Run: fixturegen -struct Person and the following will be output to stdout:

Person{
	Name: "QuZNvyPcKeEp",
	Age: 651906,
	Friends: []string{"GMV", "dKFjsoGexcbs", "cC"},
}

Tip: You can use fixturegen -struct Person | gofmt to get a formatted fixture.

Command Line Arguments

  • struct - required argument, expects the struct name for which the fixture will be generated

Fixtures can be generated even if field types are from other packages. It performs a recursive discovery for the types it finds in a package.

Known Limitations

  • Fixtures can not be generated for fields declared as interfaces because we can't know the actual type
  • Fixtures can not be generated for a struct that has a self referencing field (we would go in an infinite loop)
  • Types from vendored external packages are not supported for now

Credits

About

Command Line Tool For Generating Golang Fixtures

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages