some

package module
v0.0.0-...-069085c Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2018 License: MIT Imports: 6 Imported by: 1

README

some

CircleCI GoDoc Go Report Card codecov

Key based dumy data generator for testing.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Float64 is a default float spec.
	Float64 Float64Spec = Float64Spec{
		1,
		0,
	}
	// Float32 is a default float spec.
	Float32 Float32Spec = Float32Spec{
		1,
		0,
	}
)
View Source
var (
	// GlobalRand is a default random number generator.
	GlobalRand *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))
	// GlobalCache is a default cache store.
	GlobalCache map[string]interface{} = make(map[string]interface{})
)
View Source
var (
	// Int is a default int spec.
	Int IntSpec = IntSpec{
		math.MaxInt32,
		0,
	}
	// Int64 is a default int64 spec.
	Int64 Int64Spec = Int64Spec{
		math.MaxInt64,
		0,
	}
)

Functions

This section is empty.

Types

type BoolSpec

type BoolSpec struct{}

BoolSpec is a spec of a bool.

var Bool BoolSpec = BoolSpec{}

Bool is a default bool spec.

func (BoolSpec) Generate

func (s BoolSpec) Generate(r *rand.Rand) bool

Generate generates a random bool from r.

type CacheKey

type CacheKey interface {
	CacheKey() string
}

type Float32Spec

type Float32Spec struct {
	Max float32
	Min float32
}

Float32Spec is a spec of a float64.

func (*Float32Spec) Generate

func (s *Float32Spec) Generate(r *rand.Rand) float32

Generate generates a random bool from r.

func (Float32Spec) WithMax

func (s Float32Spec) WithMax(max float32) Float32Spec

WithMax returns new spec with given max.

func (Float32Spec) WithMin

func (s Float32Spec) WithMin(min float32) Float32Spec

WithMin returns new spec with given min.

type Float64Spec

type Float64Spec struct {
	Max float64
	Min float64
}

Float64Spec is a spec of a float64.

func (Float64Spec) Generate

func (s Float64Spec) Generate(r *rand.Rand) float64

Generate generates a random bool from r.

func (Float64Spec) WithMax

func (s Float64Spec) WithMax(max float64) Float64Spec

WithMax returns new spec with given max.

func (Float64Spec) WithMin

func (s Float64Spec) WithMin(min float64) Float64Spec

WithMin returns new spec with given min.

type Generator

type Generator struct {
	// LocalRand is a instance specific random number generator.
	LocalRand *rand.Rand
	// LocalCache is a instance specific cache store.
	LocalCache map[string]interface{}
}

Generator generates and caches a dummy data.

func (*Generator) Bool

func (g *Generator) Bool(key string, spec BoolSpec) bool

Bool generates a bool according to a key and spec.

func (*Generator) Cache

func (g *Generator) Cache() map[string]interface{}

Cache returns a cache store. GlobalRand or LocalCache are returned.

func (*Generator) Float32

func (g *Generator) Float32(key string, spec Float32Spec) float32

Float32 generates a float according to a key and spec.

func (*Generator) Float64

func (g *Generator) Float64(key string, spec Float64Spec) float64

Float64 generates a float according to a key and spec.

func (*Generator) Generate

func (g *Generator) Generate(key string, spec interface{}, f func(r *rand.Rand) interface{}) interface{}

func (*Generator) Int

func (g *Generator) Int(key string, spec IntSpec) int

Int generates a int according to a key and spec.

func (*Generator) Int64

func (g *Generator) Int64(key string, spec Int64Spec) int64

Int64 generates a int64 according to a key and spec.

func (*Generator) Rand

func (g *Generator) Rand(key string) *rand.Rand

Rand returns a random number generator for the specific key. GlobalRand or LocalCache are returned for the empty key.

func (*Generator) String

func (g *Generator) String(key string, spec StringSpec) string

String generates a string according to a key and spec.

func (*Generator) Time

func (g *Generator) Time(key string, spec TimeSpec) time.Time

Time generates a time.Time according to a key and spec.

func (*Generator) URL

func (g *Generator) URL(key string, spec URLSpec) url.URL

URL generates a url.URL according to a key and spec.

func (*Generator) Uint

func (g *Generator) Uint(key string, spec UintSpec) uint

Uint generates a uint according to a key and spec.

type Int64Spec

type Int64Spec struct {
	Max int64
	Min int64
}

Int64Spec is spec of a int64.

func (Int64Spec) Generate

func (s Int64Spec) Generate(r *rand.Rand) int64

Generate generates a random int64 from r.

func (Int64Spec) WithMax

func (s Int64Spec) WithMax(max int64) Int64Spec

WithMax returns new spec with given max.

func (Int64Spec) WithMin

func (s Int64Spec) WithMin(min int64) Int64Spec

WithMin returns new spec with given min.

type IntSpec

type IntSpec struct {
	Max int
	Min int
}

IntSpec is spec of a int.

func (IntSpec) Generate

func (s IntSpec) Generate(r *rand.Rand) int

Generate generates a random int from r.

func (IntSpec) WithMax

func (s IntSpec) WithMax(max int) IntSpec

WithMax returns new spec with given max.

func (IntSpec) WithMin

func (s IntSpec) WithMin(min int) IntSpec

WithMin returns new spec with given min.

type Some

type Some struct{}

func (Some) Bool

func (s Some) Bool() BoolSpec

func (Some) Float32

func (s Some) Float32() Float32Spec

func (Some) Float64

func (s Some) Float64() Float64Spec

func (Some) Int

func (s Some) Int() IntSpec

func (Some) Int64

func (s Some) Int64() Int64Spec

func (Some) String

func (s Some) String() StringSpec

func (Some) Time

func (s Some) Time() TimeSpec

func (Some) URL

func (s Some) URL() URLSpec

func (Some) Uint

func (s Some) Uint() UintSpec

type StringSpec

type StringSpec struct {
	Len int
}

BoolSpec is a spec of a string.

var String StringSpec = StringSpec{
	10,
}

String is a default string spec.

func (StringSpec) Generate

func (s StringSpec) Generate(r *rand.Rand) string

Generate generates a random string from r.

func (StringSpec) WithLen

func (s StringSpec) WithLen(len int) StringSpec

WithLen returns new spec with given len.

type TimeSpec

type TimeSpec struct {
	After  time.Time
	Before time.Time
}

TimeSpec is a spec of a time.Time.

var Time TimeSpec = TimeSpec{
	time.Unix(0, 0),
	time.Date(3000, time.January, 1, 0, 0, 0, 0, time.UTC),
}

Bool is a default time.Time spec.

func (TimeSpec) Generate

func (s TimeSpec) Generate(r *rand.Rand) time.Time

Generate generates a random time.Time from r.

func (TimeSpec) WithAfter

func (s TimeSpec) WithAfter(after time.Time) TimeSpec

WithAfter returns new spec with given after.

func (TimeSpec) WithBefore

func (s TimeSpec) WithBefore(before time.Time) TimeSpec

WithBefore returns new spec with given before.

type URLSpec

type URLSpec struct {
	Schemes []string
}

URLSpec is a spec of a url.URL.

var URL URLSpec = URLSpec{
	[]string{"http", "https"},
}

URL is a default url.URL spec.

func (URLSpec) Generate

func (s URLSpec) Generate(r *rand.Rand) url.URL

Generate generates a random url.URL from r.

func (URLSpec) WithSchemes

func (s URLSpec) WithSchemes(schemes []string) URLSpec

WithSchemes returns new spec with given schemes.

type UintSpec

type UintSpec struct {
	Max uint
	Min uint
}

UintSpec is a spec of a uint.

var Uint UintSpec = UintSpec{
	math.MaxUint32,
	0,
}

Uint is a default uint spec.

func (*UintSpec) Generate

func (s *UintSpec) Generate(r *rand.Rand) uint

Generate generates a random uint from r.

func (UintSpec) WithMax

func (s UintSpec) WithMax(max uint) UintSpec

WithMax returns new spec with given max.

func (UintSpec) WithMin

func (s UintSpec) WithMin(min uint) UintSpec

WithMin returns new spec with given min.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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