transporttest

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 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
	Metrics      func(context.Context, *model.MetricsPayload) 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) SendMetrics added in v0.5.0

func (t CallbackTransport) SendMetrics(ctx context.Context, p *model.MetricsPayload) error

SendMetrics returns t.Metrics(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
	Metrics      chan<- SendMetricsRequest
}

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) SendMetrics added in v0.5.0

func (c *ChannelTransport) SendMetrics(ctx context.Context, payload *model.MetricsPayload) error

SendMetrics sends a SendMetricsRequest value over the c.Metrics 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) SendMetrics added in v0.5.0

SendMetrics 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) Metrics added in v0.5.0

func (p Payload) Metrics() []*model.Metrics

Metrics returns the metrics within the payload. If the payload is not a metrics 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) SendMetrics added in v0.5.0

func (r *RecorderTransport) SendMetrics(ctx context.Context, payload *model.MetricsPayload) error

SendMetrics records the metrics 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 SendMetricsRequest added in v0.5.0

type SendMetricsRequest struct {
	Payload *model.MetricsPayload
	Result  chan<- error
}

SendMetricsRequest is the type of values sent over the ChannelTransport.Metrics channel when its SendMetrics 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