apmtest

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DiscardTracer *apm.Tracer

DiscardTracer is an apm.Tracer that discards all events.

This tracer may be used by multiple tests, and so should not be modified or closed.

Importing apmttest will close apm.DefaultTracer, and update it to this value.

Functions

func NewDiscardTracer

func NewDiscardTracer() *apm.Tracer

NewDiscardTracer returns a new apm.Tracer that discards all events.

func WithTransaction

func WithTransaction(f func(ctx context.Context)) (model.Transaction, []model.Span, []model.Error)

WithTransaction is equivalent to calling WithTransactionOptions with a zero TransactionOptions.

func WithTransactionOptions

func WithTransactionOptions(opts apm.TransactionOptions, f func(ctx context.Context)) (model.Transaction, []model.Span, []model.Error)

WithTransactionOptions calls f with a new context containing a transaction and transaction options, flushes the transaction to a test server, and returns the decoded transaction and any associated spans and errors.

Types

type HTTPTestSuite

type HTTPTestSuite struct {
	suite.Suite

	// Handler holds an instrumented HTTP handler. Handler must
	// support the following routes:
	//
	//   GET /implicit_write (no explicit write on the response)
	//   GET /panic_before_write (panic without writing response)
	//   GET /panic_after_write (panic after writing response)
	//
	Handler http.Handler

	// Tracer is the apm.Tracer used to instrument Handler.
	//
	// HTTPTestSuite will close the tracer when all tests have
	// been completed.
	Tracer *apm.Tracer

	// Recorder is the transport used as the transport for Tracer.
	Recorder *transporttest.RecorderTransport
	// contains filtered or unexported fields
}

HTTPTestSuite is a test suite for HTTP instrumentation modules.

func (*HTTPTestSuite) SetupSuite

func (s *HTTPTestSuite) SetupSuite()

SetupSuite runs before the tests in the suite are run.

func (*HTTPTestSuite) SetupTest

func (s *HTTPTestSuite) SetupTest()

SetupTest runs before each test.

func (*HTTPTestSuite) TearDownSuite

func (s *HTTPTestSuite) TearDownSuite()

TearDownSuite runs after the tests in the suite are run.

func (*HTTPTestSuite) TestImplicitWrite

func (s *HTTPTestSuite) TestImplicitWrite()

TestImplicitWrite tests the behaviour of instrumented handlers for routes which do not explicitly write a response, but instead leave it to the framework to write an empty 200 response.

func (*HTTPTestSuite) TestPanicAfterWrite

func (s *HTTPTestSuite) TestPanicAfterWrite()

TestPanicAfterWrite tests the behaviour of instrumented handlers for routes which panic after writing headers. The handler is expected to recover the panic without otherwise affecting the response.

func (*HTTPTestSuite) TestPanicBeforeWrite

func (s *HTTPTestSuite) TestPanicBeforeWrite()

TestPanicBeforeWrite tests the behaviour of instrumented handlers for routes which panic before any headers are written. The handler is expected to recover the panic and write an empty 500 response.

type LogRecord

type LogRecord struct {
	// Level is the log level: "debug", "error", or "warning".
	Level string

	// Format is the log message format, like "Thingy did foo %d times".
	Format string

	// Message is the formatted message.
	Message string
}

LogRecord holds the details of a log record.

type LogfLogger

type LogfLogger interface {
	Logf(string, ...interface{})
}

LogfLogger is an interface with the a Logf method, implemented by *testing.T and *testing.B.

type RecordLogger

type RecordLogger struct {
	Records []LogRecord
}

RecordLogger is an implementation of apm.Logger, recording log entries.

func (*RecordLogger) Debugf

func (l *RecordLogger) Debugf(format string, args ...interface{})

Debugf logs debug messages.

func (*RecordLogger) Errorf

func (l *RecordLogger) Errorf(format string, args ...interface{})

Errorf logs error messages.

func (*RecordLogger) Warningf

func (l *RecordLogger) Warningf(format string, args ...interface{})

Warningf logs error messages.

type RecordingTracer

type RecordingTracer struct {
	*apm.Tracer
	transporttest.RecorderTransport
}

RecordingTracer holds an apm.Tracer and transporttest.RecorderTransport.

func NewRecordingTracer

func NewRecordingTracer() *RecordingTracer

NewRecordingTracer returns a new RecordingTracer, containing a new Tracer using the RecorderTransport stored inside.

func (*RecordingTracer) WithTransaction

func (rt *RecordingTracer) WithTransaction(f func(ctx context.Context)) (model.Transaction, []model.Span, []model.Error)

WithTransaction calls rt.WithTransactionOptions with a zero apm.TransactionOptions.

func (*RecordingTracer) WithTransactionOptions

func (rt *RecordingTracer) WithTransactionOptions(opts apm.TransactionOptions, f func(ctx context.Context)) (model.Transaction, []model.Span, []model.Error)

WithTransactionOptions starts a transaction with the given options, calls f with the transaction in the provided context, ends the transaction and flushes the tracer, and then returns the resulting events.

type TestLogger

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

TestLogger is an implementation of apm.Logger, logging to a testing.T.

func NewTestLogger

func NewTestLogger(l LogfLogger) TestLogger

NewTestLogger returns a new TestLogger that logs messages to l.

func (TestLogger) Debugf

func (t TestLogger) Debugf(format string, args ...interface{})

Debugf logs debug messages.

func (TestLogger) Errorf

func (t TestLogger) Errorf(format string, args ...interface{})

Errorf logs error messages.

type WatchConfigFunc

type WatchConfigFunc func(context.Context, apmconfig.WatchParams) <-chan apmconfig.Change

WatchConfigFunc is a function type that implements apmconfig.Watcher.

func (WatchConfigFunc) WatchConfig

func (f WatchConfigFunc) WatchConfig(ctx context.Context, params apmconfig.WatchParams) <-chan apmconfig.Change

WatchConfig returns f(ctx, params).

Jump to

Keyboard shortcuts

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