Documentation
¶
Overview ¶
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, modDir string) string
- func BuildTempModuleWithFirstRun(tb testing.TB, modDir string) string
- func CheckMockBufferWrites(t *testing.T, ctx context.Context, start time.Time, ...)
- func ConcatResourceNames(values ...[]resource.Name) []resource.Name
- func ConcatResourceStatuses(values ...[]resource.Status) []resource.Status
- func ExtractNames(values ...resource.Name) []string
- func FilterByStatus(tb testing.TB, resourceStatuses []resource.Status, state resource.NodeState) []resource.Status
- 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 ToStructPBStruct(t *testing.T, v any) *structpb.Struct
- func VerifySameElements[E cmp.Ordered](tb testing.TB, actual, expected []E)
- func VerifySameResourceNames(tb testing.TB, actual, expected []resource.Name)
- func VerifySameResourceStatuses(tb testing.TB, actual, expected []resource.Status)
- func VerifyTopologicallySortedLevels(t *testing.T, g *resource.Graph, levels [][]resource.Name, ...)
- 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 ¶
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, modDir string) string
BuildTempModule will attempt to build the module in the provided directory and put the resulting executable binary into a temporary directory. If successful, this function will return the path to the executable binary.
func BuildTempModuleWithFirstRun ¶ added in v0.49.0
func BuildTempModuleWithFirstRun(tb testing.TB, modDir string) string
BuildTempModuleWithFirstRun will attempt to build the module in the provided directory and put the resulting executable binary into a temporary directory. After building, it will also copy "meta.json" and "first_run.sh" into the same temporary directory. It is assumed that these files are in the provided module directory. If successful, this function will return the path to the executable binary.
func CheckMockBufferWrites ¶ added in v0.51.0
func CheckMockBufferWrites(
t *testing.T,
ctx context.Context,
start time.Time,
writes chan []*v1.SensorData,
expecteds []*v1.SensorData,
)
CheckMockBufferWrites checks that the Write match the expected data & metadata (timestamps).
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 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 FilterByStatus ¶ added in v0.42.0
func FilterByStatus(tb testing.TB, resourceStatuses []resource.Status, state resource.NodeState) []resource.Status
FilterByStatus takes a slice of resource.Status and a resource.NodeState and returns a slice of resource.Status that are in the given resource.NodeState.
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 ToStructPBStruct ¶ added in v0.51.0
func ToStructPBStruct(t *testing.T, v any) *structpb.Struct
ToStructPBStruct calls structpb.NewValue and fails tests if an error is encountered. Otherwise, returns a *structpb.Struct.
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. To make debugging failures easier, this function prints out differing resource.Name elements both as structs and strings.
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 MockBuffer ¶ added in v0.13.0
type MockBuffer struct {
Writes chan []*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 NewMockBuffer ¶ added in v0.51.0
func NewMockBuffer(t *testing.T) *MockBuffer
NewMockBuffer returns a mock buffer. This needs to be closed before the collector, otherwise the collector's Close method will block.
func (*MockBuffer) Close ¶ added in v0.51.0
func (m *MockBuffer) Close()
Close cancels the MockBuffer context so all methods stop blocking.
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) Path ¶ added in v0.13.0
func (m *MockBuffer) Path() string
Path returns a hardcoded fake path.
func (*MockBuffer) WriteBinary ¶ added in v0.55.0
func (m *MockBuffer) WriteBinary(items []*v1.SensorData) error
WriteBinary writes binary sensor data.
func (*MockBuffer) WriteTabular ¶ added in v0.55.0
func (m *MockBuffer) WriteTabular(item *v1.SensorData) error
WriteTabular writes tabular sensor data to the Writes channel.
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.
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.
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). |