| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package rgb
- import (
- "testing"
- "github.com/spf13/cobra"
- )
- func TestLightingEnabledRequiresActiveEffectAndBrightness(t *testing.T) {
- cases := []struct {
- name string
- mode uint8
- brightness uint8
- want bool
- }{
- {"active", 1, 160, true},
- {"zero brightness", 1, 0, false},
- {"disabled effect", 0, 160, false},
- {"both zero", 0, 0, false},
- }
- for _, tc := range cases {
- t.Run(tc.name, func(t *testing.T) {
- if got := lightingEnabled(tc.mode, tc.brightness); got != tc.want {
- t.Errorf("lightingEnabled(%d, %d) = %t, want %t", tc.mode, tc.brightness, got, tc.want)
- }
- })
- }
- }
- func TestDeviceFlagIsInheritedByRGBCommands(t *testing.T) {
- originalTargetDevice := targetDevice
- t.Cleanup(func() { targetDevice = originalTargetDevice })
- const wantPath = "/dev/hidraw5"
- ran := false
- cmd := Init()
- cmd.AddCommand(&cobra.Command{
- Use: "probe",
- Run: func(*cobra.Command, []string) { ran = true },
- })
- cmd.SetArgs([]string{"--device", wantPath, "probe"})
- if err := cmd.Execute(); err != nil {
- t.Fatalf("Execute() error = %v", err)
- }
- if !ran {
- t.Fatal("child command did not run")
- }
- if targetDevice != wantPath {
- t.Errorf("targetDevice = %q, want %q", targetDevice, wantPath)
- }
- }
|