package download import ( "context" "net/http" "net/http/httptest" "os" "path/filepath" "testing" ) func TestDownloaderHasNoClientTimeout(t *testing.T) { d := NewWithOptions(true, false) if d.http.Timeout != 0 { t.Fatalf("http timeout = %v, want 0 (no global timeout)", d.http.Timeout) } } func TestDownloaderFile(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte("abc123")) })) defer ts.Close() d := New() out := filepath.Join(t.TempDir(), "x", "a.bin") if err := d.File(context.Background(), ts.URL, out); err != nil { t.Fatalf("File() error = %v", err) } b, err := os.ReadFile(out) if err != nil { t.Fatalf("ReadFile() error = %v", err) } if string(b) != "abc123" { t.Fatalf("contents = %q, want %q", string(b), "abc123") } } func TestManifestDetection(t *testing.T) { if !isManifestResponse("application/dash+xml", []byte("x")) { t.Fatalf("expected dash content-type to be manifest") } if !isManifestResponse("application/octet-stream", []byte("")) { t.Fatalf("expected MPD XML body to be manifest") } if !isManifestResponse("text/plain", []byte("#EXTM3U\n#EXT-X-VERSION:3")) { t.Fatalf("expected HLS body to be manifest") } if isManifestResponse("audio/flac", []byte("fLaC")) { t.Fatalf("did not expect flac to be manifest") } }