parser

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeInt   = "int"
	TypeStr   = "str"
	TypeFloat = "float"
)

Variables

View Source
var (
	ErrFixtureNotFound  = errors.New("fixture not found")
	ErrFixtureFileLoad  = errors.New("failed to load fixture file")
	ErrFixtureParseFile = errors.New("failed to parse fixture file")
	ErrParserNotFound   = errors.New("parser not found")
)

Functions

func New

func New(locations []string) *fileParser

func NewContext

func NewContext() *context

func RegisterParser

func RegisterParser(format string, parser FixtureFileParser)

Types

type Database

type Database struct {
	Keys   *Keys   `yaml:"keys"`
	Hashes *Hashes `yaml:"hashes"`
	Sets   *Sets   `yaml:"sets"`
	Lists  *Lists  `yaml:"lists"`
	ZSets  *ZSets  `yaml:"zsets"`
}

Database contains data to load into Redis database

type Fixture

type Fixture struct {
	Inherits  []string         `yaml:"inherits"`
	Templates Templates        `yaml:"templates"`
	Databases map[int]Database `yaml:"databases"`
}

Fixture is a representation of the test data, that is preloaded to a redis database before the test starts

Example (yaml):

```yaml inherits:

  • parent_template
  • child_template
  • other_fixture

databases:

1:
	keys:
		$name: keys1
		values:
			a:
				value: 1
				expiration: 10s
			b:
				value: 2
2:
	keys:
		$name: keys2
		values:
			c:
				value: 3
				expiration: 10s
			d:
				value: 4

```

type FixtureFileParser

type FixtureFileParser interface {
	Parse(ctx *context, filename string) (*Fixture, error)
	Copy(parser *fileParser) FixtureFileParser
}

func GetParser

func GetParser(format string) FixtureFileParser

type HashRecordValue

type HashRecordValue struct {
	Name       string        `yaml:"$name"`
	Extend     string        `yaml:"$extend"`
	Values     []*HashValue  `yaml:"values"`
	Expiration time.Duration `yaml:"expiration"`
}

HashRecordValue represent a single hash data structure

type HashValue

type HashValue struct {
	Key   Value `yaml:"key"`
	Value Value `yaml:"value"`
}

type Hashes

type Hashes struct {
	Values map[string]*HashRecordValue `yaml:"values"`
}

Hashes represent a collection of hash data structures, that will be loaded into Redis database

type KeyValue

type KeyValue struct {
	Value      Value         `yaml:"value"`
	Expiration time.Duration `yaml:"expiration"`
}

KeyValue represent a redis key/value pair

type Keys

type Keys struct {
	Name   string               `yaml:"$name"`
	Extend string               `yaml:"$extend"`
	Values map[string]*KeyValue `yaml:"values"`
}

Keys represent a collection of key/value pairs, that will be loaded into Redis database

type ListRecordValue

type ListRecordValue struct {
	Name       string        `yaml:"$name"`
	Extend     string        `yaml:"$extend"`
	Values     []*ListValue  `yaml:"values"`
	Expiration time.Duration `yaml:"expiration"`
}

ListRecordValue represent a single list data structure

type ListValue

type ListValue struct {
	Value Value `yaml:"value"`
}

ListValue represent a list value object

type Lists

type Lists struct {
	Values map[string]*ListRecordValue `yaml:"values"`
}

Lists represent a collection of Redis list data structures

type SetRecordValue

type SetRecordValue struct {
	Name       string        `yaml:"$name"`
	Extend     string        `yaml:"$extend"`
	Values     []*SetValue   `yaml:"values"`
	Expiration time.Duration `yaml:"expiration"`
}

SetRecordValue represent a single set data structure

type SetValue

type SetValue struct {
	Value Value `yaml:"value"`
}

SetValue represent a set value object

type Sets

type Sets struct {
	Values map[string]*SetRecordValue `yaml:"values"`
}

Sets represent a collection of set data structures, that will be loaded into Redis database

type Templates

type Templates struct {
	Keys   []*Keys            `yaml:"keys"`
	Hashes []*HashRecordValue `yaml:"hashes"`
	Sets   []*SetRecordValue  `yaml:"sets"`
	Lists  []*ListRecordValue `yaml:"lists"`
	ZSets  []*ZSetRecordValue `yaml:"zsets"`
}

type Value

type Value struct {
	Type  string
	Value interface{}
}

func Float

func Float(value float64) Value

func Int

func Int(value int) Value

func Str

func Str(value string) Value

func (*Value) UnmarshalYAML

func (obj *Value) UnmarshalYAML(unmarshal func(interface{}) error) error

type ZSetRecordValue

type ZSetRecordValue struct {
	Name       string        `yaml:"$name"`
	Extend     string        `yaml:"$extend"`
	Values     []*ZSetValue  `yaml:"values"`
	Expiration time.Duration `yaml:"expiration"`
}

ZSetRecordValue represent a single sorted set data structure

type ZSetValue

type ZSetValue struct {
	Value Value   `yaml:"value"`
	Score float64 `yaml:"score"`
}

ZSetValue represent a zset value object

type ZSets

type ZSets struct {
	Values map[string]*ZSetRecordValue `yaml:"values"`
}

ZSets represent a collection of Redis sorted set data structure

Jump to

Keyboard shortcuts

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