| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package main
- import (
- "path/filepath"
- "testing"
- intdevice "netdome.biz/paul/qmk-rgb/internal/device"
- "netdome.biz/paul/qmk-rgb/internal/via"
- )
- // stubOpenTarget points the commands at one protocol, the display names a board
- // would supply and the channels that board has. It returns the restore function.
- func stubOpenTarget(t *testing.T, proto rgbProtocol, display map[uint16]string, channels []via.Channel, vendorID, productID uint16) func() {
- t.Helper()
- original := openTarget
- openTarget = func() (rgbProtocol, targetDeviceData, []via.Channel, error) {
- target := targetDeviceData{
- Device: intdevice.Device{VendorID: vendorID, ProductID: productID},
- Display: display,
- }
- requested, err := resolveZoneName(targetZone, display, nil)
- if err != nil {
- return nil, target, nil, err
- }
- target.Requested = requested
- resolved, err := resolveChannels(proto, target)
- if err != nil {
- return nil, target, nil, err
- }
- return proto, target, resolved, nil
- }
- return func() { openTarget = original }
- }
- // impact80Target is the board most command tests describe.
- func impact80Target(t *testing.T, proto rgbProtocol) func() {
- t.Helper()
- return stubOpenTarget(t, proto, impact80Display(), impact80Channels(), 0x36B0, 0x309F)
- }
- // withJSON turns on the machine shape for a test that asserts the JSON
- // commands, which print text unless it is asked for.
- func withJSON(t *testing.T) {
- t.Helper()
- original := jsonOutput
- jsonOutput = true
- t.Cleanup(func() { jsonOutput = original })
- }
- // vendoredDefinitions points the data directory at the repository's definitions,
- // so a test that needs the Impact 80's effect names uses the file that ships with
- // the tool rather than a catalog compiled in beside it. There is no such catalog
- // any more: the file is the only source of a name.
- func vendoredDefinitions(t *testing.T) func() {
- t.Helper()
- return forceDefinitionsDir(t, filepath.Join("..", "..", "definitions"))
- }
|