diff --git a/internal/protocol/http/fetcher_test.go b/internal/protocol/http/fetcher_test.go index 1c86c43e..377266d5 100644 --- a/internal/protocol/http/fetcher_test.go +++ b/internal/protocol/http/fetcher_test.go @@ -314,62 +314,11 @@ func TestFetcher_DownloadChunkedContinue(t *testing.T) { downloadContinue(listener, 1, t) } -func TestFetcher_DownloadNoRangeWithSize(t *testing.T) { - listener := test.StartTestNoRangeServer() - defer listener.Close() - - downloadNormal(listener, 1, t) -} - -func TestFetcher_DownloadNoRangeContinue(t *testing.T) { - listener := test.StartTestNoRangeServer() - defer listener.Close() - - downloadContinue(listener, 1, t) -} - -// TestFetcher_DownloadNoRangeNotExceedSize verifies that when a server returns -// Content-Length but doesn't support Range requests, the downloaded bytes never -// exceed the total file size after pause and resume. -func TestFetcher_DownloadNoRangeNotExceedSize(t *testing.T) { - listener := test.StartTestNoRangeServer() - defer listener.Close() - - fetcher := downloadReady(listener, 1, t) - err := fetcher.Start() - if err != nil { - t.Fatal(err) - } - // Let it download some data - time.Sleep(time.Millisecond * 50) - if err := fetcher.Pause(); err != nil { - t.Fatal(err) - } - time.Sleep(time.Millisecond * 50) - if err := fetcher.Start(); err != nil { - t.Fatal(err) - } - err = fetcher.Wait() - if err != nil { - t.Fatal(err) - } - - // Verify total downloaded does not exceed file size - totalDownloaded := fetcher.Progress().TotalDownloaded() - if totalDownloaded > test.BuildSize { - t.Errorf("Downloaded %d bytes exceeds file size %d", totalDownloaded, test.BuildSize) - } - - want := test.FileMd5(test.BuildFile) - got := test.FileMd5(test.DownloadFile) - if want != got { - t.Errorf("Download() got = %v, want %v", got, want) - } -} - // TestFetcher_DownloadChunkedNotExceedSize verifies that when a server doesn't -// return Content-Length (chunked transfer), the download properly handles -// pause/resume without accumulating extra bytes. +// return Content-Length (chunked transfer, no Range support), the download +// properly handles pause/resume without accumulating extra bytes. +// This simulates the real-world bug where servers like GitHub's zip downloads +// don't return Content-Length. func TestFetcher_DownloadChunkedNotExceedSize(t *testing.T) { listener := test.StartTestCustomServer() defer listener.Close() diff --git a/internal/test/httptest.go b/internal/test/httptest.go index f3cd535b..67760009 100644 --- a/internal/test/httptest.go +++ b/internal/test/httptest.go @@ -636,25 +636,6 @@ func StartTestRangeBugServer() net.Listener { }) } -// StartTestNoRangeServer starts a server that returns Content-Length but does NOT support Range requests. -// This simulates servers where file size is known but range downloads are not supported. -func StartTestNoRangeServer() net.Listener { - return startTestServer(func(sl *shutdownListener) http.Handler { - mux := http.NewServeMux() - mux.HandleFunc("/"+BuildName, func(writer http.ResponseWriter, request *http.Request) { - file, err := os.Open(BuildFile) - if err != nil { - panic(err) - } - defer file.Close() - writer.Header().Set("Content-Length", fmt.Sprintf("%d", BuildSize)) - writer.WriteHeader(200) - io.Copy(writer, file) - }) - return mux - }) -} - func rangeFileHandle(writer http.ResponseWriter, request *http.Request, modifyEnd func(end int64) int64, iocpN func(file *os.File, n int64)) { r := request.Header.Get("Range")