Skip to content

Commit 02eed70

Browse files
kookseecursoragent
andcommitted
test(async): use httptest server instead of httpbin
Avoid flaky CI failures when the external httpbin endpoint is unavailable. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 0c082bd commit 02eed70

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

async/go_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@ package async
33
import (
44
"fmt"
55
"net/http"
6+
"net/http/httptest"
67
"testing"
78
"time"
89

910
"github.com/stretchr/testify/assert"
1011
)
1112

1213
func TestAsync(t *testing.T) {
13-
ret := Async(func() (*http.Response, error) { //nolint
14-
return http.Get("https://httpbin.org")
14+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
15+
w.WriteHeader(http.StatusOK)
16+
}))
17+
t.Cleanup(server.Close)
18+
19+
ret := Async(func() (*http.Response, error) {
20+
return http.Get(server.URL)
1521
}).Await()
1622
assert.NoError(t, ret.GetErr())
1723
rsp := ret.Unwrap()
@@ -20,7 +26,7 @@ func TestAsync(t *testing.T) {
2026
_ = b.Close()
2127
}()
2228
}
23-
assert.Equal(t, rsp.StatusCode, 200)
29+
assert.Equal(t, http.StatusOK, rsp.StatusCode)
2430
}
2531

2632
func TestGoChan(t *testing.T) {

0 commit comments

Comments
 (0)