go1.20.5
GoThrough

httptest.DefaultRemoteAddr

// DefaultRemoteAddr is the default remote address to return in RemoteAddr if // an explicit DefaultRemoteAddr isn't set on ResponseRecorder. const DefaultRemoteAddr = "1.2.3.4"

httptest.NewRecorder

// NewRecorder returns an initialized ResponseRecorder. func NewRecorder() *ResponseRecorder

httptest.NewRequest

// NewRequest returns a new incoming server Request, suitable // for passing to an http.Handler for testing. // // The target is the RFC 7230 "request-target": it may be either a // path or an absolute URL. If target is an absolute URL, the host name // from the URL is used. Otherwise, "example.com" is used. // // The TLS field is set to a non-nil dummy value if target has scheme // "https". // // The Request.Proto is always HTTP/1.1. // // An empty method means "GET". // // The provided body may be nil. If the body is of type *bytes.Reader, // *strings.Reader, or *bytes.Buffer, the Request.ContentLength is // set. // // NewRequest panics on error for ease of use in testing, where a // panic is acceptable. // // To generate a client HTTP request instead of a server request, see // the NewRequest function in the net/http package. func NewRequest(method string, target string, body io.Reader) *http.Request

httptest.NewServer

// NewServer starts and returns a new Server. // The caller should call Close when finished, to shut it down. func NewServer(handler http.Handler) *Server

httptest.NewTLSServer

// NewTLSServer starts and returns a new Server using TLS. // The caller should call Close when finished, to shut it down. func NewTLSServer(handler http.Handler) *Server

httptest.NewUnstartedServer

// NewUnstartedServer returns a new Server but doesn't start it. // // After changing its configuration, the caller should call Start or // StartTLS. // // The caller should call Close when finished, to shut it down. func NewUnstartedServer(handler http.Handler) *Server