recorder

package
v1.72.1 Latest Latest
Warning

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

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

Documentation

Overview

Package recorder records & replay yarpc requests on the client side.

For recording, the client must be connected and able to issue requests to a remote service. Every request and its response is recorded into a YAML file, under the directory "testdata/recordings" relative to the test directory.

During replay, the client doesn't need to be connected, for any recorded request Recorder will return the recorded response. Any new request (ie: not pre-recorded) will abort the test.

NewRecorder() returns a Recorder, in the mode specified by the flag `--recorder=replay|append|overwrite`. `replay` is the default.

The new Recorder instance is a yarpc outbound middleware. It takes a `testing.T` or compatible as argument.

Example:

func MyTest(t *testing.T) {
  dispatcher := yarpc.NewDispatcher(yarpc.Config{
  	Name: "...",
  	Outbounds: transport.Outbounds{
  		...
  	},
    OutboundMiddleware: yarpc.OutboundMiddleware {
  	  Unary: recorder.NewRecorder(t),
    },
  })
}

Running the tests in append mode:

$ go test -v ./... --recorder=append

The recorded messages will be stored in `./testdata/recordings/*.yaml`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mode

type Mode int

Mode is the recording mode of the recorder.

const (

	// Replay replays stored request/response pairs, any non pre-recorded
	// requests will be rejected.
	Replay Mode

	// Overwrite will store all request/response pairs, overwriting existing
	// records.
	Overwrite

	// Append will store all new request/response pairs and replay from
	// existing record.
	Append
)

type Option

type Option func(*config)

Option is the type used for the functional options pattern.

func RecordMode

func RecordMode(mode Mode) Option

RecordMode sets the mode.

func RecordsPath

func RecordsPath(path string) Option

RecordsPath sets the records directory path.

type Recorder

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

Recorder records & replay yarpc requests on the client side.

For recording, the client must be connected and able to issue requests to a remote service. Every request and its response is recorded into a YAML file, under the directory "testdata/recordings".

During replay, the client doesn't need to be connected, for any recorded request Recorder will return the recorded response. Any new request will abort the test by calling logger.Fatal().

func NewRecorder

func NewRecorder(logger TestingT, opts ...Option) *Recorder

NewRecorder returns a Recorder in whatever mode specified via the `--recorder` flag.

The new Recorder instance is a yarpc unary outbound middleware. It takes a logger as argument compatible with `testing.T`.

See package documentation for more details.

func (*Recorder) Call

Call implements the yarpc transport outbound middleware interface

func (*Recorder) SetMode

func (r *Recorder) SetMode(newMode Mode)

SetMode let you choose enable the different replay and recording modes, overriding the --recorder flag.

type TestingT

type TestingT interface {
	// Logf must behaves similarly to testing.T.Logf.
	Logf(format string, args ...interface{})

	// Fatal should behaves similarly to testing.T.Fatal. Namely, it must abort
	// the current test.
	Fatal(args ...interface{})
}

TestingT is an interface used by the recorder for logging and reporting fatal errors. It is intentionally made to match with testing.T.

Jump to

Keyboard shortcuts

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