Files
radiantwave-legacy/internal/page/AudioDevices_test.go
T
NeilClack 312f5e2a90
build-prod.yml / build (push) Failing after 2s
build-dev.yml / build (push) Failing after 2s
Rename rhemawave to radiantwave throughout
2026-08-08 01:20:11 -05:00

44 lines
1.3 KiB
Go

package page
import (
"testing"
"radiantwavetech.com/radiantwave/internal/mixer"
)
func TestCurrentDeviceIndex(t *testing.T) {
devices := []mixer.Device{
{Name: "Built-in Audio Analog Stereo", Label: "Internal Speakers"},
{Name: "Built-in Audio Digital Stereo (HDMI)", Label: "HDMI | Monitor | TV"},
}
singleDevice := []mixer.Device{
{Name: "Built-in Audio Analog Stereo", Label: "Internal Speakers"},
}
tests := []struct {
name string
devices []mixer.Device
currentName string
want int
}{
{"empty list, default device", nil, "", 0},
{"empty list, named device", nil, "USB Audio", -1},
{"default device", devices, "", 0},
{"exact first device match", devices, "Built-in Audio Analog Stereo", 1},
{"exact second device match", devices, "Built-in Audio Digital Stereo (HDMI)", 2},
{"no match", devices, "USB Audio", -1},
{"single device, default", singleDevice, "", 0},
{"single device, exact match", singleDevice, "Built-in Audio Analog Stereo", 1},
{"single device, no match", singleDevice, "USB Audio", -1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := currentDeviceIndex(tt.devices, tt.currentName); got != tt.want {
t.Errorf("currentDeviceIndex(%v, %q) = %d, want %d", tt.devices, tt.currentName, got, tt.want)
}
})
}
}