grpcrr

package
v0.0.0-...-fbfa381 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package grpcrr implements gRPC record and replay, mainly for use in tests. The client using gRPC must accept options of type google.golang.org/api/option.ClientOption.

Open creates a new RecordReplay. Whether it is recording or replaying is controlled by the -grpcrecord flag, which is defined by this package only in test programs (built by “go test”). See the Open documentation for more details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RecordReplay

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

A RecordReplay can operate in two modes: record and replay.

In record mode, the RecordReplay intercepts gRPC calls and logs the requests and responses to a file.

In replay mode, the RecordReplay responds to requests by finding an identical request in the log and sending the logged response.

func Open

func Open(file string) (*RecordReplay, error)

Open opens a new record/replay log in the named file and returns a RecordReplay backed by that file.

By default Open expects the file to exist and contain a previously-recorded log of RPCs, which are consulted for replies.

If the command-line flag -grpcrecord is set to a non-empty regular expression that matches file, then Open creates the file as a new log. In that mode, actual RPCs are made and also logged to the file for replaying in a future run.

After Open succeeds, pass the return value of RecordReplay.ClientOptions to a NewClient function to enable record/replay.

func (*RecordReplay) ClientOptions

func (r *RecordReplay) ClientOptions() []option.ClientOption

ClientOptions returns options to pass to a gRPC client that accepts them.

func (*RecordReplay) Close

func (rr *RecordReplay) Close() error

Close closes the RecordReplay.

func (*RecordReplay) Initial

func (r *RecordReplay) Initial() []byte

Initial returns the data stored with SetInitial. It panics in record mode.

func (*RecordReplay) Recording

func (rr *RecordReplay) Recording() bool

Recording reports whether rr is in recording mode.

func (*RecordReplay) SetInitial

func (r *RecordReplay) SetInitial(initial []byte)

SetInitial provides data to be stored at the beginning of the file in record mode. It panics in replay mode.

Jump to

Keyboard shortcuts

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