Documentation
¶
Overview ¶
Package b2wiretest provides a recording HTTP server for B2 wire tests.
Index ¶
- func AssertHeader(t testing.TB, r Request, name, want string)
- func AssertJSON(t testing.TB, r Request, path string, want any)
- func AssertNoJSON(t testing.TB, r Request, path string)
- func AssertQuery(t testing.TB, r Request, name, want string)
- type Request
- type Response
- type Server
- func (s *Server) Calls(call string) []Request
- func (s *Server) Handle(call string, h func(Request) Response)
- func (s *Server) Last(t testing.TB, call string) Request
- func (s *Server) Reply(call string, status int, body string)
- func (s *Server) ReplySequence(call string, rs ...Response)
- func (s *Server) Requests() []Request
- func (s *Server) StrictReplySequence(call string, rs ...Response)
- func (s *Server) URL() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertHeader ¶
AssertHeader checks one request header's value.
func AssertJSON ¶
AssertJSON decodes r.Body and checks a non-empty, dot-separated path in its JSON object. A hand-built Request must set Body. Numbers compare by value with large integers kept exact. Dots always separate path segments; keys containing literal dots cannot be addressed.
func AssertNoJSON ¶
AssertNoJSON checks that a non-empty, dot-separated path is absent from r.Body. An empty Body means the field is absent; a non-empty Body must be a single JSON object. It has the same path limitations as AssertJSON.
Types ¶
type Request ¶
type Request struct {
Seq int
Method string
Path string
// Call is the last segment of Path, including for non-API paths; a trailing slash gives "".
Call string
Query url.Values
Header http.Header
Body []byte
JSON map[string]any
}
Request is a snapshot of one HTTP request received by a Server.
type Response ¶
Response is the status, headers, and body returned for a scripted call. Status 0 means 200. Content-Type defaults to application/json unless Header sets it; X-Content-Type-Options is always nosniff.
func RangeDownload ¶
RangeDownload returns a B2-style download response for a fixture's body. A range covering the whole body is returned as HTTP 200; partial ranges are 206.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server records B2 requests and answers with built-in or scripted responses.
func New ¶
New starts a recording server and closes it when t finishes. Cleanup rejects new requests and waits for active HTTP handlers before returning.
func (*Server) Handle ¶
Handle registers a response computed from each request. It replaces any earlier script. See Response for status and header defaults.
func (*Server) Reply ¶
Reply registers a response repeated for every request to call. Status 0 means 200.
func (*Server) ReplySequence ¶
ReplySequence registers successive responses; the last response repeats. See Response for status and header defaults.
func (*Server) StrictReplySequence ¶
StrictReplySequence registers responses that must be used exactly once each. It reports an error for an extra request or an unused response at test cleanup. Replacing it reports any unused responses from the earlier sequence.