target_seam_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package main
  2. import (
  3. "testing"
  4. intdevice "netdome.biz/paul/qmk-rgb/internal/device"
  5. "netdome.biz/paul/qmk-rgb/internal/via"
  6. )
  7. // stubOpenTarget points the commands at one protocol, the display names a board
  8. // would supply and the channels that board has. It returns the restore function.
  9. func stubOpenTarget(t *testing.T, proto rgbProtocol, display map[uint16]string, channels []via.Channel, vendorID, productID uint16) func() {
  10. t.Helper()
  11. original := openTarget
  12. openTarget = func() (rgbProtocol, targetDeviceData, []via.Channel, error) {
  13. target := targetDeviceData{
  14. Device: intdevice.Device{VendorID: vendorID, ProductID: productID},
  15. Display: display,
  16. }
  17. requested, err := resolveZoneName(targetZone, display)
  18. if err != nil {
  19. return nil, target, nil, err
  20. }
  21. target.Requested = requested
  22. resolved, err := resolveChannels(proto, target)
  23. if err != nil {
  24. return nil, target, nil, err
  25. }
  26. return proto, target, resolved, nil
  27. }
  28. return func() { openTarget = original }
  29. }
  30. // impact80Target is the board most command tests describe.
  31. func impact80Target(t *testing.T, proto rgbProtocol) func() {
  32. t.Helper()
  33. return stubOpenTarget(t, proto, impact80Display(), impact80Channels(), 0x36B0, 0x309F)
  34. }