Fix fileutil CI panic by serving ReadFile test fixtures from a local httptest server (#358)

* Initial plan

* Apply remaining changes

Co-authored-by: duke-git <5037603+duke-git@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: duke-git <5037603+duke-git@users.noreply.github.com>
This commit is contained in:
Copilotandduke-git authored and GitHub committed 2026-10-13 11:07:23 +08:00
1 parent 835111c832
commit 227501958f
4 files changed
+79 -64

No files matched your search

+10 -2
View File
@@ -1,7 +1,10 @@
package fileutil
import (
"fmt"
"io"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"runtime"
@@ -516,9 +519,14 @@ func TestWriteBytesToFile(t *testing.T) {
}
func TestReadFile(t *testing.T) {
reader, close, err := ReadFile("https://httpbin.org/robots.txt")
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "User-agent: *\nDisallow: /deny\n")
}))
defer ts.Close()
reader, close, err := ReadFile(ts.URL)
if err != nil {
t.Fail()
t.Fatal(err)
}
defer close()