Files
bjarneo--cliamp/tracksave/save_test.go
T
Bjarne Øverli 7404285d1f
CI / go (push) Has been cancelled
CI / build (darwin, macos-14) (push) Has been cancelled
CI / build (windows, windows-2025) (push) Has been cancelled
Release / build (amd64, darwin, macos-latest) (push) Has been cancelled
Release / build (amd64, linux, ubuntu-latest) (push) Has been cancelled
Release / build (amd64, windows, windows-latest) (push) Has been cancelled
Release / build (arm64, darwin, macos-latest) (push) Has been cancelled
Release / build (arm64, linux, ubuntu-latest) (push) Has been cancelled
Release / release (push) Has been cancelled
Release / update-homebrew (push) Has been cancelled
fix(ci): restore cross-platform checks
2026-07-21 23:15:49 +02:00

53 lines
1.2 KiB
Go

package tracksave
import (
"os"
"path/filepath"
"testing"
"github.com/bjarneo/cliamp/playlist"
)
func TestSaveCopiesTemporaryDownload(t *testing.T) {
home := setTestHome(t)
source, err := os.CreateTemp("", "cliamp-save-*.flac")
if err != nil {
t.Fatal(err)
}
sourcePath := source.Name()
t.Cleanup(func() { _ = os.Remove(sourcePath) })
if _, err := source.WriteString("audio"); err != nil {
t.Fatal(err)
}
if err := source.Close(); err != nil {
t.Fatal(err)
}
destination, err := Save(playlist.Track{Path: sourcePath, Title: "Song", Artist: "Artist"})
if err != nil {
t.Fatal(err)
}
want := filepath.Join(home, "Music", "cliamp", "Artist - Song.flac")
if destination != want {
t.Fatalf("destination = %q, want %q", destination, want)
}
if data, err := os.ReadFile(destination); err != nil || string(data) != "audio" {
t.Fatalf("saved data = %q, err=%v", data, err)
}
}
func TestSaveRejectsUserLibraryFile(t *testing.T) {
setTestHome(t)
if _, err := Save(playlist.Track{Path: "/var/lib/music/song.flac"}); err == nil {
t.Fatal("Save accepted a non-temporary library file")
}
}
func setTestHome(t *testing.T) string {
t.Helper()
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
return home
}