internal

package
v0.0.0-...-c2b9891 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID      int
	Balance int64
}

func LoadAccount

func LoadAccount(key string, value io.Reader) (*Account, error)

func (*Account) Key

func (a *Account) Key() string

func (*Account) Reload

func (a *Account) Reload(ctx context.Context, r kv.Getter) error

func (*Account) Save

func (a *Account) Save(ctx context.Context, w kv.Setter) error

func (*Account) Value

func (a *Account) Value() io.Reader

type TemplateOp

type TemplateOp string

type TemplateRuntime

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

func (*TemplateRuntime) Close

func (rt *TemplateRuntime) Close()

func (*TemplateRuntime) RunStep

RunStep executes the database command on a user DB.

type TemplateStep

type TemplateStep struct {

	// Op holds the test action, which is one of the templateOps defined above.
	Op TemplateOp

	Database    string
	Transaction string
	Snapshot    string
	Iterator    string

	Key   string
	Value string
	Next  bool

	Begin string
	End   string

	Error string
	// contains filtered or unexported fields
}

TemplateStep represents a sinlge database command for a transaction or snapshot or an iterator. It is defined as a string in the following format:

db:%s new-transaction => error:nil, tx:%s tx:%s get key:%s => error:ErrNotExist tx:%s set key:%s value:%s tx:%s get key:%s => value:%s tx:%s delete key:%s tx:%s get key:%s => error:ErrNotExist tx:%s commit => tx:%s rollback => error:non-nil

db:%s new-snapshot => snap:%s snap:%s get key:%s => error:ErrNotExist value:%s snap:%s discard

tx:%s ascend begin:%s end:%s => nil it:%s

it:%s fetch next:true => key:%s value:%s error:%s

Database commands above are parsed and validated into an object which can be used to run the command on a user database.

func ParseTemplateStep

func ParseTemplateStep(s string) (*TemplateStep, error)

ParseTemplateStep parses input string into a database command.

func (*TemplateStep) String

func (s *TemplateStep) String() string

type TemplateStepResult

type TemplateStepResult struct {
	Step   *TemplateStep
	Status error

	Key   string
	Value io.Reader

	Iterator    kv.Iterator
	Snapshot    kv.Snapshot
	Transaction kv.Transaction
}

TemplateStepResult holds the result of a TemplateStep execution.

func RunTemplateTest

func RunTemplateTest(ctx context.Context, text string, dbs ...kv.Database) ([]*TemplateStepResult, error)

RunTemplateTest runs all database operations in the input template serially one-after-another in the order defined in the template.

type TemplateTest

type TemplateTest struct {
	Steps []*TemplateStep
}

func ParseTemplateTest

func ParseTemplateTest(r io.Reader) (*TemplateTest, error)

func (*TemplateTest) WithKeyPrefix

func (t *TemplateTest) WithKeyPrefix(prefix string) (*TemplateTest, error)

WithKeyPrefix returns a new test with the given prefix added to all keys. Templates with `scan` operator or empty values for `begin` and `end` are not supported.

Jump to

Keyboard shortcuts

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