go-zero/rest/httpx/util_test.go
2020-08-12 12:25:52 +08:00

19 lines
326 B
Go

package httpx
import (
"net/http"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetRemoteAddr(t *testing.T) {
host := "8.8.8.8"
r, err := http.NewRequest(http.MethodGet, "/", strings.NewReader(""))
assert.Nil(t, err)
r.Header.Set(xForwardFor, host)
assert.Equal(t, host, GetRemoteAddr(r))
}