Files
Bjarne Øverli 0fe84edc80
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
Make SoundCloud provider opt-in
SoundCloud is now off by default and requires [soundcloud] enabled = true
in config.toml to register. Previously it was always enabled and users had
to opt out with enabled = false.

Why: SoundCloud playback requires yt-dlp, and a non-trivial number of
users don't have it installed. Showing the provider when it can't actually
play anything was confusing. Opt-in matches the pattern used by Spotify,
Plex, Jellyfin, Emby, and Navidrome.

- config: rename SoundCloudConfig.Disabled to Enabled and flip the
  parser to check for 'true' instead of 'false'.
- soundcloud: rename Config.Disabled to Enabled, NewFromConfig now
  returns nil unless cfg.Enabled is true.
- docs/soundcloud.md, docs/configuration.md, config.toml.example,
  site/index.html: reframe as opt-in with enabled = true examples.
2026-05-05 18:49:39 +02:00

137 lines
3.2 KiB
Go

package config
import (
"os"
"path/filepath"
"testing"
)
func TestLoadSoundCloudDisabledByDefault(t *testing.T) {
t.Setenv("HOME", t.TempDir())
cfg, err := Load()
if err != nil {
t.Fatalf("Load: %v", err)
}
if cfg.SoundCloud.Enabled {
t.Error("SoundCloud.Enabled = true with no config, want false")
}
if cfg.SoundCloud.IsSet() {
t.Error("SoundCloud.IsSet() = true with no config, want false")
}
}
func TestLoadSoundCloudExplicitlyEnabled(t *testing.T) {
t.Setenv("HOME", t.TempDir())
path := filepath.Join(os.Getenv("HOME"), ".config", "cliamp", "config.toml")
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatalf("MkdirAll: %v", err)
}
data := []byte(`
[soundcloud]
enabled = true
user = "alice"
`)
if err := os.WriteFile(path, data, 0o644); err != nil {
t.Fatalf("WriteFile: %v", err)
}
cfg, err := Load()
if err != nil {
t.Fatalf("Load: %v", err)
}
if !cfg.SoundCloud.Enabled {
t.Error("SoundCloud.Enabled = false, want true")
}
if cfg.SoundCloud.User != "alice" {
t.Errorf("SoundCloud.User = %q, want alice", cfg.SoundCloud.User)
}
if !cfg.SoundCloud.IsSet() {
t.Error("SoundCloud.IsSet() = false, want true")
}
}
func TestLoadSoundCloudSectionWithoutEnabledStaysOff(t *testing.T) {
t.Setenv("HOME", t.TempDir())
path := filepath.Join(os.Getenv("HOME"), ".config", "cliamp", "config.toml")
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatalf("MkdirAll: %v", err)
}
data := []byte(`
[soundcloud]
user = "alice"
`)
if err := os.WriteFile(path, data, 0o644); err != nil {
t.Fatalf("WriteFile: %v", err)
}
cfg, err := Load()
if err != nil {
t.Fatalf("Load: %v", err)
}
if cfg.SoundCloud.Enabled {
t.Error("SoundCloud.Enabled = true without explicit enabled = true, want false")
}
if cfg.SoundCloud.IsSet() {
t.Error("SoundCloud.IsSet() = true without explicit enabled = true, want false")
}
}
func TestLoadSoundCloudCookiesFrom(t *testing.T) {
t.Setenv("HOME", t.TempDir())
path := filepath.Join(os.Getenv("HOME"), ".config", "cliamp", "config.toml")
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatalf("MkdirAll: %v", err)
}
data := []byte(`
[soundcloud]
enabled = true
user = "alice"
cookies_from = "firefox"
`)
if err := os.WriteFile(path, data, 0o644); err != nil {
t.Fatalf("WriteFile: %v", err)
}
cfg, err := Load()
if err != nil {
t.Fatalf("Load: %v", err)
}
if cfg.SoundCloud.CookiesFrom != "firefox" {
t.Errorf("SoundCloud.CookiesFrom = %q, want firefox", cfg.SoundCloud.CookiesFrom)
}
}
func TestLoadSoundCloudInterpolatesUserFromEnv(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("CLIAMP_TEST_SC_USER", "carol")
path := filepath.Join(os.Getenv("HOME"), ".config", "cliamp", "config.toml")
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatalf("MkdirAll: %v", err)
}
data := []byte(`
[soundcloud]
enabled = true
user = "${CLIAMP_TEST_SC_USER}"
`)
if err := os.WriteFile(path, data, 0o644); err != nil {
t.Fatalf("WriteFile: %v", err)
}
cfg, err := Load()
if err != nil {
t.Fatalf("Load: %v", err)
}
if cfg.SoundCloud.User != "carol" {
t.Errorf("SoundCloud.User = %q, want carol (from env)", cfg.SoundCloud.User)
}
}