Skip to content

Go Faker designed to work with go-openapi/strfmt and Struct field tag interpolation

License

Notifications You must be signed in to change notification settings

the0rem/go-fakeit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-fakeit

Go Report Card Coverage Status Godoc Release

Go Fakeit provides a way to automatically fake data from Go Structs. It is designed to work with both builtin Go Data Types as well as go-openapi/strfmt Data Types.

It comes with support for Struct Field Tag interpolation to set specific fakers for Struct Fields.

TODO

  • Handle faking Interface, Map & Chanel Struct Fields
  • Complete test coverage for handlers and fakers
  • Add godocs for public functions
  • Add handling for limiting recursion depth of circular dependencies
  • Add Struct Field Tag option to omit Field from being faked

Available Fakers

Fakeit implements the available fakers in the https://github.com/icrowley/fake package. Available fakers can be found on Godoc

Available Handlers

Fakeit comes with support for all builtin Go Types, as well as all go-openapi/strfmt Types. The default fakers which are used for handling each Data Type can be found in the Godoc

Using tags to specify faker rules

The fakeit Tag can be used on Struct Fields to specify faker behaviour. The examples below describe how to utilise the functionality.

Example 1 - Overriding the default faker:

type AwesomeThing struct {
  ID            strfmt.UUID
  Name          string `fakeit:"password,min=25,max=30"`
  Description   *string `fakeit:"paragraph"`
}

Example 2 - Omitting a Field form being faked:

There are cases where you don't want to populate a certain field in a struct (such as when generating data for inserting into a database). In this case the field can be annotated with a hyphen (-). This follows the convention set the the JSON package in Go.

type AwesomeThing struct {
  ID        strfmt.UUID
  Name      string
  DeletedAt *string `fakeit:"-"`
}

The result will be:

thing := AwesomeThing{}
fakeit.Fakeit(&thing)
fmt.Printf("%+v\n", thing)

// Prints output:
// &{ID:34b7a0d3-c753-11e7-9dd1-dca90491e849 Name:Stagorchid DeletedAt:<nil>}

About

Go Faker designed to work with go-openapi/strfmt and Struct field tag interpolation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages