transporttest

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package transporttest provides implementations of transport.Transport for testing purposes.

Index

Constants

This section is empty.

Variables

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

SendErrors discards the payload and returns t.Error.

func (ErrorTransport) SendTransactions

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

func (p Payload) Errors() []*model.Error

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 Payloads

type Payloads []Payload

Payloads is a slice of Payload.

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.

Jump to

Keyboard shortcuts

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