Namespace: go.std.net.http.httptest
v1.0Contents
Summary
Provides a low-level interface to the net/http/httptest package.
Package httptest provides utilities for HTTP testing.
Index
- *ResponseRecorder
- *Server
- DefaultRemoteAddr
- NewRecorder
- NewRequest
- NewServer
- NewTLSServer
- NewUnstartedServer
- ResponseRecorder
- Server
- arrayOfResponseRecorder
- arrayOfServer
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
DefaultRemoteAddr
String v1.0DefaultRemoteAddr is the default remote address to return in RemoteAddr if
an explicit DefaultRemoteAddr isn't set on ResponseRecorder.
Variables
-
(None.)
Functions, Macros, and Special Forms
-
NewRecorder
Function v1.0(NewRecorder)
NewRecorder returns an initialized ResponseRecorder.
Go returns: *ResponseRecorder
Joker input arguments: []
Joker returns: ^*ResponseRecorder -
NewRequest
Function v1.0(NewRequest method target body)
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.
Go input arguments: (method string, target string, body io.Reader)
Go returns: *net/http.Request
Joker input arguments: [^String method, ^String target, ^go.std.io/Reader body]
Joker returns: ^go.std.net.http/*Request -
NewServer
Function v1.0(NewServer handler)
NewServer starts and returns a new Server.
The caller should call Close when finished, to shut it down.
Go input arguments: (handler net/http.Handler)
Go returns: *Server
Joker input arguments: [^go.std.net.http/Handler handler]
Joker returns: ^*Server -
NewTLSServer
Function v1.0(NewTLSServer handler)
NewTLSServer starts and returns a new Server using TLS.
The caller should call Close when finished, to shut it down.
Go input arguments: (handler net/http.Handler)
Go returns: *Server
Joker input arguments: [^go.std.net.http/Handler handler]
Joker returns: ^*Server -
NewUnstartedServer
Function v1.0(NewUnstartedServer handler)
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.
Go input arguments: (handler net/http.Handler)
Go returns: *Server
Joker input arguments: [^go.std.net.http/Handler handler]
Joker returns: ^*Server
Types
-
*ResponseRecorder
Concrete Type v1.0ResponseRecorder is an implementation of http.ResponseWriter that
records its mutations for later inspection in tests.
-
Flush
Receiver for *ResponseRecorder v1.0([])
Flush implements http.Flusher. To test whether Flush was
called, see rw.Flushed.
-
Header
Receiver for *ResponseRecorder v1.0([])
Header implements http.ResponseWriter. It returns the response
headers to mutate within a handler. To test the headers that were
written after a handler completes, use the Result method and see
the returned Response value's Header.
-
Result
Receiver for *ResponseRecorder v1.0([])
Result returns the response generated by the handler.
The returned Response will have at least its StatusCode,
Header, Body, and optionally Trailer populated.
More fields may be populated in the future, so callers should
not DeepEqual the result in tests.
The Response.Header is a snapshot of the headers at the time of the
first write call, or at the time of this call, if the handler never
did a write.
The Response.Body is guaranteed to be non-nil and Body.Read call is
guaranteed to not return any error other than io.EOF.
Result must only be called after the handler has finished running.
-
Write
Receiver for *ResponseRecorder v1.0([buf])
Write implements http.ResponseWriter. The data in buf is written to
rw.Body, if not nil.
-
WriteHeader
Receiver for *ResponseRecorder v1.0([code])
WriteHeader implements http.ResponseWriter.
-
WriteString
Receiver for *ResponseRecorder v1.0([str])
WriteString implements io.StringWriter. The data in str is written
to rw.Body, if not nil.
-
*Server
Concrete Type v1.0A Server is an HTTP server listening on a system-chosen port on the
local loopback interface, for use in end-to-end HTTP tests.
-
Certificate
Receiver for *Server v1.0([])
Certificate returns the certificate used by the server, or nil if
the server doesn't use TLS.
-
Client
Receiver for *Server v1.0([])
Client returns an HTTP client configured for making requests to the server.
It is configured to trust the server's TLS test certificate and will
close its idle connections on Server.Close.
-
Close
Receiver for *Server v1.0([])
Close shuts down the server and blocks until all outstanding
requests on this server have completed.
-
CloseClientConnections
Receiver for *Server v1.0([])
CloseClientConnections closes any open HTTP connections to the test Server.
-
Start
Receiver for *Server v1.0([])
Start starts a server from NewUnstartedServer.
-
StartTLS
Receiver for *Server v1.0([])
StartTLS starts TLS on a server from NewUnstartedServer.
-
ResponseRecorder
Concrete Type v1.0ResponseRecorder is an implementation of http.ResponseWriter that
records its mutations for later inspection in tests.
-
Server
Concrete Type v1.0A Server is an HTTP server listening on a system-chosen port on the
local loopback interface, for use in end-to-end HTTP tests.
-
arrayOfResponseRecorder
Concrete Type v1.0ResponseRecorder is an implementation of http.ResponseWriter that
records its mutations for later inspection in tests.
-
arrayOfServer
Concrete Type v1.0A Server is an HTTP server listening on a system-chosen port on the
local loopback interface, for use in end-to-end HTTP tests.