test: cover hls playlist response

This commit is contained in:
2026-06-16 01:18:49 +02:00
committed by Milas Holsting
parent e836d464cb
commit a2d16caea0

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"mal/internal/domain" "mal/internal/domain"
"net/http"
"strings" "strings"
"testing" "testing"
) )
@@ -77,7 +78,45 @@ func TestRewriteHLSPlaylistProxiesSegmentAndKeyURIs(t *testing.T) {
} }
func TestIsHLSPlaylistResponse(t *testing.T) { func TestIsHLSPlaylistResponse(t *testing.T) {
if !isHLSPlaylistResponse("https://example.test/master.m3u8?token=abc", nil) { tests := []struct {
t.Fatal("expected .m3u8 URL to be treated as playlist") name string
target string
headers map[string]string
want bool
}{
{
name: "playlist url",
target: "https://example.test/master.m3u8?token=abc",
want: true,
},
{
name: "playlist content type",
target: "https://example.test/video.bin",
headers: map[string]string{
"Content-Type": "application/x-mpegurl; charset=utf-8",
},
want: true,
},
{
name: "non playlist",
target: "https://example.test/video.bin",
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var headers http.Header
if len(tt.headers) > 0 {
headers = make(http.Header)
for key, value := range tt.headers {
headers.Set(key, value)
}
}
if got := isHLSPlaylistResponse(tt.target, headers); got != tt.want {
t.Fatalf("isHLSPlaylistResponse() = %v, want %v", got, tt.want)
}
})
} }
} }