File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,15 +3,21 @@ package async
33import (
44 "fmt"
55 "net/http"
6+ "net/http/httptest"
67 "testing"
78 "time"
89
910 "github.com/stretchr/testify/assert"
1011)
1112
1213func 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
2632func TestGoChan (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments