Documentation ¶
Overview ¶
Package transporttest provides implementations of transport.Transport for testing purposes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Discard transport.Transport = ErrorTransport{}
Discard is a transport.Transport which discards all payloads, and returns no errors.
Functions ¶
This section is empty.
Types ¶
type CallbackTransport ¶
type CallbackTransport struct { Transactions func(context.Context, *model.TransactionsPayload) error Errors func(context.Context, *model.ErrorsPayload) error }
CallbackTransport is a transport that invokes the given callbacks for the payloads for each method call.
func (CallbackTransport) SendErrors ¶
func (t CallbackTransport) SendErrors(ctx context.Context, p *model.ErrorsPayload) error
SendErrors returns t.Errors(ctx, p).
func (CallbackTransport) SendTransactions ¶
func (t CallbackTransport) SendTransactions(ctx context.Context, p *model.TransactionsPayload) error
SendTransactions returns t.Transactions(ctx, p).
type ChannelTransport ¶
type ChannelTransport struct { Transactions chan<- SendTransactionsRequest Errors chan<- SendErrorsRequest }
ChannelTransport implements transport.Transport, sending payloads to the provided channels as request objects. Once a request object has been received, an error should be sent to its Result channel to unblock the tracer.
func (*ChannelTransport) SendErrors ¶
func (c *ChannelTransport) SendErrors(ctx context.Context, payload *model.ErrorsPayload) error
SendErrors sends a SendErrorsRequest value over the c.Errors channel with the given payload, and waits for a response on the error channel included in the request, or for the context to be canceled.
func (*ChannelTransport) SendTransactions ¶
func (c *ChannelTransport) SendTransactions(ctx context.Context, payload *model.TransactionsPayload) error
SendTransactions sends a SendTransactionsRequest value over the c.Transactions channel with the given payload, and waits for a response on the error channel included in the request, or for the context to be canceled.
type ErrorTransport ¶
type ErrorTransport struct {
Error error
}
ErrorTransport is a transport that returns the stored error for each method call.
func (ErrorTransport) SendErrors ¶
func (t ErrorTransport) SendErrors(context.Context, *model.ErrorsPayload) error
SendErrors discards the payload and returns t.Error.
func (ErrorTransport) SendTransactions ¶
func (t ErrorTransport) SendTransactions(context.Context, *model.TransactionsPayload) error
SendTransactions discards the payload and returns t.Error.
type Payload ¶
type Payload struct {
Value interface{}
}
Payload wraps an untyped payload value. Use the methods to obtain the appropriate payload type fields.
func (Payload) Errors ¶
Errors returns the errors within the payload. If the payload is not an errors payload, this will panic.
func (Payload) Transactions ¶
func (p Payload) Transactions() []model.Transaction
Transactions returns the transactions within the payload. If the payload is not a transactions payload, this will panic.
type RecorderTransport ¶
type RecorderTransport struct {
// contains filtered or unexported fields
}
RecorderTransport implements transport.Transport, recording the payloads sent. The payloads can be retrieved using the Payloads method.
func NewRecorderTracer ¶
func NewRecorderTracer() (*elasticapm.Tracer, *RecorderTransport)
NewRecorderTracer returns a new elasticapm.Tracer and RecorderTransport, which is set as the tracer's transport.
func (*RecorderTransport) Payloads ¶
func (r *RecorderTransport) Payloads() Payloads
Payloads returns the payloads recorded by SendTransactions and SendErrors. Each element of Payloads is a deep copy of the *model.TransactionsPayload or *model.ErrorsPayload, produced by encoding/decoding the payload to/from JSON.
func (*RecorderTransport) SendErrors ¶
func (r *RecorderTransport) SendErrors(ctx context.Context, payload *model.ErrorsPayload) error
SendErrors records the errors payload such that it can later be obtained via Payloads.
func (*RecorderTransport) SendTransactions ¶
func (r *RecorderTransport) SendTransactions(ctx context.Context, payload *model.TransactionsPayload) error
SendTransactions records the transactions payload such that it can later be obtained via Payloads.
type SendErrorsRequest ¶
type SendErrorsRequest struct { Payload *model.ErrorsPayload Result chan<- error }
SendErrorsRequest is the type of values sent over the ChannelTransport.Errors channel when its SendErrors method is called.
type SendTransactionsRequest ¶
type SendTransactionsRequest struct { Payload *model.TransactionsPayload Result chan<- error }
SendTransactionsRequest is the type of values sent over the ChannelTransport.Transactions channel when its SendTransactions method is called.