testutil

package
v0.0.0-...-81c2c1e Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 MockEvents

func MockEvents() []optic.Event

MockEvents returns a mock `[]optic.Event“ object for using in unit tests.

func MockLogLines

func MockLogLines() []optic.LogLine

MockLogLines returns a mock `[]optic.LogLine“ object for using in unit tests.

func MockMetrics

func MockMetrics() []optic.Metric

MockMetrics returns a mock `[]optic.Metric“ object for using in unit tests.

func MockRaw

func MockRaw() []optic.Raw

MockRaw returns a mock `[]optic.Raw“ object for using in unit tests.

func TestLogLine

func TestLogLine(content string) optic.LogLine

TestLogLine Returns a simple test logline event:

path -> "test1"
content -> content
tags -> "tag1":"value1"
fields -> nil

func TestMetric

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

TestMetric Returns a simple test metric event:

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

func TestRaw

func TestRaw(value []byte) optic.Raw

TestRaw Returns a simple test raw event:

source -> "test1"
value -> value
tags -> "tag1":"value1"
fields -> nil

Types

type Accumulator

type Accumulator struct {
	sync.Mutex
	*sync.Cond

	Events []*Event

	Discard bool
	Errors  []error
	// contains filtered or unexported fields
}

Accumulator defines a mocked out accumulator

func (*Accumulator) AddError

func (a *Accumulator) AddError(err error)

AddError appends the given error to Accumulator.Errors.

func (*Accumulator) AddEvent

func (a *Accumulator) AddEvent(event optic.Event)

func (*Accumulator) AddEvents

func (a *Accumulator) AddEvents(events []optic.Event)

func (*Accumulator) AddLogLine

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

func (*Accumulator) AddLogLines

func (a *Accumulator) AddLogLines(loglines []optic.LogLine)

func (*Accumulator) AddMetric

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

func (*Accumulator) AddMetricType

func (a *Accumulator) AddMetricType(
	name string,
	tags map[string]string,
	fields map[string]interface{},
	metricType optic.MetricType,
	timestamp ...time.Time,
)

func (*Accumulator) AddMetrics

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

func (*Accumulator) AddRaw

func (a *Accumulator) AddRaw(
	source string,
	value []byte,
	tags map[string]string,
	fields map[string]interface{},
	timestamp ...time.Time,
)

func (*Accumulator) AddRaws

func (a *Accumulator) AddRaws(raws []optic.Raw)

func (*Accumulator) AssertContainsMetricWithTaggedFields

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

func (*Accumulator) ClearEvents

func (a *Accumulator) ClearEvents()

func (*Accumulator) Count

func (a *Accumulator) Count() uint64

func (*Accumulator) Debug

func (a *Accumulator) Debug() bool

func (*Accumulator) FieldsCount

func (a *Accumulator) FieldsCount() int

FieldsCount returns the total number of fields in the accumulator, across all events.

func (*Accumulator) GatherError

func (a *Accumulator) GatherError(gf func(optic.Accumulator) error) error

GatherError calls the given Gather function and returns the first error found.

func (*Accumulator) GetMetric

func (a *Accumulator) GetMetric(name string) (*Event, bool)

GetMetric gets the specified metric point from the accumulator.

func (*Accumulator) HasMetric

func (a *Accumulator) HasMetric(name string) bool

HasMetric returns true if the accumulator has a metric with the given name.

func (*Accumulator) SetDebug

func (a *Accumulator) SetDebug(debug bool)

func (*Accumulator) Wait

func (a *Accumulator) Wait(n int)

Wait waits for the given number of events 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.

type Event

type Event struct {
	Type optic.EventType

	// raw
	Source string
	Value  []byte
	// metric
	Name       string
	MetricType optic.MetricType
	// logline
	Path    string
	Content string

	Tags   map[string]string
	Fields map[string]interface{}
	Time   time.Time
}

Event defines a single point measurement

func (*Event) EventType

func (e *Event) EventType() optic.EventType

func (*Event) String

func (e *Event) String() string

Jump to

Keyboard shortcuts

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