http_test.go (626B)
1 package nativehttp 2 3 import ( 4 "io" 5 "net/http" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestGet(t *testing.T) { 12 svr := http.Server{ 13 Addr: "localhost:1337", 14 Handler: http.HandlerFunc(func(wr http.ResponseWriter, r *http.Request) { 15 t.Log("request") 16 if _, err := wr.Write([]byte("hellope!")); err != nil { 17 t.Fatalf("failed copying data to response writer") 18 } 19 }), 20 } 21 22 defer svr.Close() 23 24 go svr.ListenAndServe() 25 26 r, err := Get("http://127.0.0.1:1337") 27 assert.NoError(t, err) 28 assert.NotNil(t, r) 29 30 by, err := io.ReadAll(r) 31 assert.NoError(t, err) 32 assert.Equal(t, string(by), "hellope!") 33 }