google / gousb

gousb provides low-level interface for accessing USB devices
Apache License 2.0
838 stars 124 forks source link

Export fakelibusb test code #75

Open ghost opened 4 years ago

ghost commented 4 years ago

I would like to use fakelibusb_test.go in my USB code for unit testing as it seems pretty cool for mocking actual USB code. Can you maybe put it into a library so I can import it and use it for unit testing?

zagrodzki commented 4 years ago

I don't think it's particularly useful outside of gousb, since it fakes a very particular interface internal to gousb (gousb.libusbIntf).

It might be more interesting to offer a fake implementation of gousb.Context - this would be externally visible and could be used as a replacement for gousb.Context injection. It's useful only if you use gousb in your code. Would that be useful?

FWIW, I'm looking into adding a set of integration tests based on Linux virtual USB host driver (vhci-hcd), which I think would offer better fidelity compared to my fake libusbIntf implementation.

ghost commented 3 years ago

That sounds good, yeah :-)

zagrodzki commented 3 years ago

I assume the "sounds good" refers to "offer a fake implementation of gousb.Context". Unfortunately I don't expect to have time to work on that anytime soon. If anyone would like to offer a contribution, I'm happy to help with the design and review.