Documentation
¶
Overview ¶
Package testutils provides common testing utilities for reader tests.
Index ¶
- func AssertNoScan(t *testing.T, ch chan readers.Scan, timeout time.Duration)
- func AssertScanReceived(t *testing.T, ch chan readers.Scan, timeout time.Duration) readers.Scan
- func CreateTempDevicePath(t *testing.T) string
- func CreateTestScanChannel(_ *testing.T) chan readers.Scan
- func WaitForCondition(condition func() bool, timeout time.Duration) bool
- type MockSerialPort
- type SerialPort
- type SerialPortFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertNoScan ¶
AssertNoScan verifies that no scan is received on the channel within the timeout. Fails the test if a scan is received.
func AssertScanReceived ¶
AssertScanReceived waits for a scan to be received on the channel within the timeout. Returns the received scan. Fails the test if no scan is received within timeout.
func CreateTempDevicePath ¶
CreateTempDevicePath creates a temporary file to represent a device path for testing. On Windows systems, it returns a COM port path. On Unix systems, it creates a temporary file and registers cleanup with t.Cleanup().
func CreateTestScanChannel ¶
CreateTestScanChannel creates a buffered channel for reader scans with capacity of 10.
Types ¶
type MockSerialPort ¶
type MockSerialPort struct {
ReadError error
CloseError error
TimeoutErr error
ReadFunc func(p []byte) (n int, err error)
ReadData []byte
ReadIndex int
Closed bool
// contains filtered or unexported fields
}
MockSerialPort is a mock implementation of serial port for testing. It implements the common serial port interface used by readers.
func NewMockSerialPort ¶
func NewMockSerialPort() *MockSerialPort
NewMockSerialPort creates a new mock serial port for testing.
func (*MockSerialPort) Close ¶
func (m *MockSerialPort) Close() error
Close implements the Close method for serial ports.
func (*MockSerialPort) IsClosed ¶
func (m *MockSerialPort) IsClosed() bool
IsClosed returns true if the port has been closed (thread-safe).
func (*MockSerialPort) Read ¶
func (m *MockSerialPort) Read(p []byte) (n int, err error)
Read implements the Read method for serial ports. It supports custom read functions, error injection, and buffered data reading.
func (*MockSerialPort) SetReadTimeout ¶
func (m *MockSerialPort) SetReadTimeout(_ time.Duration) error
SetReadTimeout implements the SetReadTimeout method for serial ports.
type SerialPort ¶
type SerialPort = serialport.SerialPort
SerialPort preserves compatibility for existing reader test helpers.
func DefaultSerialPortFactory ¶
func DefaultSerialPortFactory(path string, mode *serial.Mode) (SerialPort, error)
DefaultSerialPortFactory delegates to the production serial factory.
type SerialPortFactory ¶
type SerialPortFactory = serialport.SerialPortFactory
SerialPortFactory preserves compatibility for existing reader test helpers.