testutil

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromTestMetric

func FromTestMetric(met *Metric) cua.Metric

func GetLocalHost

func GetLocalHost() string

GetLocalHost returns the DOCKER_HOST environment variable, parsing out any scheme or ports so that only the IP address is returned.

func IgnoreTime

func IgnoreTime() cmp.Option

IgnoreTime disables comparison of timestamp.

func MetricEqual

func MetricEqual(expected, actual cua.Metric, opts ...cmp.Option) bool

MetricEqual returns true if the metrics are equal.

func MockMetrics

func MockMetrics() []cua.Metric

MockMetrics returns a mock []cua.Metric object for using in unit tests of output sinks.

func MustMetric

func MustMetric(
	name string,
	tags map[string]string,
	fields map[string]interface{},
	tm time.Time,
	tp ...cua.ValueType,
) cua.Metric

Metric creates a new metric or panics on error.

func RequireMetricEqual

func RequireMetricEqual(t *testing.T, expected, actual cua.Metric, opts ...cmp.Option)

RequireMetricEqual halts the test with an error if the metrics are not equal.

func RequireMetricsEqual

func RequireMetricsEqual(t *testing.T, expected, actual []cua.Metric, opts ...cmp.Option)

RequireMetricsEqual halts the test with an error if the array of metrics are not equal.

func SortMetrics

func SortMetrics() cmp.Option

SortMetrics enables sorting metrics before comparison.

func TestMetric

func TestMetric(value interface{}, name ...string) cua.Metric

TestMetric Returns a simple test point:

measurement -> "test1" or name
tags -> "tag1":"value1"
value -> value
time -> time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)

Types

type Accumulator

type Accumulator struct {
	*sync.Cond
	TimeFunc func() time.Time

	Errors  []error
	Metrics []*Metric

	sync.Mutex
	Discard bool
	// contains filtered or unexported fields
}

Accumulator defines a mocked out accumulator

func (*Accumulator) AddCounter

func (a *Accumulator) AddCounter(
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
	timestamp ...time.Time,
)

func (*Accumulator) AddCumulativeHistogram added in v0.0.10

func (a *Accumulator) AddCumulativeHistogram(
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
	timestamp ...time.Time,
)

func (*Accumulator) AddError

func (a *Accumulator) AddError(err error)

AddError appends the given error to Accumulator.Errors.

func (*Accumulator) AddFields

func (a *Accumulator) AddFields(
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
	timestamp ...time.Time,
)

AddFields adds a measurement point with a specified timestamp.

func (*Accumulator) AddGauge

func (a *Accumulator) AddGauge(
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
	timestamp ...time.Time,
)

func (*Accumulator) AddHistogram

func (a *Accumulator) AddHistogram(
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
	timestamp ...time.Time,
)

func (*Accumulator) AddMetric

func (a *Accumulator) AddMetric(m cua.Metric)

func (*Accumulator) AddMetrics

func (a *Accumulator) AddMetrics(metrics []cua.Metric)

func (*Accumulator) AddSummary

func (a *Accumulator) AddSummary(
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
	timestamp ...time.Time,
)

func (*Accumulator) AddTrackingMetric

func (a *Accumulator) AddTrackingMetric(m cua.Metric) cua.TrackingID

func (*Accumulator) AddTrackingMetricGroup

func (a *Accumulator) AddTrackingMetricGroup(group []cua.Metric) cua.TrackingID

func (*Accumulator) AssertContainsFields

func (a *Accumulator) AssertContainsFields(
	t *testing.T,
	measurement string,
	fields map[string]interface{},
)

func (*Accumulator) AssertContainsTaggedFields

func (a *Accumulator) AssertContainsTaggedFields(
	t *testing.T,
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
)

func (*Accumulator) AssertDoesNotContainMeasurement

func (a *Accumulator) AssertDoesNotContainMeasurement(t *testing.T, measurement string)

func (*Accumulator) AssertDoesNotContainsTaggedFields

func (a *Accumulator) AssertDoesNotContainsTaggedFields(
	t *testing.T,
	measurement string,
	fields map[string]interface{},
	tags map[string]string,
)

func (*Accumulator) BoolField

func (a *Accumulator) BoolField(measurement string, field string) (bool, bool)

BoolField returns the bool value of the given measurement and field or false.

func (*Accumulator) ClearMetrics

func (a *Accumulator) ClearMetrics()

func (*Accumulator) Debug

func (a *Accumulator) Debug() bool

func (*Accumulator) Delivered

func (a *Accumulator) Delivered() <-chan cua.DeliveryInfo

func (*Accumulator) DisablePrecision

func (a *Accumulator) DisablePrecision()

func (*Accumulator) FirstError

func (a *Accumulator) FirstError() error

func (*Accumulator) FloatField

func (a *Accumulator) FloatField(measurement string, field string) (float64, bool)

FloatField returns the float64 value of the given measurement and field or false.

func (*Accumulator) GatherError

func (a *Accumulator) GatherError(gf func(context.Context, cua.Accumulator) error) error

Calls the given Gather function and returns the first error found.

func (*Accumulator) Get

func (a *Accumulator) Get(measurement string) (*Metric, bool)

Get gets the specified measurement point from the accumulator

func (*Accumulator) GetCUAMetrics

func (a *Accumulator) GetCUAMetrics() []cua.Metric

func (*Accumulator) HasField

func (a *Accumulator) HasField(measurement string, field string) bool

HasField returns true if the given measurement has a field with the given name

func (*Accumulator) HasFloatField

func (a *Accumulator) HasFloatField(measurement string, field string) bool

HasFloatField returns true if the given measurement has a float value

func (*Accumulator) HasInt32Field

func (a *Accumulator) HasInt32Field(measurement string, field string) bool

HasInt32Field returns true if the measurement has an Int value

func (*Accumulator) HasInt64Field

func (a *Accumulator) HasInt64Field(measurement string, field string) bool

HasInt64Field returns true if the measurement has an Int64 value

func (*Accumulator) HasIntField

func (a *Accumulator) HasIntField(measurement string, field string) bool

HasIntField returns true if the measurement has an Int value

func (*Accumulator) HasMeasurement

func (a *Accumulator) HasMeasurement(measurement string) bool

HasMeasurement returns true if the accumulator has a measurement with the given name

func (*Accumulator) HasPoint

func (a *Accumulator) HasPoint(
	measurement string,
	tags map[string]string,
	fieldKey string,
	fieldValue interface{},
) bool

func (*Accumulator) HasStringField

func (a *Accumulator) HasStringField(measurement string, field string) bool

HasStringField returns true if the measurement has an String value

func (*Accumulator) HasTag

func (a *Accumulator) HasTag(measurement string, key string) bool

func (*Accumulator) HasTimestamp

func (a *Accumulator) HasTimestamp(measurement string, timestamp time.Time) bool

HasTimestamp returns true if the measurement has a matching Time value

func (*Accumulator) HasUIntField

func (a *Accumulator) HasUIntField(measurement string, field string) bool

HasUIntField returns true if the measurement has a UInt value

func (*Accumulator) Int32Field

func (a *Accumulator) Int32Field(measurement string, field string) (int32, bool)

Int32Field returns the int32 value of the given measurement and field or false.

func (*Accumulator) Int64Field

func (a *Accumulator) Int64Field(measurement string, field string) (int64, bool)

Int64Field returns the int64 value of the given measurement and field or false.

func (*Accumulator) IntField

func (a *Accumulator) IntField(measurement string, field string) (int, bool)

IntField returns the int value of the given measurement and field or false.

func (*Accumulator) NFields

func (a *Accumulator) NFields() int

NFields returns the total number of fields in the accumulator, across all measurements

func (*Accumulator) NMetrics

func (a *Accumulator) NMetrics() uint64

func (*Accumulator) SetDebug

func (a *Accumulator) SetDebug(debug bool)

func (*Accumulator) SetPrecision

func (a *Accumulator) SetPrecision(precision time.Duration)

func (*Accumulator) StringField

func (a *Accumulator) StringField(measurement string, field string) (string, bool)

StringField returns the string value of the given measurement and field or false.

func (*Accumulator) TagSetValue

func (a *Accumulator) TagSetValue(measurement string, key string) string

func (*Accumulator) TagValue

func (a *Accumulator) TagValue(measurement string, key string) string

func (*Accumulator) Uint64Field

func (a *Accumulator) Uint64Field(measurement string, field string) (uint64, bool)

Uint64Field returns the int64 value of the given measurement and field or false.

func (*Accumulator) Wait

func (a *Accumulator) Wait(n int)

Wait waits for the given number of metrics to be added to the accumulator.

func (*Accumulator) WaitError

func (a *Accumulator) WaitError(n int)

WaitError waits for the given number of errors to be added to the accumulator.

func (*Accumulator) WithTracking

func (a *Accumulator) WithTracking(maxTracked int) cua.TrackingAccumulator

type Container added in v0.0.47

type Container struct {
	WaitingFor   wait.Strategy
	Ports        map[string]string
	Env          map[string]string
	BindMounts   map[string]string
	Image        string
	Name         string
	Address      string
	ExposedPorts []string
	Logs         TestLogConsumer
	Networks     []string
	Entrypoint   []string
	// contains filtered or unexported fields
}

func (*Container) Exec added in v0.0.47

func (c *Container) Exec(cmds []string) (int, io.Reader, error)

func (*Container) LookupMappedPorts added in v0.0.47

func (c *Container) LookupMappedPorts() error

create a lookup table of exposed ports to mapped ports

func (*Container) PrintLogs added in v0.0.47

func (c *Container) PrintLogs()

func (*Container) Start added in v0.0.47

func (c *Container) Start() error

func (*Container) Terminate added in v0.0.47

func (c *Container) Terminate() error

type Logger

type Logger struct {
	Name string // Name is the plugin name, will be printed in the `[]`.
}

Logger defines a logging structure for plugins.

func (Logger) Debug

func (l Logger) Debug(args ...interface{})

Debug logs a debug message, patterned after log.Print.

func (Logger) Debugf

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

Debugf logs a debug message, patterned after log.Printf.

func (Logger) Error

func (l Logger) Error(args ...interface{})

Error logs an error message, patterned after log.Print.

func (Logger) Errorf

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

Errorf logs an error message, patterned after log.Printf.

func (Logger) Info

func (l Logger) Info(args ...interface{})

Info logs an information message, patterned after log.Print.

func (Logger) Infof

func (l Logger) Infof(format string, args ...interface{})

Infof logs an information message, patterned after log.Printf.

func (Logger) Warn

func (l Logger) Warn(args ...interface{})

Warn logs a warning message, patterned after log.Print.

func (Logger) Warnf

func (l Logger) Warnf(format string, args ...interface{})

Warnf logs a warning message, patterned after log.Printf.

type Metric

type Metric struct {
	Time        time.Time
	Tags        map[string]string
	Fields      map[string]interface{}
	Measurement string
	Type        cua.ValueType
}

Metric defines a single point measurement

func (*Metric) String

func (p *Metric) String() string

type NopAccumulator

type NopAccumulator struct{}

NopAccumulator is used for benchmarking to isolate the plugin from the internal accumulator machinery.

func (*NopAccumulator) AddCounter

func (n *NopAccumulator) AddCounter(measurement string, fields map[string]interface{}, tags map[string]string, t ...time.Time)

func (*NopAccumulator) AddCumulativeHistogram added in v0.0.10

func (n *NopAccumulator) AddCumulativeHistogram(measurement string, fields map[string]interface{}, tags map[string]string, t ...time.Time)

func (*NopAccumulator) AddError

func (n *NopAccumulator) AddError(err error)

func (*NopAccumulator) AddFields

func (n *NopAccumulator) AddFields(measurement string, fields map[string]interface{}, tags map[string]string, t ...time.Time)

func (*NopAccumulator) AddGauge

func (n *NopAccumulator) AddGauge(measurement string, fields map[string]interface{}, tags map[string]string, t ...time.Time)

func (*NopAccumulator) AddHistogram

func (n *NopAccumulator) AddHistogram(measurement string, fields map[string]interface{}, tags map[string]string, t ...time.Time)

func (*NopAccumulator) AddMetric

func (n *NopAccumulator) AddMetric(cua.Metric)

func (*NopAccumulator) AddSummary

func (n *NopAccumulator) AddSummary(measurement string, fields map[string]interface{}, tags map[string]string, t ...time.Time)

func (*NopAccumulator) SetPrecision

func (n *NopAccumulator) SetPrecision(precision time.Duration)

func (*NopAccumulator) WithTracking

func (n *NopAccumulator) WithTracking(maxTracked int) cua.TrackingAccumulator

type PKI added in v0.0.12

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

func NewPKI

func NewPKI(path string) *PKI

func (*PKI) CACertPath added in v0.0.12

func (p *PKI) CACertPath() string

func (*PKI) CipherSuite added in v0.0.12

func (p *PKI) CipherSuite() string

func (*PKI) ClientCertPath added in v0.0.12

func (p *PKI) ClientCertPath() string

func (*PKI) ClientKeyPath added in v0.0.12

func (p *PKI) ClientKeyPath() string

func (*PKI) ReadCACert added in v0.0.12

func (p *PKI) ReadCACert() string

func (*PKI) ReadClientCert added in v0.0.12

func (p *PKI) ReadClientCert() string

func (*PKI) ReadClientKey added in v0.0.12

func (p *PKI) ReadClientKey() string

func (*PKI) ReadServerCert added in v0.0.12

func (p *PKI) ReadServerCert() string

func (*PKI) ReadServerKey added in v0.0.12

func (p *PKI) ReadServerKey() string

func (*PKI) ServerCertPath added in v0.0.12

func (p *PKI) ServerCertPath() string

func (*PKI) ServerKeyPath added in v0.0.12

func (p *PKI) ServerKeyPath() string

func (*PKI) TLSClientConfig added in v0.0.12

func (p *PKI) TLSClientConfig() *tls.ClientConfig

func (*PKI) TLSMaxVersion added in v0.0.12

func (p *PKI) TLSMaxVersion() string

func (*PKI) TLSMinVersion added in v0.0.12

func (p *PKI) TLSMinVersion() string

func (*PKI) TLSServerConfig added in v0.0.12

func (p *PKI) TLSServerConfig() *tls.ServerConfig

type TestLogConsumer added in v0.0.47

type TestLogConsumer struct {
	Msgs []string
}

func (*TestLogConsumer) Accept added in v0.0.47

func (g *TestLogConsumer) Accept(l testcontainers.Log)

Jump to

Keyboard shortcuts

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