initial Go port of streamrip

This commit is contained in:
2026-04-19 21:11:38 +02:00
commit 97e8b758b3
32 changed files with 7008 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
package config
import (
"errors"
"os"
"path/filepath"
"testing"
)
func TestDefaultConfigData(t *testing.T) {
data := DefaultConfigData()
if data.Misc.Version != CurrentConfigVersion {
t.Fatalf("version = %q, want %q", data.Misc.Version, CurrentConfigVersion)
}
if data.Downloads.Folder == "" {
t.Fatalf("downloads folder should not be empty")
}
if data.Database.DownloadsPath == "" || data.Database.FailedDownloadsPath == "" {
t.Fatalf("database paths should not be empty")
}
}
func TestLoadCreatesDefaultConfigWhenMissing(t *testing.T) {
tmpDir := t.TempDir()
path := filepath.Join(tmpDir, "config.toml")
cfg, err := Load(path)
if err != nil {
t.Fatalf("Load() error = %v", err)
}
if cfg.Path != path {
t.Fatalf("path = %q, want %q", cfg.Path, path)
}
if _, err = os.Stat(path); err != nil {
t.Fatalf("expected created config file: %v", err)
}
}
func TestLoadOutdatedConfig(t *testing.T) {
tmpDir := t.TempDir()
path := filepath.Join(tmpDir, "config.toml")
data := DefaultConfigData()
data.Misc.Version = "1.0.0"
if err := saveConfigData(path, data); err != nil {
t.Fatalf("saveConfigData() error = %v", err)
}
_, err := Load(path)
if !errors.Is(err, ErrOutdatedConfig) {
t.Fatalf("Load() error = %v, want ErrOutdatedConfig", err)
}
}
func TestSessionCloneDoesNotAliasSlices(t *testing.T) {
tmpDir := t.TempDir()
path := filepath.Join(tmpDir, "config.toml")
data := DefaultConfigData()
data.Metadata.Exclude = []string{"lyrics"}
data.Qobuz.Secrets = []string{"s1"}
if err := saveConfigData(path, data); err != nil {
t.Fatalf("saveConfigData() error = %v", err)
}
cfg, err := Load(path)
if err != nil {
t.Fatalf("Load() error = %v", err)
}
cfg.Session.Metadata.Exclude[0] = "comment"
cfg.Session.Qobuz.Secrets[0] = "s2"
if cfg.File.Metadata.Exclude[0] != "lyrics" {
t.Fatalf("file metadata exclude unexpectedly mutated")
}
if cfg.File.Qobuz.Secrets[0] != "s1" {
t.Fatalf("file qobuz secrets unexpectedly mutated")
}
}