Documentation
¶
Overview ¶
Package testcloud provides an isolated HTTP fixture, never a live cloud.
Index ¶
- func CancelWhenBlocked(t testing.TB, parent context.Context, cause error) context.Context
- func JSON(w http.ResponseWriter, status int, body string)
- func NewServer(handler http.Handler) *httptest.Server
- func NovaVersionDocument(self, minimum, maximum string) string
- func Response(status int, body string, header http.Header) *http.Response
- func StreamResponse(status int, body io.ReadCloser, header http.Header) *http.Response
- type Body
- type Call
- type Cloud
- type Gate
- type Progress
- type Recorder
- type RoundTripperFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CancelWhenBlocked ¶
CancelWhenBlocked returns a child of parent that is cancelled with cause as soon as an SDK progress send under it blocks because nobody receives. It uses progress.NotifyBlocked, so no timing assumption is involved; if no send blocks within ten seconds the test fails and the context is cancelled with a distinct error.
func NewServer ¶
NewServer starts an httptest server whose idle connections close without lingering. Each fixture server is short-lived, and the default close leaves a TIME_WAIT socket per connection; across the full suite that exhausts local ephemeral ports. Connections serving a request keep the default close, so a handler that truncates its body still produces a clean EOF, not a reset.
func NovaVersionDocument ¶
NovaVersionDocument is a single CURRENT v2.1 version document.
func Response ¶
Response builds a fake response with only StatusCode, Header and Body set. The header is used as given; nil leaves Response.Header nil.
func StreamResponse ¶
StreamResponse is Response with a caller-supplied body, such as a *Body.
Types ¶
type Body ¶
type Body struct {
Data string
ReadErr error
CloseErr error
OnRead func()
OnClose func()
// contains filtered or unexported fields
}
Body is a scripted response body for read, close and truncation faults. Reads yield Data; the read that exhausts Data returns ReadErr (io.EOF when ReadErr is nil) together with the last bytes, and later reads return 0 and the same error. A truncated body is Data plus io.ErrUnexpectedEOF. OnRead runs once, after the first Read has copied its bytes and before it returns. Close runs OnClose on every call and returns CloseErr. Fields must be set before the first Read or Close.
type Call ¶
type Call struct {
Method string // r.Method
Path string // r.URL.Path
EscapedPath string // r.URL.EscapedPath()
RawQuery string // r.URL.RawQuery
Body string // the full request body; "" when r.Body is nil
Header http.Header // r.Header.Clone()
}
Call is one request seen by a Recorder.
type Cloud ¶
type Cloud struct {
Server *httptest.Server
Mux *http.ServeMux
Provider *gophercloud.ProviderClient
}
func (*Cloud) AdvertiseNova ¶
AdvertiseNova serves a Nova v2.1 version document at the discovery path (ending in a slash) with the given advertised bounds. Empty bounds serve a clean 404, as a cloud without version discovery does. It returns a counter of discovery requests.
func (*Cloud) Client ¶
func (c *Cloud) Client(service, path string) *gophercloud.ServiceClient
func (*Cloud) SetTransport ¶
func (c *Cloud) SetTransport(rt http.RoundTripper)
SetTransport replaces the provider's HTTP transport, so requests reach rt instead of the fixture server. Client endpoints still name the server URL.
type Gate ¶
type Gate struct {
// contains filtered or unexported fields
}
Gate holds the Nth request that match accepts until the test has run its action through AwaitThen, then answers it with the request context's error without forwarding it. It forces an interleaving in which the operation has already started its next request when the test acts, for example cancels. Other requests pass through unchanged.
func (*Gate) AwaitThen ¶
AwaitThen waits until the gated request arrives, runs action and releases the request. The ten-second limit only guards against a hang.
func (*Gate) Intercept ¶
Intercept handles r when it is the gated request: it waits for AwaitThen to finish and returns the request context's error with handled true. Requests that are not gated return handled false.
func (*Gate) Wrap ¶
func (g *Gate) Wrap(next http.RoundTripper) http.RoundTripper
Wrap forwards every request except the gated one to next.
type Progress ¶
type Progress[T any] struct { C chan T // contains filtered or unexported fields }
Progress drains an SDK progress channel on its own goroutine and calls fn for each received value, in order. Pass C to the progress option and call Done after the operation returns, before asserting on what fn recorded. The SDK sends nothing after an operation returns, so Done may close C.
func NewProgress ¶
NewProgress starts the receiver. A nil fn only drains. Cleanup calls Done.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder is an http.RoundTripper that records every request and answers it with Reply. It is safe for concurrent use.
func NewRecorder ¶
NewRecorder returns a Recorder that answers through LinkRequest(reply).
func (*Recorder) Reset ¶
func (rec *Recorder) Reset()
Reset discards the recorded calls, so later Calls and Len see only the requests that arrive afterwards. The reply function is unchanged.
func (*Recorder) RoundTrip ¶
RoundTrip records r and then calls the reply function. The request body is read to its end before the reply runs; r.Body is then replaced with a fresh reader over the same bytes, so the reply can still inspect it. A request body read error is not reported; Call.Body holds the bytes read before it.
type RoundTripperFunc ¶
RoundTripperFunc adapts a function to http.RoundTripper. RoundTrip returns exactly what the function returns; use LinkRequest when the fake response should carry its request as a real transport's does.
func LinkRequest ¶
LinkRequest wraps fn so that a non-nil response whose Request is nil gets the outgoing request, as net/http.Transport sets Response.Request. A response that already names a request keeps it.