Documentation ¶
Overview ¶
Package testutils implements test utilities.
Package testutils implements test utilities.
Index ¶
- Variables
- func AddRemotes(values []resource.Name, remotes ...string) []resource.Name
- func AddSuffixes(values []resource.Name, suffixes ...string) []resource.Name
- func BuildTempModule(tb testing.TB, dir string) string
- func ConcatResourceNames(values ...[]resource.Name) []resource.Name
- func ExtractNames(values ...resource.Name) []string
- func MakeRobotForModuleLogging(t *testing.T, parentAddr string) rpc.Server
- func NewInfoObservedTestLogger(tb testing.TB) (logging.Logger, *observer.ObservedLogs)
- func NewResourceNameSet(resourceNames ...resource.Name) map[resource.Name]struct{}
- func NewUnimplementedResource(name resource.Name) resource.Resource
- func Retry(condition condition, numRetries int)
- func SubtractNames(from []resource.Name, values ...resource.Name) []resource.Name
- func SubtractNamesFromLevels(from [][]resource.Name, values ...resource.Name) [][]resource.Name
- func ToProtoMapIgnoreOmitEmpty(data interface{}) map[string]interface{}
- func VerifySameElements[E cmp.Ordered](tb testing.TB, actual, expected []E)
- func VerifySameResourceNames(tb testing.TB, actual, expected []resource.Name)
- func VerifyTopologicallySortedLevels(t *testing.T, g *resource.Graph, levels [][]resource.Name, ...)
- type FakeConvertedAttributes
- type MockBuffer
- type ServerTransportStream
- type TrackingDialer
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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
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 ¶
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 ExtractNames ¶
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
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
NewInfoObservedTestLogger is a copy of NewObservedTestLogger with info level debugging instead of debug level.
func NewResourceNameSet ¶
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
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
SubtractNames removes values from the first slice of resource names.
func SubtractNamesFromLevels ¶ added in v0.2.36
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
VerifySameElements asserts that two slices contain the same elements without considering order.
func VerifySameResourceNames ¶ added in v0.29.0
VerifySameResourceNames asserts that two slices of resource.Names contain the same resources.Names without considering order.
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.
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 ¶
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.
Source Files ¶
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). |