Files
supersonic/backend/servermanager_test.go
T
Drew WeymouthandClaude Sonnet 4.6 9dd606ce73 Normalize server URLs before connecting (#861)
* Fix #304: normalize server URLs before connecting

Prepend http:// when no scheme is present and strip trailing slashes
for all server types. For Jellyfin, additionally strip /web/index.html
and /web path suffixes that users copy from the browser URL bar.

Normalization is applied in ServerManager.connect() on the by-value
parameter, so stored config is never mutated.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* move url normalize funcs

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-17 19:34:47 -08:00

50 lines
1.6 KiB
Go

package backend
import "testing"
func TestNormalizeServerURL(t *testing.T) {
tests := []struct {
input string
want string
}{
{"", ""},
{"http://192.168.1.1:8096", "http://192.168.1.1:8096"},
{"https://music.example.com", "https://music.example.com"},
{"192.168.1.1:4533", "http://192.168.1.1:4533"},
{"music.example.com", "http://music.example.com"},
{"http://192.168.1.1:8096/", "http://192.168.1.1:8096"},
{"http://192.168.1.1:8096///", "http://192.168.1.1:8096"},
{"192.168.1.1:8096/", "http://192.168.1.1:8096"},
}
for _, tt := range tests {
got := NormalizeServerURL(tt.input)
if got != tt.want {
t.Errorf("NormalizeServerURL(%q) = %q, want %q", tt.input, got, tt.want)
}
}
}
func TestNormalizeJellyfinURL(t *testing.T) {
tests := []struct {
input string
want string
}{
{"", ""},
{"http://192.168.1.1:8096", "http://192.168.1.1:8096"},
{"192.168.1.1:8096", "http://192.168.1.1:8096"},
{"192.168.1.1:8096/", "http://192.168.1.1:8096"},
{"192.168.1.1:8096/web/index.html", "http://192.168.1.1:8096"},
{"http://192.168.1.1:8096/web/index.html", "http://192.168.1.1:8096"},
{"http://192.168.1.1:8096/web/", "http://192.168.1.1:8096"},
{"http://192.168.1.1:8096/web", "http://192.168.1.1:8096"},
{"https://jellyfin.example.com/web/index.html", "https://jellyfin.example.com"},
{"https://jellyfin.example.com/web/", "https://jellyfin.example.com"},
}
for _, tt := range tests {
got := NormalizeJellyfinURL(tt.input)
if got != tt.want {
t.Errorf("NormalizeJellyfinURL(%q) = %q, want %q", tt.input, got, tt.want)
}
}
}