add localAddr test

This commit is contained in:
bxd
2023-11-20 22:00:08 +08:00
parent 314d5a2262
commit abadadeb81
2 changed files with 23 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ Requests is a fully featured HTTP client library for Golang. Network requests ca
* [Form request](https://github.com/gospider007/requests/blob/master/test/request/form_test.go) with `multipart/form-data`
* [Flow request](https://github.com/gospider007/requests/blob/master/test/request/stream_test.go)
* [Request URL Path Params](https://github.com/gospider007/requests/blob/master/test/request/params_test.go)
* [Local network card](https://github.com/gospider007/requests/blob/master/test/request/params_test.go)
* [Response](https://github.com/gospider007/requests/tree/master/test/response)
* [Return whether to reuse connections](https://github.com/gospider007/requests/blob/master/test/response/isNewConn_test.go)
* [Middleware](https://github.com/gospider007/requests/tree/master/test/middleware)

22
test/localAddr_test.go Normal file
View File

@@ -0,0 +1,22 @@
package main
import (
"net"
"testing"
"github.com/gospider007/requests"
)
func TestLocalAddr(t *testing.T) {
resp, err := requests.Get(nil, "https://httpbin.org/anything", requests.RequestOption{
LocalAddr: &net.TCPAddr{ //set dns server
IP: net.ParseIP("192.168.1.239"),
},
})
if err != nil {
t.Fatal(err)
}
if resp.StatusCode() != 200 {
t.Fatal("http status code is not 200")
}
}