From 84628359edaf9106531491784b3517b912746682 Mon Sep 17 00:00:00 2001 From: hermes Date: Wed, 30 Sep 2026 21:59:32 +0200 Subject: [PATCH] add internal/infra/icecast_test.go --- internal/infra/icecast_test.go | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 internal/infra/icecast_test.go diff --git a/internal/infra/icecast_test.go b/internal/infra/icecast_test.go new file mode 100644 index 0000000..2c15074 --- /dev/null +++ b/internal/infra/icecast_test.go @@ -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 : %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") + } +}