add internal/infra/icecast_test.go

This commit is contained in:
2026-09-30 21:59:32 +02:00
parent 543343070b
commit 84628359ed
+51
View File
@@ -0,0 +1,51 @@
package infra
import (
"strings"
"testing"
)
func TestIcecastSourceRequest(t *testing.T) {
req := buildSourceRequest("hackme", SourceMeta{
Mount: "/ai-radio.mp3",
Name: "AI Radio",
Genre: "AI Generated",
Bitrate: "128",
URL: "http://example.com",
Description: "Endless AI radio",
})
if !strings.HasPrefix(req, "SOURCE hackme\r\n") {
t.Fatalf("request must start with SOURCE <password>: %q", req[:40])
}
for _, want := range []string{
"mount: /ai-radio.mp3\r\n",
"ice-name: AI Radio\r\n",
"ice-genre: AI Generated\r\n",
"ice-bitrate: 128\r\n",
"ice-public: 1\r\n",
"content-type: audio/mpeg\r\n",
} {
if !strings.Contains(req, want) {
t.Fatalf("missing header %q in:\n%s", want, req)
}
}
// must terminate with blank line
if !strings.HasSuffix(req, "\r\n\r\n") {
t.Fatal("request must end with CRLF CRLF")
}
}
func TestParseIcecastResponse(t *testing.T) {
ok, msg := parseSourceResponse("HTTP/1.1 200 OK\r\nicestreamid: abc\r\n\r\n")
if !ok {
t.Fatalf("200 should be accepted: %s", msg)
}
ok, msg = parseSourceResponse("HTTP/1.1 401 Unauthorized\r\n\r\n")
if ok {
t.Fatalf("401 must be rejected: %s", msg)
}
ok, _ = parseSourceResponse("HTTP/1.0 200 OK\r\n")
if !ok {
t.Fatal("HTTP/1.0 200 should be accepted")
}
}