testproxy

package module
v0.0.0-...-d642fce Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: MIT Imports: 14 Imported by: 0

README

Testing software deployed to cloud services like Azure can incure significant costs from provisioning and maintaining the services needed for testing.

Here at Microsoft, we've developed a lightweight test proxy that allows us to record app interactions with Azure and play them back on demand, reducing our testing costs significantly. we're now excited to share this tool with the broader Azure development community and invite you to try it out for yourself.

This repository contains a sample project that demonstrates integration of the record and playback test proxy with an app that interacts with the Azure Cosmos DB Table Storage service.

You must have the test proxy installed and running before starting the test.

To install the proxy:

Install .NET 5.0 or higher

Install the test-proxy:

dotnet tool update azure.sdk.tools.testproxy \--global \--add-source https://pkgs.dev.azure.com/azure-sdk/public/\_packaging/azure-sdk-for-net/nuget/v3/index.json \--version \"1.0.0-dev\*\"

After installing the tool, run it in a terminal or cmd window by typing the command 'test-proxy'. The included recording file is provided for illustration purposes only, it can't be used to play back the test since the resources associated with it no longer exist in Azure.

This project is intended to be a demo that goes with the following Azure SDK blog post:

The test proxy is compatible with all four major languages and can be easily installed using the standard dotnet tool installation process as described in the blog post. To use it, you'll need to be able to reroute your app requests to the test proxy via modifications to the request headers.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCurrentDirectory

func GetCurrentDirectory() string

func Load

func Load(root string) error

func StartTestProxy

func StartTestProxy(tpv *TestProxyVariables) error

StartTextProxy() will initiate a record or playback session by POST-ing a request to a running instance of the test proxy. The test proxy will return a recording ID value in the response header, which we pull out and save as 'x-recording-id'.

func StopTestProxy

func StopTestProxy(tpv *TestProxyVariables) error

StopTextProxy() instructs the test proxy to stop recording or stop playback, depending on the mode it is running in. The instruction to stop is made by POST-ing a request to a running instance of the test proxy. We pass in the recording ID and a directive to save the recording (when recording is running).

**Note that if you skip this step your recording WILL NOT be saved.**

Types

type TestProxyTransport

type TestProxyTransport struct {
	// contains filtered or unexported fields
}

Derived from policy.Transporter, TestProxyTransport provides custom implementations of the abstract methods defined in the base class described above in the HTTP Transport section of this article. These custom implementations allow us to intercept and reroute app traffic sent between an app and Azure to the test proxy.

func NewTestProxyTransport

func NewTestProxyTransport(transport policy.Transporter, host string, port int, recordingId string, mode string) *TestProxyTransport

func (*TestProxyTransport) Do

func (tpt *TestProxyTransport) Do(req *http.Request) (resp *http.Response, err error)

type TestProxyVariables

type TestProxyVariables struct {
	Host        string
	Port        int
	Mode        string
	RecordingId string

	CurrentRecordingPath string
	// Maintain an http client for POST-ing to the test proxy to start and stop recording.
	// For your test client, you can either maintain the lack of certificate validation (the test-proxy
	// is making real HTTPS calls, so if your actual api call is having cert issues, those will still surface.
	HttpClient *http.Client
}

TestProxyVariables class encapsulates variables that store values related to the test proxy, such as connection host (localhost), connection port (5001), and mode (record/playback).

func NewTestProxyVariables

func NewTestProxyVariables(t *testing.T) *TestProxyVariables

Jump to

Keyboard shortcuts

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