fillit

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 7 Imported by: 0

README

Fill It Docs

Description

Fill It is a simple tool that allows you to fill random values for almost all Go types.
It is useful for testing and generating random data.

The package is inspired by faker.
This package provides more customization options for data generation, such as global type data providers or setting a provider for a field by its path.

Go Report License GoDoc


Installation

go get github.com/yanodincov/fillit

Example

Types

Fully Supported Types
  • bool
  • int{,8,16,32,64}
  • uint{,8,16,32,64}
  • float{32,64}
  • complex{64,128}
  • string
  • array
  • slice
  • map
  • struct
  • pointer

All these types, and any combinations of them, are supported, such as:

  • Nested structs
  • Custom types using any supported types
  • Slice of structs
  • Structs with circular references
Not Supported Types
  • interface
  • channel
  • function
  • uintptr

These types are not supported and will be ignored. However, you can fill interface types with this package if you define a custom provider for them.

Benchmarks

Tested structures
type simpleTypeStruct struct {
	Str string
	Arr [3]int
	Int int
	Bol bool
}

type simpleNestedTypeStruct struct {
	Map   map[int]string
	Slice []int
	Bs1   simpleTypeStruct
}

type doubleNestedFileStruct struct {
	Map   map[string]simpleNestedTypeStruct
	Slice []simpleNestedTypeStruct
	Bs2   simpleNestedTypeStruct
}

type tripleNestedFileStruct struct {
	Map   map[simpleTypeStruct]doubleNestedFileStruct
	Slice []doubleNestedFileStruct
	Bs3   doubleNestedFileStruct
}
Results (Fill It)
BenchmarkFill/simple_type-8             397930    3032 ns/op
BenchmarkFill/simple_nested_struct-8    76544	  15469 ns/op
BenchmarkFill/double_nested_struct-8    3692	  325196 ns/op
BenchmarkFill/triple_nested_struct-8    168       7071680 ns/op
Results (faker) (with the same structs)
BenchmarkFakerFill/simple_type-8             167934    7109 ns/op
BenchmarkFakerFill/simple_nested_struct-8    41426     29000 ns/op
BenchmarkFakerFill/double_nested_struct-8    2096      566001 ns/op
BenchmarkFakerFill/triple_nested_struct-8    100       11944321 ns/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fill

func Fill[T any](opts ...cfg.FillOptFn) (T, error)

Fill generates and return a filled value of the given type.

Function can fill next types:

  • all comparable types (int, string, bool, etc.);
  • slices;
  • maps;
  • structs;
  • any constructions with above types, like slices of structs, nested structs, even nested structs with circular references;

By default, Fill uses default configuration. You can see get it via cfg.GetDefaultFillCfg. If you want to use different configuration, you can pass it via cfg.FillOptFn in opts arg or change global configuration using cfg.ModifyDefaultFillCfg..

func FillT

func FillT[T any](tb testing.TB, opts ...cfg.FillOptFn) T

FillT wraps Fill function and adds testing.TB as first argument for error handling.

Check Fill function for more details.

Types

This section is empty.

Directories

Path Synopsis
example
simple command
struct command
internal
gen

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL