| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package main
- import (
- "bytes"
- "testing"
- intrgb "netdome.biz/paul/qmk-rgb/internal/rgb"
- )
- // README.md: "With `--zone`, commands target exactly the selected channel."
- // A profile key names a channel, so a load applies only the keys that resolve to
- // a selected channel. The keys themselves are resolved by resolveZoneName, which
- // channels_test.go covers; what matters here is that a key is never applied to a
- // channel it does not name.
- func TestLoadAppliesOnlyTheKeysTheSelectionNames(t *testing.T) {
- dir := t.TempDir()
- profile := Profile{
- Name: "three",
- Version: 1,
- Zones: map[string]*ZoneSettings{
- "logo": {Enabled: true, Effect: "light", Brightness: 100, Speed: 1, Color: "00ff"},
- "backlight": {Enabled: true, Effect: "solid_color", Brightness: 100, Speed: 1, Color: "00ff"},
- "side": {Enabled: true, Effect: "wave", Brightness: 100, Speed: 1, Color: "00ff"},
- },
- }
- originalDir := profilesDir
- t.Cleanup(func() { profilesDir = originalDir })
- profilesDir = dir
- if err := profile.Save(); err != nil {
- t.Fatalf("save profile: %v", err)
- }
- tests := []struct {
- name string
- zoneFlag string
- wantApplied int
- }{
- {"no flag applies all three", "", 3},
- {"logo applies one", "logo", 1},
- {"backlight applies one", "backlight", 1},
- {"side applies one", "side", 1},
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- proto := &verifyingProtocol{}
- restore := stubTargetForProfileTest(t, proto, tt.zoneFlag, impact80Display())
- defer restore()
- cmd := NewProfileLoadCmd()
- cmd.SetOut(&bytes.Buffer{})
- cmd.SetErr(&bytes.Buffer{})
- cmd.SetArgs([]string{"three"})
- if err := cmd.Execute(); err != nil {
- t.Fatalf("load returned error: %v", err)
- }
- if got := effectWrites(proto); got != tt.wantApplied {
- t.Errorf("effect writes = %d, want %d", got, tt.wantApplied)
- }
- })
- }
- }
- // effectWrites counts the effect writes, one per applied channel.
- func effectWrites(proto *verifyingProtocol) int {
- count := 0
- for _, r := range proto.reports {
- if r.param == uint8(intrgb.EffectID) {
- count++
- }
- }
- return count
- }
|