Terminal Jellyfin client, watch-side companion to TUISTREAM. - LAN auto-discovery (broadcast + unicast subnet sweep) - mpv-window video playback over JSON IPC (pause/seek/progress/resume) - headless audio playback with in-terminal now-playing screen - volume control with remembered level, mute - audio auto-advance + n/p track skip through the album queue - Omarchy-themed UI with Nerd Font (nf-md) icons - cliamp Jellyfin provider auto-config on login - pacman dependency-installing installer Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
63 lines
2.1 KiB
Go
63 lines
2.1 KiB
Go
package cliamp
|
|
|
|
import "testing"
|
|
|
|
func TestMergeSection_AppendWhenAbsent(t *testing.T) {
|
|
existing := "[plex]\nurl = \"http://plex\"\ntoken = \"abc\"\n"
|
|
block := Creds{URL: "http://jf", Token: "tok", UserID: "uid"}.block()
|
|
got := mergeSection(existing, "jellyfin", block)
|
|
|
|
// The plex section must survive untouched.
|
|
if !contains(got, "[plex]") || !contains(got, `url = "http://plex"`) || !contains(got, `token = "abc"`) {
|
|
t.Fatalf("plex section not preserved:\n%s", got)
|
|
}
|
|
// The jellyfin section must be appended.
|
|
if !contains(got, "[jellyfin]") || !contains(got, `token = "tok"`) || !contains(got, `user_id = "uid"`) {
|
|
t.Fatalf("jellyfin section not appended:\n%s", got)
|
|
}
|
|
}
|
|
|
|
func TestMergeSection_ReplaceExisting(t *testing.T) {
|
|
existing := "[jellyfin]\nurl = \"old\"\ntoken = \"OLD\"\n\n[spotify]\nclient = \"sp\"\n"
|
|
block := Creds{URL: "http://new", Token: "NEW", UserID: "uid"}.block()
|
|
got := mergeSection(existing, "jellyfin", block)
|
|
|
|
if contains(got, `token = "OLD"`) || contains(got, `url = "old"`) {
|
|
t.Fatalf("old jellyfin values not replaced:\n%s", got)
|
|
}
|
|
if !contains(got, `token = "NEW"`) || !contains(got, `url = "http://new"`) {
|
|
t.Fatalf("new jellyfin values missing:\n%s", got)
|
|
}
|
|
// The spotify section after jellyfin must survive.
|
|
if !contains(got, "[spotify]") || !contains(got, `client = "sp"`) {
|
|
t.Fatalf("spotify section not preserved:\n%s", got)
|
|
}
|
|
}
|
|
|
|
func TestMergeSection_EmptyDoc(t *testing.T) {
|
|
block := Creds{URL: "http://jf", Token: "tok", UserID: "uid"}.block()
|
|
got := mergeSection("", "jellyfin", block)
|
|
if got != block+"\n" {
|
|
t.Fatalf("empty-doc merge wrong:\n%q", got)
|
|
}
|
|
}
|
|
|
|
func TestBlock_OmitsEmptyFields(t *testing.T) {
|
|
got := Creds{URL: "http://jf", Token: "tok", UserID: "uid"}.block()
|
|
if contains(got, "user =") || contains(got, "password =") {
|
|
t.Fatalf("empty user/password should be omitted:\n%s", got)
|
|
}
|
|
}
|
|
|
|
func contains(haystack, needle string) bool {
|
|
return len(haystack) >= len(needle) && indexOf(haystack, needle) >= 0
|
|
}
|
|
|
|
func indexOf(s, sub string) int {
|
|
for i := 0; i+len(sub) <= len(s); i++ {
|
|
if s[i:i+len(sub)] == sub {
|
|
return i
|
|
}
|
|
}
|
|
return -1
|
|
}
|