factory

package
v0.0.0-...-d364ca2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package factory provides typed, persistence-agnostic test data factories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder[T any] func(sequence uint64) *T

Builder constructs an entity for a one-based sequence number.

type Factory

type Factory[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any](builder Builder[T], persister Persister[T]) (*Factory[T], error)

func (*Factory[T]) Build

func (factory *Factory[T]) Build(traits ...Trait[T]) (*T, error)

Build constructs an entity without persisting it. Traits run in call order.

func (*Factory[T]) BuildList

func (factory *Factory[T]) BuildList(count int, traits ...Trait[T]) ([]*T, error)

BuildList constructs count entities without persistence.

func (*Factory[T]) Create

func (factory *Factory[T]) Create(ctx context.Context, traits ...Trait[T]) (*T, error)

Create constructs and persists one entity.

func (*Factory[T]) CreateList

func (factory *Factory[T]) CreateList(ctx context.Context, count int, traits ...Trait[T]) ([]*T, error)

CreateList constructs and persists count entities in order. Transactional behavior is deliberately owned by the supplied persister or calling context.

type Persister

type Persister[T any] func(context.Context, *T) error

Persister stores an entity. Applications normally adapt a repository Create method here instead of coupling factories to a persistence implementation.

type Trait

type Trait[T any] func(*T)

Trait applies an explicit variation to a built entity.

Jump to

Keyboard shortcuts

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