fixture

package module
v0.0.0-...-be9ab65 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFuncMap

func AddFuncMap(fm template.FuncMap)

func ULID

func ULID(v any, err error) ulid.ULID

ULID is meant to be used with (*Fixture).GetField, and will panic if the incoming err is not nil. E.g.:

ULID(f.GetField("users", "1", "id"))

Types

type CommandFunc

type CommandFunc func(in *CommandInput) (*CommandOutput, error)

type CommandInput

type CommandInput struct {
	Fixture *Fixture
	Table   string
	Key     string
	Field   string

	Line string
}

func (*CommandInput) ScanLine

func (in *CommandInput) ScanLine() ([]string, map[string]string, error)

type CommandOutput

type CommandOutput struct {
	Callback  func() (any, error)
	DependsOn [][2]string
	IsUpdate  bool
	Value     any
}

type Database

type Database map[string]Table

type Edge

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

func (*Edge) From

func (e *Edge) From() graph.Node

func (*Edge) ReversedEdge

func (e *Edge) ReversedEdge() graph.Edge

func (*Edge) To

func (e *Edge) To() graph.Node

type Fixture

type Fixture struct {
	Runner  *Runner
	Context context.Context

	// TODO: Should check for one of?
	File       string
	Body       io.Reader
	BodyFormat string

	// If defined, the fixture body will be parsed as a Go text/template string
	// and executed with TemplateData as its data.
	TemplateData map[string]any

	PrintJSON bool
	// contains filtered or unexported fields
}

func (*Fixture) Apply

func (f *Fixture) Apply() error

func (*Fixture) Edge

func (f *Fixture) Edge(uid, vid int64) graph.Edge

func (*Fixture) From

func (f *Fixture) From(id int64) graph.Nodes

func (*Fixture) GetField

func (f *Fixture) GetField(table, key, field string) (any, error)

func (*Fixture) GetNode

func (f *Fixture) GetNode(label [2]string) *Node

func (*Fixture) HasEdgeBetween

func (f *Fixture) HasEdgeBetween(xid, yid int64) bool

func (*Fixture) HasEdgeFromTo

func (f *Fixture) HasEdgeFromTo(uid, vid int64) bool

func (*Fixture) Node

func (f *Fixture) Node(id int64) graph.Node

func (*Fixture) Nodes

func (f *Fixture) Nodes() graph.Nodes

func (*Fixture) SetRecord

func (f *Fixture) SetRecord(table, key string, record Record)

func (*Fixture) To

func (f *Fixture) To(id int64) graph.Nodes

type Node

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

func (*Node) AppendFrom

func (r *Node) AppendFrom(node *Node)

func (*Node) AppendTo

func (r *Node) AppendTo(node *Node)

func (*Node) ID

func (r *Node) ID() int64

func (*Node) Label

func (r *Node) Label() [2]string

func (*Node) LenFrom

func (r *Node) LenFrom() int

func (*Node) LenTo

func (r *Node) LenTo() int

type Nodes

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

func (*Nodes) Len

func (r *Nodes) Len() int

func (*Nodes) Next

func (r *Nodes) Next() bool

func (*Nodes) Node

func (r *Nodes) Node() graph.Node

func (*Nodes) Reset

func (r *Nodes) Reset()

type PostgresWriter

type PostgresWriter struct {
	Conn *pgxpool.Pool
	Tx   pgx.Tx
}

func (*PostgresWriter) Insert

func (w *PostgresWriter) Insert(f *Fixture, table string, key string, record Record) error

func (*PostgresWriter) Update

func (w *PostgresWriter) Update(f *Fixture, table string, key string, record Record) error

type Record

type Record map[string]any

type RecordError

type RecordError struct {
	Table string
	Key   string
	Field string
	Err   error
}

func (*RecordError) Error

func (e *RecordError) Error() string

type RedisWriter

type RedisWriter struct {
	Client *redis.Client
}

func (*RedisWriter) Insert

func (w *RedisWriter) Insert(f *Fixture, table string, key string, record Record) error

func (*RedisWriter) Update

func (w *RedisWriter) Update(f *Fixture, table string, key string, record Record) error

type Runner

type Runner struct {
	// The default name for the primary key field.
	// This value can be overwritten by TableOptions.
	// Default: "id"
	PrimaryKeyName string

	// The writer used for this runner.
	Writer Writer

	TableOptions map[string]*TableOptions
	TableAliases map[string]string
	// contains filtered or unexported fields
}

type Table

type Table map[string]Record

func GetDefaultValues

func GetDefaultValues(file string) (Table, error)

type TableOptions

type TableOptions struct {
	DatabaseName   string
	PrimaryKeyName string
	DefaultValues  Record
}

type Writer

type Writer interface {
	Insert(f *Fixture, table, key string, record Record) error
	Update(f *Fixture, table, key string, record Record) error
}

Writer is an interface that handles inserting or updating database records.

Jump to

Keyboard shortcuts

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