mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
harden qobuz and downloader reliability edge cases
This commit is contained in:
@@ -3,6 +3,8 @@ package download
|
||||
import (
|
||||
"context"
|
||||
"crypto/cipher"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
@@ -120,3 +122,39 @@ func TestFileDeezerEncrypted(t *testing.T) {
|
||||
t.Fatalf("decrypted file mismatch")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDownloaderFileTruncatedResponseRemovesPartialFile(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Content-Length", "10")
|
||||
_, _ = w.Write([]byte("abc"))
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
d := NewWithOptions(true, false)
|
||||
out := filepath.Join(t.TempDir(), "x", "a.bin")
|
||||
err := d.File(context.Background(), ts.URL, out)
|
||||
if err == nil || !errors.Is(err, io.ErrUnexpectedEOF) {
|
||||
t.Fatalf("expected unexpected EOF, got %v", err)
|
||||
}
|
||||
if _, statErr := os.Stat(out); !errors.Is(statErr, os.ErrNotExist) {
|
||||
t.Fatalf("expected no partial file, stat err=%v", statErr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileDeezerEncryptedTruncatedResponseRemovesPartialFile(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Content-Length", "4096")
|
||||
_, _ = w.Write([]byte("short"))
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
d := NewWithOptions(true, false)
|
||||
out := filepath.Join(t.TempDir(), "x", "a.flac")
|
||||
err := d.FileDeezerEncrypted(context.Background(), ts.URL, out, "3135556")
|
||||
if err == nil || !errors.Is(err, io.ErrUnexpectedEOF) {
|
||||
t.Fatalf("expected unexpected EOF, got %v", err)
|
||||
}
|
||||
if _, statErr := os.Stat(out); !errors.Is(statErr, os.ErrNotExist) {
|
||||
t.Fatalf("expected no partial file, stat err=%v", statErr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user