Documentation
¶
Overview ¶
recording implements a proxy server that records and plays back HTTP interactions. The implementation largely reuses [go-vcr], but adds support for:
- Saving and loading of variables in the recording session
- Enabling recording on a HTTP/1.1 proxy server that uses HTTP Connect, unlike go-vcr/recorder which by default supports client-side recording
Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License.
Index ¶
- Constants
- func GetProvisioningState(respBody string) (string, error)
- func GetStatus(respBody string) (string, error)
- func NewPoller(i *cassette.Interaction) (poller, error)
- func NewResilientHttpTransport(transport http.RoundTripper) *resilientHttpTransport
- func NewResilientHttpTransportWithBackoff(transport http.RoundTripper, backoffDuration time.Duration) *resilientHttpTransport
- func TrimSubscriptionsDeployment(i *cassette.Interaction, variables map[string]string) error
- type Options
- type Session
Constants ¶
const EnvNameKey = "env_name"
const SubscriptionIdKey = "subscription_id"
const TimeKey = "time"
Variables ¶
This section is empty.
Functions ¶
func GetProvisioningState ¶
func GetStatus ¶
GetStatus returns the LRO's status from the response body. Typically used for Azure-AsyncOperation flows. If there is no status in the response body the empty string is returned.
func NewPoller ¶
func NewPoller(i *cassette.Interaction) (poller, error)
func NewResilientHttpTransport ¶
func NewResilientHttpTransport(transport http.RoundTripper) *resilientHttpTransport
NewResilientHttpTransport creates a new resilient HTTP transport that wraps the provided transport
func NewResilientHttpTransportWithBackoff ¶
func NewResilientHttpTransportWithBackoff( transport http.RoundTripper, backoffDuration time.Duration) *resilientHttpTransport
NewResilientHttpTransportWithBackoff creates a new resilient HTTP transport with configurable backoff duration
func TrimSubscriptionsDeployment ¶
func TrimSubscriptionsDeployment(i *cassette.Interaction, variables map[string]string) error
Trims subscription-level deployment responses to only contain the ones that match the current environment.
Types ¶
type Options ¶
type Options interface {
Apply(r recordOptions) recordOptions
}
func WithHostMapping ¶
WithHostMapping allows mapping one host to another in a recording. This is useful in cases where you are using httptest.NewServer in a recorded test, since the host for the server differs across runs due to the randomly assigned port. In this case you can call WithHostMapping(strings.TrimPrefix(server.URL, "http://"), "127.0.0.1:80") to ensure that in the recording the host is always set to the same value.
func WithRecordMode ¶
type Session ¶
type Session struct {
// ProxyUrl is the URL of the proxy server that will be recording or replaying interactions.
ProxyUrl string
// CmdProxyPaths are the paths that should be appended to PATH to proxy any cmd invocations.
CmdProxyPaths []string
// If true, playing back from recording.
Playback bool
// Variables stored in the session.
Variables map[string]string
// A http.Client that is configured to communicate through the proxy server.
ProxyClient *http.Client
}
func Start ¶
Start starts the recorder proxy, returning a recording.Session. In live mode, it returns nil. By default, interactions are automatically recorded once if no recording is available on disk. To set the record mode, specify AZURE_RECORD_MODE='live', 'playback', or 'record'. To control the exact behavior in a test, pass WithRecordMode to Start.
Start automatically adds the required t.Cleanup to save recordings when the test succeeds, and handles shutting down the proxy server.
By default, the recorder proxy will log error and info messages. The environment variable RECORDER_PROXY_DEBUG can be set to enable debug logging for the recorder proxy.