package usb import ( "io" "sync" ) // mockPort implements serialPort for testing without hardware. // Reads block until Close() is called (simulating a hardware device that // stays connected until explicitly disconnected). type mockPort struct { mu sync.Mutex closed bool closeCh chan struct{} } func newMockPort() *mockPort { return &mockPort{ closeCh: make(chan struct{}), } } // Read blocks until the port is closed, then returns io.EOF. // This mirrors the behaviour of a real serial port: Read blocks until data // arrives or the port is closed. func (p *mockPort) Read(buf []byte) (int, error) { <-p.closeCh return 0, io.EOF } // Write is a no-op for the mock (no hardware to write to). func (p *mockPort) Write(data []byte) (int, error) { p.mu.Lock() defer p.mu.Unlock() if p.closed { return 0, io.ErrClosedPipe } return len(data), nil } // Close signals the mock port as closed, unblocking any pending Read. func (p *mockPort) Close() error { p.mu.Lock() defer p.mu.Unlock() if !p.closed { p.closed = true close(p.closeCh) } return nil }