Documentation
¶
Index ¶
- Variables
- func DefaultLogger() *log.Logger
- func ModeRecordReplay() bool
- func SaveScenario() error
- func SetDebugLogger(logger *log.Logger)
- func SetScenario(name string) error
- func ShouldRetryImmediately() bool
- type HTTPRecordingClient
- type Interaction
- type Interactions
- type Matcher
- type Mode
- type Recorder
- func (r *Recorder) CancelRequest(req *http.Request, realTransport http.RoundTripper)
- func (r *Recorder) HookTransport(client *http.Client) error
- func (r *Recorder) RoundTrip(req *http.Request, realTransport http.RoundTripper) (*http.Response, error)
- func (r *Recorder) SetMatcher(matcher Matcher)
- func (r *Recorder) SetTransformer(t Transformer)
- func (r *Recorder) Stop() error
- type Request
- type Response
- type Scenario
- func (s *Scenario) AddInteraction(i *Interaction)
- func (s *Scenario) GetInteraction(r Request) (*Interaction, error)
- func (s *Scenario) GetInteractionWithBody(r Request) (*Interaction, error)
- func (s *Scenario) GetInteractionWithBodyFromList(r Request, list []*Interaction) (*Interaction, error)
- func (s *Scenario) GetInteractionWithFullPath(r Request) (*Interaction, error)
- func (s *Scenario) GetInteractionWithQueryString(r Request) (*Interaction, error)
- func (s *Scenario) GetInteractionWithQueryStringFromList(r Request, list []*Interaction) (*Interaction, error)
- func (s *Scenario) Reset()
- func (s *Scenario) Save() error
- type Transformer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInteractionNotFound indicates that a requested // interaction was not found in the scenario file ErrInteractionNotFound = errors.New("Requested interaction not found") )
Functions ¶
func DefaultLogger ¶
func ModeRecordReplay ¶
func ModeRecordReplay() bool
ModeRecordReplay returns true in record and replay
func SaveScenario ¶
func SaveScenario() error
SaveScenario saves the recorded service calls for the current scenario
func SetDebugLogger ¶
func SetScenario ¶
SetScenario lets the recorder know which test is currently executing
func ShouldRetryImmediately ¶
func ShouldRetryImmediately() bool
ShouldRetryImmediately returns true if replaying
Types ¶
type HTTPRecordingClient ¶
HTTPRecordingClient wraps the execution of a http request, adding record/replay functionality. It is meant to be compatible with oci-go-sdk's client.HTTPRequestDispatcher interface.
func InstallRecorder ¶
func InstallRecorder(client *http.Client) (HTTPRecordingClient, error)
InstallRecorder does no-op.
func InstallRecorderForRecodReplay ¶
func InstallRecorderForRecodReplay(client *http.Client, recorder *Recorder) (HTTPRecordingClient, error)
type Interaction ¶
type Interaction struct {
Index int `yaml:"index"`
Uses int `yaml:"uses"`
Request `yaml:"request"`
Response `yaml:"response"`
}
Interaction type contains a pair of request/response for a single HTTP interaction between a client and a server
type Interactions ¶
type Interactions []Interaction
type Matcher ¶
Matcher function returns true when the actual request matches a single HTTP interaction's request according to the function's own criteria.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder represents a type used to record and replay client and server interactions
func NewRecorder ¶
NewRecorder creates a new recorder
func NewRecorderAsMode ¶
NewRecorderAsMode creates a new recorder in the specified mode
func (*Recorder) CancelRequest ¶
func (r *Recorder) CancelRequest(req *http.Request, realTransport http.RoundTripper)
CancelRequest implements the github.com/coreos/etcd/client.CancelableTransport interface
func (*Recorder) HookTransport ¶
HookTransport makes a new transport and chains the one passed in with it, returning the new one
func (*Recorder) RoundTrip ¶
func (r *Recorder) RoundTrip(req *http.Request, realTransport http.RoundTripper) (*http.Response, error)
RoundTrip implements the http.RoundTripper interface
func (*Recorder) SetMatcher ¶
SetMatcher sets a function to match requests against recorded HTTP interactions.
func (*Recorder) SetTransformer ¶
func (r *Recorder) SetTransformer(t Transformer)
SetTransformer can be used to override the default (no-op) transformer
type Request ¶
type Request struct {
// Body of request
Body string `yaml:"body"`
// BodyParsed is parsed from body json
BodyParsed interface{} `yaml:"bodyParsed"`
// Form values
Form url.Values `yaml:"form"`
// Request headers
Headers http.Header `yaml:"headers"`
// Request URL
URL string `yaml:"url"`
// Request method
Method string `yaml:"method"`
}
Request represents a client request as recorded in the scenario file
type Response ¶
type Response struct {
// Body of responsen
Body string `yaml:"body"`
// BodyParsed is parsed from body json
BodyParsed interface{} `yaml:"bodyParsed"`
// Response headers
Headers http.Header `yaml:"headers"`
// Response status message
Status string `yaml:"status"`
// Response status code
Code int `yaml:"code"`
// Response duration (something like "100ms" or "10s")
Duration string `yaml:"duration"`
}
Response represents a server response as recorded in the scenario file
type Scenario ¶
type Scenario struct {
// Name of the scenario
Name string `yaml:"-"`
// File name of the scenario as written on disk
File string `yaml:"-"`
// Scenario format version
Version int `yaml:"version"`
// Mutex to lock accessing Interactions. omitempty is set
// to prevent the mutex appearing in the recorded YAML.
Mu sync.RWMutex `yaml:"mu,omitempty"`
// Interactions between client and server
Interactions `yaml:"interactions"`
// Matches actual request with interaction requests.
Matcher `yaml:"-"`
// contains filtered or unexported fields
}
Scenario type
func (*Scenario) AddInteraction ¶
func (s *Scenario) AddInteraction(i *Interaction)
AddInteraction appends a new interaction to the scenario
func (*Scenario) GetInteraction ¶
func (s *Scenario) GetInteraction(r Request) (*Interaction, error)
GetInteraction retrieves a recorded request/response interaction
func (*Scenario) GetInteractionWithBody ¶
func (s *Scenario) GetInteractionWithBody(r Request) (*Interaction, error)
Get Interaction with body by compare the body of request and Interaction
func (*Scenario) GetInteractionWithBodyFromList ¶
func (s *Scenario) GetInteractionWithBodyFromList(r Request, list []*Interaction) (*Interaction, error)
func (*Scenario) GetInteractionWithFullPath ¶
func (s *Scenario) GetInteractionWithFullPath(r Request) (*Interaction, error)
func (*Scenario) GetInteractionWithQueryString ¶
func (s *Scenario) GetInteractionWithQueryString(r Request) (*Interaction, error)
Get match Interaction by compare the query string in request
func (*Scenario) GetInteractionWithQueryStringFromList ¶
func (s *Scenario) GetInteractionWithQueryStringFromList(r Request, list []*Interaction) (*Interaction, error)
type Transformer ¶
type Transformer func(*Request, Interaction, *Response)
Transformer converts a request and a saved interaction into a result. The Interaction is passed by value to suggest that it should not be modified.