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 RecordsPath ¶
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 ¶
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.
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.