fixtures

package
v0.26.3 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RedisOpRpush = "RPUSH"
	RedisOpSet   = "SET"
)

Variables

This section is empty.

Functions

func GetValueId

func GetValueId(value any) (any, bool)

func KernelMiddlewareLoader

func KernelMiddlewareLoader(group string, factory FixtureSetsFactory) kernel.MiddlewareFactory

func NewBlobPurger added in v0.24.0

func NewBlobPurger(ctx context.Context, config cfg.Config, logger log.Logger, settings *BlobFixturesSettings) (*blobPurger, error)

func NewDynamodbPurger added in v0.24.0

func NewDynamodbPurger(ctx context.Context, config cfg.Config, logger log.Logger, settings *ddb.Settings) (*dynamodbPurger, error)

func NewMysqlPurger added in v0.24.0

func NewMysqlPurger(ctx context.Context, config cfg.Config, logger log.Logger, tableName string) (*mysqlPurger, error)

func NewRedisPurger added in v0.24.0

func NewRedisPurger(ctx context.Context, config cfg.Config, logger log.Logger, name string) (*redisPurger, error)

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 BlobFixture added in v0.24.0

type BlobFixture struct{}

BlobFixture is a dummy struct for writing nicely typed fixture sets, even though the blob fixture loader works a bit differently

type BlobFixturesSettings

type BlobFixturesSettings struct {
	BasePath   string
	ConfigName string
}

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 DdbWriterOption

type DdbWriterOption func(settings *ddb.Settings)

func WithDdbModelIdApplication

func WithDdbModelIdApplication(application string) DdbWriterOption

type FixtureLoader

type FixtureLoader interface {
	Load(ctx context.Context, group string, fixtureSets []FixtureSet) error
}

func NewFixtureLoader

func NewFixtureLoader(ctx context.Context, config cfg.Config, 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)

func BlobFixtureSetFactory added in v0.24.0

func BlobFixtureSetFactory[T any](settings *BlobFixturesSettings, data NamedFixtures[T], options ...FixtureSetOption) FixtureSetFactory

func ConfigurableKvStoreFixtureSetFactory added in v0.24.0

func ConfigurableKvStoreFixtureSetFactory[T any](name string, data NamedFixtures[*KvStoreFixture], options ...FixtureSetOption) FixtureSetFactory

func DynamoDbFixtureSetFactory added in v0.24.0

func DynamoDbFixtureSetFactory[T any](settings *ddb.Settings, data NamedFixtures[T], options ...FixtureSetOption) FixtureSetFactory

func DynamoDbKvStoreFixtureSetFactory added in v0.24.0

func DynamoDbKvStoreFixtureSetFactory[T any](modelId *mdl.ModelId, data NamedFixtures[*KvStoreFixture], options ...FixtureSetOption) FixtureSetFactory

func MysqlOrmFixtureSetFactory added in v0.24.0

func MysqlOrmFixtureSetFactory[T any](metadata *db_repo.Metadata, data NamedFixtures[T], options ...FixtureSetOption) FixtureSetFactory

func MysqlPlainFixtureSetFactory added in v0.24.0

func MysqlPlainFixtureSetFactory[T any](metadata *MysqlPlainMetaData, data NamedFixtures[T], options ...FixtureSetOption) FixtureSetFactory

func MysqlSqlxFixtureSetFactory added in v0.24.0

func MysqlSqlxFixtureSetFactory[T any](metadata *MysqlSqlxMetaData, data NamedFixtures[T], options ...FixtureSetOption) FixtureSetFactory

func RedisFixtureSetFactory added in v0.24.0

func RedisFixtureSetFactory[T any](name string, operation string, data NamedFixtures[T], options ...FixtureSetOption) FixtureSetFactory

func RedisKvStoreFixtureSetFactory added in v0.24.0

func RedisKvStoreFixtureSetFactory[T any](modelId *mdl.ModelId, data NamedFixtures[*KvStoreFixture], options ...FixtureSetOption) FixtureSetFactory

type FixtureSetOption added in v0.24.0

type FixtureSetOption func(settings *FixtureSetSettings)

func WithEnabled added in v0.24.0

func WithEnabled(enabled bool) FixtureSetOption

func WithPurge added in v0.24.0

func WithPurge(purge bool) FixtureSetOption

type FixtureSetSettings added in v0.24.0

type FixtureSetSettings struct {
	Enabled bool
	Purge   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 {
	Purge(ctx context.Context) error
	Write(ctx context.Context, fixtures []any) error
}

func NewBlobFixtureWriter added in v0.24.0

func NewBlobFixtureWriter(ctx context.Context, config cfg.Config, logger log.Logger, settings *BlobFixturesSettings) (FixtureWriter, error)

func NewBlobFixtureWriterWithInterfaces

func NewBlobFixtureWriterWithInterfaces(logger log.Logger, batchRunner blob.BatchRunner, purger *blobPurger, store blob.Store, basePath string) FixtureWriter

func NewConfigurableKvStoreFixtureWriter added in v0.24.0

func NewConfigurableKvStoreFixtureWriter[T any](ctx context.Context, config cfg.Config, logger log.Logger, name string) (FixtureWriter, error)

func NewConfigurableKvStoreFixtureWriterWithInterfaces

func NewConfigurableKvStoreFixtureWriterWithInterfaces[T any](logger log.Logger, store kvstore.KvStore[T]) FixtureWriter

func NewDynamoDbFixtureWriter added in v0.24.0

func NewDynamoDbFixtureWriter(ctx context.Context, config cfg.Config, logger log.Logger, settings *ddb.Settings, options ...DdbWriterOption) (FixtureWriter, error)

func NewDynamoDbFixtureWriterWithInterfaces

func NewDynamoDbFixtureWriterWithInterfaces(logger log.Logger, factory ddbRepoFactory, purger *dynamodbPurger) FixtureWriter

func NewDynamoDbKvStoreFixtureWriter added in v0.24.0

func NewDynamoDbKvStoreFixtureWriter[T any](ctx context.Context, config cfg.Config, logger log.Logger, modelId *mdl.ModelId) (FixtureWriter, error)

func NewDynamoDbKvStoreFixtureWriterWithInterfaces

func NewDynamoDbKvStoreFixtureWriterWithInterfaces[T any](logger log.Logger, factory ddbKvstoreFactory[T], purger *dynamodbPurger) FixtureWriter

func NewMysqlFixtureWriterWithInterfaces

func NewMysqlFixtureWriterWithInterfaces(logger log.Logger, metadata *db_repo.Metadata, repo db_repo.Repository, purger *mysqlPurger) FixtureWriter

func NewMysqlOrmFixtureWriter added in v0.24.0

func NewMysqlOrmFixtureWriter(ctx context.Context, config cfg.Config, logger log.Logger, metadata *db_repo.Metadata) (FixtureWriter, error)

func NewMysqlPlainFixtureWriter added in v0.24.0

func NewMysqlPlainFixtureWriter(ctx context.Context, config cfg.Config, logger log.Logger, metadata *MysqlPlainMetaData) (FixtureWriter, error)

func NewMysqlPlainFixtureWriterWithInterfaces

func NewMysqlPlainFixtureWriterWithInterfaces(logger log.Logger, client db.Client, metadata *MysqlPlainMetaData, purger *mysqlPurger) FixtureWriter

func NewMysqlSqlxFixtureWriter added in v0.24.0

func NewMysqlSqlxFixtureWriter(ctx context.Context, config cfg.Config, logger log.Logger, metadata *MysqlSqlxMetaData) (FixtureWriter, error)

func NewMysqlSqlxFixtureWriterWithInterfaces added in v0.21.5

func NewMysqlSqlxFixtureWriterWithInterfaces(logger log.Logger, client db.Client, metadata *MysqlSqlxMetaData, purger *mysqlPurger) FixtureWriter

func NewRedisFixtureWriter added in v0.24.0

func NewRedisFixtureWriter(ctx context.Context, config cfg.Config, logger log.Logger, name string, operation string) (FixtureWriter, error)

func NewRedisFixtureWriterWithInterfaces

func NewRedisFixtureWriterWithInterfaces(logger log.Logger, client redis.Client, purger *redisPurger, operation string) FixtureWriter

func NewRedisKvStoreFixtureWriter added in v0.24.0

func NewRedisKvStoreFixtureWriter[T any](ctx context.Context, config cfg.Config, logger log.Logger, modelId *mdl.ModelId) (FixtureWriter, error)

func NewRedisKvStoreFixtureWriterWithInterfaces

func NewRedisKvStoreFixtureWriterWithInterfaces[T any](logger log.Logger, store kvstore.KvStore[T], purger *redisPurger) FixtureWriter

type KvStoreFixture

type KvStoreFixture struct {
	Key   interface{}
	Value interface{}
}

type MysqlPlainFixtureValues

type MysqlPlainFixtureValues []interface{}

type MysqlPlainMetaData

type MysqlPlainMetaData struct {
	TableName string
	Columns   []string
}

type MysqlSqlxMetaData added in v0.21.5

type MysqlSqlxMetaData struct {
	TableName string
}

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]

func NewNamedKvStoreFixture added in v0.24.2

func NewNamedKvStoreFixture[T any](name any, value T) *NamedFixture[*KvStoreFixture]

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 Purger added in v0.24.0

type Purger interface {
	Purge(ctx context.Context) error
}

type RedisFixture

type RedisFixture struct {
	Key    string
	Value  interface{}
	Expiry time.Duration
}

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