Monitor MPD FIFO output status for audio sources
This commit is contained in:
9 files changed
+159
-1
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package mpd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFIFOOutputState(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name, response, output, want string
|
||||
}{
|
||||
{"enabled", "outputid: 0\noutputname: DAC\nplugin: alsa\noutputenabled: 0\noutputid: 1\noutputname: Visualizer\nplugin: fifo\noutputenabled: 1", "", ""},
|
||||
{"disabled", "outputid: 2\noutputname: Visualizer\nplugin: fifo\noutputenabled: 0", "", "disabled"},
|
||||
{"missing", "outputid: 0\noutputname: DAC\nplugin: alsa\noutputenabled: 1", "", "no matching"},
|
||||
{"ambiguous", "outputid: 1\noutputname: One\nplugin: fifo\noutputenabled: 1\noutputid: 2\noutputname: Two\nplugin: fifo\noutputenabled: 0", "", "multiple"},
|
||||
{"select named disabled", "outputid: 1\noutputname: One\nplugin: fifo\noutputenabled: 1\noutputid: 2\noutputname: Two\nplugin: fifo\noutputenabled: 0", "Two", "disabled"},
|
||||
{"legacy named", "outputid: 1\noutputname: Visualizer\noutputenabled: 1", "Visualizer", ""},
|
||||
{"legacy unidentified", "outputid: 1\noutputname: Visualizer\noutputenabled: 1", "", "no matching"},
|
||||
{"wrong plugin", "outputid: 1\noutputname: Visualizer\nplugin: alsa\noutputenabled: 1", "Visualizer", "no matching"},
|
||||
{"empty", "", "", "no matching"},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := fifoOutputState(parseOutputs(strings.Split(tt.response, "\n")), tt.output)
|
||||
if tt.want == "" {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
} else if err == nil || !strings.Contains(err.Error(), tt.want) {
|
||||
t.Fatalf("got %v, want error containing %q", err, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user