modeldecodertest

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertStructValues

func AssertStructValues(t *testing.T, i interface{}, isException func(string) bool,
	values *Values)

AssertStructValues recursively walks through the given struct and asserts that values are equal to expected values

func BuildString

func BuildString(nRunes int) string

BuildString creates a string conisisting of nRunes runes

func BuildStringWith

func BuildStringWith(nRunes int, r rune) string

BuildStringWith creates a string conisisting of nRunes of the given rune

func DecodeData

func DecodeData(t *testing.T, r io.Reader, eventType string, out interface{})

DecodeData decodes input from the io.Reader into the given output it skips events with a different type than the given eventType and decodes the first matching event type

func DecodeDataWithReplacement

func DecodeDataWithReplacement(t *testing.T, r io.Reader, eventType string, newData string, out interface{}, keys ...string)

DecodeDataWithReplacement decodes input from the io.Reader and replaces data for the given key with the provided newData before decoding into the output

func InitStructValues

func InitStructValues(i interface{})

InitStructValues iterates through the struct fields represented by the given reflect.Value and initializes all fields with some arbitrary value.

func IterateStruct

func IterateStruct(i interface{}, fn func(reflect.Value, string))

IterateStruct iterates through the struct fields represented by the given reflect.Value and calls the given function on every field.

func SetStructValues

func SetStructValues(in interface{}, values *Values, opts ...SetStructValuesOption)

SetStructValues iterates through the struct fields represented by the given reflect.Value and initializes all fields with the provided values

func SetZeroStructValue

func SetZeroStructValue(i interface{}, callback func(string))

SetZeroStructValue iterates through the struct fields represented by the given reflect.Value, sets a field to its zero value, calls the callback function and resets the field to its original value

func SetZeroStructValues

func SetZeroStructValues(i interface{})

SetZeroStructValues iterates through the struct fields represented by the given reflect.Value and sets all fields to their zero values.

Types

type SetStructValuesOption

type SetStructValuesOption func(key string, field, value reflect.Value) bool

SetStructValuesOption is the type of an option which may be passed into SetStructValues to override the value to which a field is set. If the option returns false, then the field will not be updated and no more options will be invoked.

type Values

type Values struct {
	Str             string
	Int             int
	Float           float64
	Bool            bool
	Duration        time.Duration
	IP              *modelpb.IP
	HTTPHeader      http.Header
	LabelVal        *modelpb.LabelValue
	NumericLabelVal *modelpb.NumericLabelValue
	// N controls how many elements are added to a slice or a map
	N int
}

Values used for populating the model structs

func DefaultValues

func DefaultValues() *Values

DefaultValues returns a Values struct initialized with non-zero values

func NonDefaultValues

func NonDefaultValues() *Values

NonDefaultValues returns a Values struct initialized with non-zero values

func (*Values) Update

func (v *Values) Update(args ...interface{})

Update arbitrary values

Jump to

Keyboard shortcuts

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