recording

package
v0.0.0-...-4d33260 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 30 Imported by: 0

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

View Source
const EnvNameKey = "env_name"
View Source
const SubscriptionIdKey = "subscription_id"
View Source
const TimeKey = "time"

Variables

This section is empty.

Functions

func GetProvisioningState

func GetProvisioningState(respBody string) (string, error)

func GetStatus

func GetStatus(respBody string) (string, error)

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 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

func WithHostMapping(from, to string) Options

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

func WithRecordMode(mode recorder.Mode) Options

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

func Start(t *testing.T, opts ...Options) *Session

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL