fixtures

package
v0.37.4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFixtureSetFactory added in v0.37.0

func AddFixtureSetFactory(ctx context.Context, group string, factory FixtureSetsFactory) error

func AddFixtureSetPostProcessorFactory added in v0.37.0

func AddFixtureSetPostProcessorFactory(ctx context.Context, factories ...PostProcessorFactory) error

func GetValueId

func GetValueId(value any) (any, bool)

Types

type AutoNumbered deprecated

type AutoNumbered NumberSequence

AutoNumbered is the old name for a NumberSequence

Deprecated: use NumberSequence instead

func NewAutoNumbered deprecated

func NewAutoNumbered() AutoNumbered

NewAutoNumbered is the old name for NewNumberSequence

Deprecated: use NewNumberSequence instead

func NewAutoNumberedFrom deprecated

func NewAutoNumberedFrom(initial uint) AutoNumbered

NewAutoNumberedFrom is the old name for NewNumberSequenceFrom

Deprecated: use NewNumberSequenceFrom instead

type ByteSequence added in v0.25.1

type ByteSequence interface {
	io.Reader
	// GetBytes returns a slice of n bytes filled with random-looking data.
	GetBytes(n int) []byte
}

func NewByteSequence added in v0.25.1

func NewByteSequence(seed string) ByteSequence

NewByteSequence provides a way to generate random-looking values for fixtures from a given seed. A possible use case would be to provide the name of the fixture set you are creating as the seed to get distinct values from other fixture sets, but having deterministic values compared to just generating random bytes for example.

type Container added in v0.37.0

type Container struct {
	// contains filtered or unexported fields
}

func ProvideContainer added in v0.37.0

func ProvideContainer(ctx context.Context) (*Container, error)

func (*Container) AddFixtureSetFactory added in v0.37.0

func (c *Container) AddFixtureSetFactory(group string, factory FixtureSetsFactory)

func (*Container) AddPostProcessorFactories added in v0.37.0

func (c *Container) AddPostProcessorFactories(factory ...PostProcessorFactory)

func (*Container) Build added in v0.37.0

func (c *Container) Build(ctx context.Context, config cfg.Config, logger log.Logger) (FixtureLoader, error)

type FixtureLoader

type FixtureLoader interface {
	Load(ctx context.Context) error
}

func NewFixtureLoader

func NewFixtureLoader(ctx context.Context, config cfg.Config, logger log.Logger, fixtureSets map[string][]FixtureSet, postProcessors []PostProcessor) (FixtureLoader, error)

func NewFixtureLoaderDisabled added in v0.37.0

func NewFixtureLoaderDisabled(logger log.Logger) FixtureLoader

type FixtureSet

type FixtureSet interface {
	Write(ctx context.Context) error
}

func NewSimpleFixtureSet added in v0.24.0

func NewSimpleFixtureSet[T any](fixtures NamedFixtures[T], writer FixtureWriter, options ...FixtureSetOption) FixtureSet

type FixtureSetFactory added in v0.24.0

type FixtureSetFactory func(ctx context.Context, config cfg.Config, logger log.Logger) (FixtureSet, error)

type FixtureSetOption added in v0.24.0

type FixtureSetOption func(settings *FixtureSetSettings)

func WithEnabled added in v0.24.0

func WithEnabled(enabled bool) FixtureSetOption

type FixtureSetSettings added in v0.24.0

type FixtureSetSettings struct {
	Enabled bool
}

func NewFixtureSetSettings added in v0.24.0

func NewFixtureSetSettings(options ...FixtureSetOption) *FixtureSetSettings

type FixtureSetsFactory added in v0.24.0

type FixtureSetsFactory func(ctx context.Context, config cfg.Config, logger log.Logger, group string) ([]FixtureSet, error)

func NewFixtureSetsFactory added in v0.24.0

func NewFixtureSetsFactory(factories ...FixtureSetFactory) FixtureSetsFactory

type FixtureWriter

type FixtureWriter interface {
	Write(ctx context.Context, fixtures []any) error
}

type NamedFixture

type NamedFixture[T any] struct {
	Name  string
	Value T
}

func NewNamedFixture added in v0.24.2

func NewNamedFixture[T any](name string, value T) *NamedFixture[T]

type NamedFixtures added in v0.24.0

type NamedFixtures[T any] []*NamedFixture[T]

func GetNamedFixtures

func GetNamedFixtures(container any) []NamedFixtures[any]

func (NamedFixtures[T]) All added in v0.24.0

func (l NamedFixtures[T]) All() []any

All specifically returns a []any instead of a []T, so the fixture loader code doesn't complain that it can't cast a []T to []any

func (NamedFixtures[T]) CountIf added in v0.24.0

func (l NamedFixtures[T]) CountIf(f func(elem T) bool) int

func (NamedFixtures[T]) FindAll added in v0.24.0

func (l NamedFixtures[T]) FindAll(f func(elem T) bool) []T

func (NamedFixtures[T]) FindFirst added in v0.24.0

func (l NamedFixtures[T]) FindFirst(f func(elem T) bool) (T, bool)

func (NamedFixtures[T]) GetValueById added in v0.24.0

func (l NamedFixtures[T]) GetValueById(id any) T

func (NamedFixtures[T]) GetValueByName added in v0.24.0

func (l NamedFixtures[T]) GetValueByName(name string) T

func (NamedFixtures[T]) Len added in v0.24.0

func (l NamedFixtures[T]) Len() int

type NumberSequence added in v0.25.1

type NumberSequence interface {
	// GetNextInt returns the next number in the sequence as an integer
	GetNextInt() int
	// GetNextUint returns the next number in the sequence as an unsigned integer
	GetNextUint() uint
	// GetNextId is the same as GetNextUint, but returns a pointer to the result.
	// The returned id can be used to get a fresh id for a fixture if you don't want to
	// assign specific ids.
	GetNextId() *uint
	// GetNext is the old name of GetNextId
	// Deprecated: use GetNextId instead
	GetNext() *uint
}

func NewNumberSequence added in v0.25.1

func NewNumberSequence() NumberSequence

func NewNumberSequenceFrom added in v0.25.1

func NewNumberSequenceFrom(initial uint) NumberSequence

type PostProcessor added in v0.36.0

type PostProcessor interface {
	Process(ctx context.Context) error
}

type PostProcessorFactory added in v0.36.0

type PostProcessorFactory func(ctx context.Context, config cfg.Config, logger log.Logger) (PostProcessor, error)

type UuidSequence added in v0.25.1

type UuidSequence interface {
	uuid.Uuid
}

func NewUuidSequence added in v0.25.1

func NewUuidSequence(seed string) UuidSequence

NewUuidSequence provides a way to generate random-looking UUIDs for fixtures from a given seed. Use this for fixtures instead of generating random UUIDs to create distinct keys easily while also keeping the fixtures deterministic. A unique seed is required for each fixture set to ensure there are no collisions between the generated UUIDs.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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