testutils

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package testutils implements test utilities.

Package testutils implements test utilities.

Index

Constants

This section is empty.

Variables

View Source
var (
	// EchoFunc is a helper to echo out the say command passsed in a Do.
	EchoFunc = func(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error) {
		return cmd, nil
	}

	// TestCommand is a dummy command to send for a DoCommand.
	TestCommand = map[string]interface{}{"command": "test", "data": 500}
)

Functions

func AddRemotes

func AddRemotes(values []resource.Name, remotes ...string) []resource.Name

AddRemotes takes a slice of resource.Name objects and for each remote, adds the remote to every object, then returns the entire list.

func AddSuffixes

func AddSuffixes(values []resource.Name, suffixes ...string) []resource.Name

AddSuffixes takes a slice of resource.Name objects and for each suffix, adds the suffix to every object, then returns the entire list.

func BuildTempModule added in v0.2.50

func BuildTempModule(tb testing.TB, dir string) string

BuildTempModule will run "go build ." in the provided RDK directory and return the path to the built temporary file. This function will fail the current test if there are any build-related errors.

func ConcatResourceNames

func ConcatResourceNames(values ...[]resource.Name) []resource.Name

ConcatResourceNames takes a slice of slices of resource.Name objects and returns a concatenated slice of resource.Name for the purposes of comparison in automated tests.

func ConcatResourceStatuses added in v0.35.0

func ConcatResourceStatuses(values ...[]resource.Status) []resource.Status

ConcatResourceStatuses takes a slice of slices of resource.Status objects and returns a concatenated slice of resource.Status for the purposes of comparison in automated tests.

func ConfigFromJSON added in v0.31.0

func ConfigFromJSON(tb testing.TB, jsonData string) *config.Config

ConfigFromJSON creates a fully-processed config from a JSON-string. This function will fail the current if it encounters any errors.

func ExtractNames

func ExtractNames(values ...resource.Name) []string

ExtractNames takes a slice of resource.Name objects and returns a slice of name strings for the purposes of comparison in automated tests.

func MakeRobotForModuleLogging added in v0.21.0

func MakeRobotForModuleLogging(t *testing.T, parentAddr string) rpc.Server

MakeRobotForModuleLogging creates and starts an RPC server that can respond to `LogRequest`s from modules and listens at parentAddr.

func NewInfoObservedTestLogger added in v0.2.49

func NewInfoObservedTestLogger(tb testing.TB) (logging.Logger, *observer.ObservedLogs)

NewInfoObservedTestLogger is a copy of NewObservedTestLogger with info level debugging instead of debug level.

func NewResourceNameSet

func NewResourceNameSet(resourceNames ...resource.Name) map[resource.Name]struct{}

NewResourceNameSet returns a flattened set of name strings from a collection of resource.Name objects for the purposes of comparison in automated tests.

func NewUnimplementedResource added in v0.2.36

func NewUnimplementedResource(name resource.Name) resource.Resource

NewUnimplementedResource returns a resource that has all methods unimplemented.

func Retry added in v0.15.0

func Retry(condition condition, numRetries int)

Retry sleeps until a condition is met or a max of numRetries times.

func SubtractNames added in v0.2.36

func SubtractNames(from []resource.Name, values ...resource.Name) []resource.Name

SubtractNames removes values from the first slice of resource names.

func SubtractNamesFromLevels added in v0.2.36

func SubtractNamesFromLevels(from [][]resource.Name, values ...resource.Name) [][]resource.Name

SubtractNamesFromLevels removes values from each slice of resource names.

func ToProtoMapIgnoreOmitEmpty added in v0.13.0

func ToProtoMapIgnoreOmitEmpty(data interface{}) map[string]interface{}

ToProtoMapIgnoreOmitEmpty is a helper to convert an interface to a map to compare against a structpb.

func VerifySameElements added in v0.29.0

func VerifySameElements[E cmp.Ordered](tb testing.TB, actual, expected []E)

VerifySameElements asserts that two slices contain the same elements without considering order.

func VerifySameResourceNames added in v0.29.0

func VerifySameResourceNames(tb testing.TB, actual, expected []resource.Name)

VerifySameResourceNames asserts that two slices of resource.Names contain the same resources.Names without considering order.

func VerifySameResourceStatuses added in v0.35.0

func VerifySameResourceStatuses(tb testing.TB, actual, expected []resource.Status)

VerifySameResourceStatuses asserts that two slices of resource.Status contain the same elements without considering order. Does not consider resource.Status.LastUpdated timestamps when comparing.

func VerifyTopologicallySortedLevels added in v0.2.36

func VerifyTopologicallySortedLevels(t *testing.T, g *resource.Graph, levels [][]resource.Name, exclusions ...resource.Name)

VerifyTopologicallySortedLevels verifies each topological layer of a sort against the given levels from most dependencies to least dependencies.

Types

type FakeConvertedAttributes

type FakeConvertedAttributes struct {
	Thing string
}

FakeConvertedAttributes is a helper for testing if validation works.

func (*FakeConvertedAttributes) Validate

func (convAttr *FakeConvertedAttributes) Validate(path string) ([]string, error)

Validate validates that the single fake attribute Thing exists properly in the struct, meant to implement the validator interface in component.go.

type MockBuffer added in v0.13.0

type MockBuffer struct {
	Writes []*v1.SensorData
	// contains filtered or unexported fields
}

MockBuffer is a buffered writer that just appends data to an array to read without needing a real file system for testing.

func (*MockBuffer) Flush added in v0.13.0

func (m *MockBuffer) Flush() error

Flush does nothing in this implementation as all data will be stored in memory.

func (*MockBuffer) Length added in v0.13.0

func (m *MockBuffer) Length() int

Length gets the length of the buffer without race conditions.

func (*MockBuffer) Path added in v0.13.0

func (m *MockBuffer) Path() string

Path returns a hardcoded fake path.

func (*MockBuffer) Write added in v0.13.0

func (m *MockBuffer) Write(item *v1.SensorData) error

Write adds a collected sensor reading to the array.

type ServerTransportStream added in v0.2.49

type ServerTransportStream struct {
	grpc.ServerTransportStream
	// contains filtered or unexported fields
}

ServerTransportStream implements grpc.ServerTransportStream and can be used to test setting metadata in the gRPC response header.

func NewServerTransportStream added in v0.2.49

func NewServerTransportStream() *ServerTransportStream

NewServerTransportStream creates a new ServerTransportStream.

func (*ServerTransportStream) SetHeader added in v0.2.49

func (s *ServerTransportStream) SetHeader(md metadata.MD) error

SetHeader implements grpc.ServerTransportStream.

func (*ServerTransportStream) Value added in v0.2.49

func (s *ServerTransportStream) Value(key string) []string

Value returns the value in the metadata map corresponding to a given key.

type TrackingDialer

type TrackingDialer struct {
	rpc.Dialer
	NewConnections int
}

TrackingDialer tracks dial attempts.

func (*TrackingDialer) DialDirect

func (td *TrackingDialer) DialDirect(
	ctx context.Context,
	target string,
	keyExtra string,
	onClose func() error,
	opts ...grpc.DialOption,
) (rpc.ClientConn, bool, error)

DialDirect tracks calls of DialDirect.

func (*TrackingDialer) DialFunc

func (td *TrackingDialer) DialFunc(
	proto string,
	target string,
	keyExtra string,
	f func() (rpc.ClientConn, func() error, error),
) (rpc.ClientConn, bool, error)

DialFunc tracks calls of DialFunc.

Directories

Path Synopsis
Package inject provides dependency injected structures for mocking interfaces.
Package inject provides dependency injected structures for mocking interfaces.
Package robottestutils provides helper functions in testing
Package robottestutils provides helper functions in testing
Package vcamera creates and streams video to virtual V4L2 capture devices on Linux.
Package vcamera creates and streams video to virtual V4L2 capture devices on Linux.
cmd
This package creates two virtual cameras and streams test video to them until the program halts (with ctrl-c for example).
This package creates two virtual cameras and streams test video to them until the program halts (with ctrl-c for example).

Jump to

Keyboard shortcuts

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