field

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package field defines a generic way to reference and assign values to any test field by leveraging reflection and struct field tagging. Struct field tagging is used to check for semantic assignability. A source field is assignable to a destination field if the following two condition applies: - source field go type is assignable and/or convertible to destination field go type - source field is semantically assignable to destination field "Semantically assignable" means that both fields have the same `field_type`. A `field_type` must be assigned to a field via struct field tagging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JoinFieldPathSegments

func JoinFieldPathSegments(pathSegments ...string) string

JoinFieldPathSegments joins the provided field path segments into a single field path.

func Path

func Path(s string) string

Path converts the provided string to the corresponding field path representation.

func Paths

func Paths(fieldContainer reflect.Type) map[string]struct{}

Paths returns the field paths of the fields contained in the provided fieldContainer. fieldContainer's Kind must be Struct; otherwise, the function will panic. A field path is generated for each field that is neither a struct nor a pointer to a struct. For each field whose type has the struct kind, the function recursively invokes itself to provide field paths for each of its eligible subfields. Each field that is a struct pointer is dereferenced and then treated as a field whose type has the struct kind.

Types

type Field

type Field struct {
	// Path represents the unique location of a field in the parent container. A Path is composed of one or multiple
	// dot-separated field path segments. This addressing mechanism allows to organize fields in a hierarchical way.
	Path string
	// Value contains the value associated to the field. It can be settable or not, depending on how it is created.
	Value reflect.Value
	// Type is mainly used to check if a source Field Value can be semantically assigned to a destination Field Value.
	// Semantic assignability means that both fields have the same Type. A Type must be assigned to a Field via
	// `field_type` struct field tag (e.g.: `field_type:"<field_type>"`).
	Type Type
}

Field contains information regarding a field, such as its value and its field type.

func ByName

func ByName(name string, fieldContainers ...reflect.Value) (*Field, error)

ByName returns information for the field identified by name. The field is searched in the provided fieldContainers, and the first match is returned.

func (*Field) Set

func (f *Field) Set(srcField *Field) error

Set sets the Value of the current field to the Value of the provided source field. If the source Value is neither assignable nor convertible to the destination Value, or it is not semantically assignable to it, Set returns an error.

type Retriever

type Retriever interface {
	// Field returns information related to the field with the provided name.
	Field(name string) (*Field, error)
}

Retriever allows to retrieve information regarding fields.

type Type

type Type string

Type represents the type of field.

const (
	// TypeUndefined specifies an undefined field type. This is a special value indicating the absence of a Type for a
	// Field. The value of a Field marked as undefined cannot be assigned nor set to any other Field value.
	TypeUndefined Type = "undefined"
	// TypeFD specifies that the field contains a file descriptor.
	TypeFD Type = "fd"
	// TypeBuffer specifies that the field contains a buffer.
	TypeBuffer Type = "buffer"
	// TypeBufferLen specifies that the field contains a buffer length.
	TypeBufferLen Type = "buffer_len"
	// TypeFilePath specifies that the field contains a file path.
	TypeFilePath Type = "file_path"
	// TypeOpenFlags specifies that the field contains the open system call flags.
	TypeOpenFlags Type = "open_flags"
	// TypeOpenMode specifies that the field contains the open system call modes.
	TypeOpenMode Type = "open_mode"
	// TypeOpenHow specifies that the field contains the openat2 system call open_how parameter.
	TypeOpenHow Type = "open_how"
	// TypeOpenHowFlags specifies that the field contains the openat2 system call open_how flags.
	TypeOpenHowFlags Type = "open_how_flags"
	// TypeOpenHowMode specifies that the field contains the openat2 system call open_how mode.
	TypeOpenHowMode Type = "open_how_mode"
	// TypeOpenHowResolve specifies that the field contains the openat2 system call open_how resolve value.
	TypeOpenHowResolve Type = "open_how_resolve"
	// TypeLinkAtFlags specifies that the field contains the linkat system call flags.
	TypeLinkAtFlags Type = "linkat_flags"
	// TypeModuleParams specifies that the field contains the init_module system call params.
	TypeModuleParams Type = "module_params"
	// TypeFinitModuleFlags specifies that the field contains the finit_module system call flags.
	TypeFinitModuleFlags Type = "finit_module_flags"
	// TypeDup3Flags specifies that the field contains the dup3 system call flags.
	TypeDup3Flags Type = "dup3_flags"
	// TypeSocketAddress specifies that the field contains a sockaddr.
	TypeSocketAddress Type = "socket_address"
	// TypeSocketDomain specifies that the field contains the socket system call domain.
	TypeSocketDomain Type = "socket_domain"
	// TypeSocketType specifies that the field contains the socket system call type.
	TypeSocketType Type = "socket_type"
	// TypeSocketProtocol specifies that the field contains the socket system call protocol.
	TypeSocketProtocol Type = "socket_protocol"
	// TypeSendFlags specifies that the field contains the sendto system call flags.
	TypeSendFlags Type = "send_flags"
	// TypePID specifies that the field contains a process identifier.
	TypePID Type = "pid"
	// TypeSignal specifies that the field contains a signal.
	TypeSignal Type = "signal"
)

Jump to

Keyboard shortcuts

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