summaryrefslogtreecommitdiff
path: root/internal/gui/audio_player_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-02 16:36:25 +0300
committerPaul Buetow <paul@buetow.org>2026-04-02 16:36:25 +0300
commit6bd23a588bacee2e8c75f477150b7e2d345002ff (patch)
tree67bfa78afe206e7560350bdd52c60e0e80ec3243 /internal/gui/audio_player_test.go
parent6ce9123de04ffff961cbf1da73648679216ff637 (diff)
Release v0.9.0v0.9.0
Diffstat (limited to 'internal/gui/audio_player_test.go')
-rw-r--r--internal/gui/audio_player_test.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/internal/gui/audio_player_test.go b/internal/gui/audio_player_test.go
new file mode 100644
index 0000000..2dd3b0c
--- /dev/null
+++ b/internal/gui/audio_player_test.go
@@ -0,0 +1,60 @@
+package gui
+
+import (
+ "errors"
+ "path/filepath"
+ "reflect"
+ "testing"
+)
+
+func TestLinuxAudioCommandCandidates(t *testing.T) {
+ t.Run("mp3 prefers mpg123", func(t *testing.T) {
+ audioFile := "/tmp/audio.mp3"
+ got := linuxAudioCommandCandidates(audioFile)
+ want := []audioCommandCandidate{
+ {name: "mpg123", args: []string{"-q", audioFile}},
+ {name: "ffplay", args: []string{"-nodisp", "-autoexit", "-loglevel", "quiet", audioFile}},
+ {name: "play", args: []string{"-q", audioFile}},
+ {name: "paplay", args: []string{audioFile}},
+ {name: "aplay", args: []string{"-q", audioFile}},
+ }
+ if !reflect.DeepEqual(got, want) {
+ t.Fatalf("linuxAudioCommandCandidates(mp3) mismatch\nwant: %#v\ngot: %#v", want, got)
+ }
+ })
+
+ t.Run("wav avoids mpg123", func(t *testing.T) {
+ audioFile := "/tmp/audio.wav"
+ got := linuxAudioCommandCandidates(audioFile)
+ if got[0].name != "ffplay" {
+ t.Fatalf("first wav candidate = %q, want %q", got[0].name, "ffplay")
+ }
+ for _, candidate := range got {
+ if candidate.name == "mpg123" {
+ t.Fatalf("wav candidates unexpectedly include mpg123: %#v", got)
+ }
+ }
+ })
+}
+
+func TestLinuxAudioPlaybackCommandUsesFormatCompatiblePlayer(t *testing.T) {
+ audioFile := "/tmp/audio.wav"
+ cmd, err := linuxAudioPlaybackCommand(audioFile, func(name string) (string, error) {
+ switch name {
+ case "ffplay":
+ return filepath.Join("/usr/bin", name), nil
+ default:
+ return "", errors.New("not found")
+ }
+ })
+ if err != nil {
+ t.Fatalf("linuxAudioPlaybackCommand() unexpected error: %v", err)
+ }
+
+ if got, want := filepath.Base(cmd.Path), "ffplay"; got != want {
+ t.Fatalf("command path base = %q, want %q", got, want)
+ }
+ if len(cmd.Args) < 2 || cmd.Args[len(cmd.Args)-1] != audioFile {
+ t.Fatalf("command args = %#v, want final arg %q", cmd.Args, audioFile)
+ }
+}