Documentation ¶
Overview ¶
Package testutils provides utilities for verifying the functionality of and content produced by collector components.
Index ¶
- func AssertAllLogsReceived(t testing.TB, resourceLogsFilename, collectorConfigFilename string, ...)
- func AssertAllMetricsReceived(t testing.TB, resourceMetricsFilename, collectorConfigFilename string, ...)
- func CheckGoldenFile(t *testing.T, configFile string, expectedFilePath string, ...)
- func CheckGoldenFileWithCollectorOptions(t *testing.T, configFile string, expectedFilePath string, ...)
- func CheckGoldenFileWithMount(t *testing.T, configFile string, expectedFilePath string, files [][]string, ...)
- func CollectorImageIsForArm(t testing.TB) bool
- func CollectorImageIsSet() bool
- func GetAvailablePort(t testing.TB) uint16
- func GetCollectorImage() string
- func GetCollectorImageOrSkipTest(t testing.TB) string
- func GetDockerGID(t testing.TB) uint32
- func HasTestOption(opt TestOption, opts []TestOption) bool
- func SkipIfNotContainerTest(t testing.TB)
- type Collector
- type CollectorBuilder
- type CollectorContainer
- func (collector CollectorContainer) Build() (Collector, error)
- func (collector *CollectorContainer) EffectiveConfig(t testing.TB, port uint16) map[string]any
- func (collector *CollectorContainer) InitialConfig(t testing.TB, port uint16) map[string]any
- func (collector *CollectorContainer) Shutdown() error
- func (collector *CollectorContainer) Start() error
- func (collector CollectorContainer) WillFail(fail bool) Collector
- func (collector CollectorContainer) WithArgs(args ...string) Collector
- func (collector CollectorContainer) WithConfigPath(path string) Collector
- func (collector CollectorContainer) WithEnv(env map[string]string) Collector
- func (collector CollectorContainer) WithExposedPorts(ports ...string) CollectorContainer
- func (collector CollectorContainer) WithImage(image string) CollectorContainer
- func (collector CollectorContainer) WithLogLevel(level string) Collector
- func (collector CollectorContainer) WithLogger(logger *zap.Logger) Collector
- func (collector CollectorContainer) WithMount(path string, mountPoint string) Collector
- type CollectorProcess
- func (collector CollectorProcess) Build() (Collector, error)
- func (collector *CollectorProcess) EffectiveConfig(t testing.TB, port uint16) map[string]any
- func (collector *CollectorProcess) InitialConfig(t testing.TB, port uint16) map[string]any
- func (collector *CollectorProcess) Shutdown() error
- func (collector *CollectorProcess) Start() error
- func (collector CollectorProcess) WillFail(fail bool) Collector
- func (collector CollectorProcess) WithArgs(args ...string) Collector
- func (collector CollectorProcess) WithConfigPath(path string) Collector
- func (collector CollectorProcess) WithEnv(env map[string]string) Collector
- func (collector CollectorProcess) WithLogLevel(level string) Collector
- func (collector CollectorProcess) WithLogger(logger *zap.Logger) Collector
- func (collector CollectorProcess) WithMount(string, string) Collector
- func (collector CollectorProcess) WithPath(path string) CollectorProcess
- type Container
- func (container *Container) AssertExec(t testing.TB, timeout time.Duration, cmd ...string) (rc int, stdout, stderr string)
- func (container Container) Build() *Container
- func (container *Container) ContainerIP(ctx context.Context) (string, error)
- func (container *Container) ContainerIPs(ctx context.Context) ([]string, error)
- func (container *Container) CopyDirToContainer(ctx context.Context, hostDirPath string, containerParentPath string, ...) error
- func (container *Container) CopyFileFromContainer(ctx context.Context, filePath string) (io.ReadCloser, error)
- func (container *Container) CopyFileToContainer(ctx context.Context, hostFilePath string, containerFilePath string, ...) error
- func (container *Container) CopyToContainer(ctx context.Context, fileContent []byte, containerFilePath string, ...) error
- func (container *Container) Endpoint(ctx context.Context, s string) (string, error)
- func (container *Container) Exec(ctx context.Context, cmd []string, options ...exec.ProcessOption) (int, io.Reader, error)
- func (container *Container) FollowOutput(consumer testcontainers.LogConsumer)
- func (container *Container) GetContainerID() string
- func (container *Container) Host(ctx context.Context) (string, error)
- func (container *Container) IsRunning() bool
- func (container *Container) Logs(ctx context.Context) (io.ReadCloser, error)
- func (container *Container) MappedPort(ctx context.Context, port nat.Port) (nat.Port, error)
- func (container *Container) Name(ctx context.Context) (string, error)
- func (container *Container) NetworkAliases(ctx context.Context) (map[string][]string, error)
- func (container *Container) Networks(ctx context.Context) ([]string, error)
- func (container *Container) PortEndpoint(ctx context.Context, port nat.Port, s string) (string, error)
- func (container *Container) Ports(ctx context.Context) (nat.PortMap, error)
- func (container *Container) SessionID() string
- func (container *Container) Start(ctx context.Context) error
- func (container *Container) StartLogProducer(ctx context.Context) error
- func (container *Container) State(ctx context.Context) (*types.ContainerState, error)
- func (container *Container) Stop(ctx context.Context, timeout *time.Duration) error
- func (container *Container) StopLogProducer() error
- func (container *Container) Terminate(ctx context.Context) error
- func (container Container) WillWaitForHealth(waitTime time.Duration) Container
- func (container Container) WillWaitForLogs(logStatements ...string) Container
- func (container Container) WillWaitForPorts(ports ...string) Container
- func (container Container) WithBinds(binds ...string) Container
- func (container Container) WithBuildArgs(args map[string]*string) Container
- func (container Container) WithCmd(cmd ...string) Container
- func (container Container) WithContext(path string) Container
- func (container Container) WithContextArchive(contextArchive io.Reader) Container
- func (container Container) WithDockerfile(dockerfile string) Container
- func (container Container) WithEntrypoint(entrypoint ...string) Container
- func (container Container) WithEnv(env map[string]string) Container
- func (container Container) WithEnvVar(key, value string) Container
- func (container Container) WithExposedPorts(ports ...string) Container
- func (container Container) WithFile(file testcontainers.ContainerFile) Container
- func (container Container) WithHostConfigModifier(cm func(*dockerContainer.HostConfig)) Container
- func (container Container) WithImage(image string) Container
- func (container Container) WithLabel(key, value string) Container
- func (container Container) WithLabels(labels map[string]string) Container
- func (container Container) WithMount(mount testcontainers.ContainerMount) Container
- func (container Container) WithName(name string) Container
- func (container Container) WithNetworkMode(mode string) Container
- func (container Container) WithNetworks(networks ...string) Container
- func (container Container) WithPriviledged(privileged bool) Container
- func (container Container) WithStartupTimeout(startupTimeout time.Duration) Container
- func (container Container) WithUser(user string) Container
- type OTLPReceiverSink
- func (otlp *OTLPReceiverSink) AllLogs() []plog.Logs
- func (otlp *OTLPReceiverSink) AllMetrics() []pmetric.Metrics
- func (otlp *OTLPReceiverSink) AllTraces() []ptrace.Traces
- func (otlp *OTLPReceiverSink) AssertAllLogsReceived(t testing.TB, expectedResourceLogs telemetry.ResourceLogs, ...) error
- func (otlp *OTLPReceiverSink) AssertAllMetricsReceived(t testing.TB, expectedResourceMetrics telemetry.ResourceMetrics, ...) error
- func (otlp *OTLPReceiverSink) AssertAllTracesReceived(t testing.TB, expectedResourceTraces telemetry.ResourceTraces, ...) error
- func (otlp OTLPReceiverSink) Build() (*OTLPReceiverSink, error)
- func (otlp *OTLPReceiverSink) DataPointCount() int
- func (otlp *OTLPReceiverSink) LogRecordCount() int
- func (otlp *OTLPReceiverSink) Reset()
- func (otlp *OTLPReceiverSink) Shutdown() error
- func (otlp *OTLPReceiverSink) SpanCount() int
- func (otlp *OTLPReceiverSink) Start() error
- func (otlp OTLPReceiverSink) WithEndpoint(endpoint string) OTLPReceiverSink
- type TestOption
- type Testcase
- func (t *Testcase) Containers(builders ...Container) (containers []*Container, stop func())
- func (t *Testcase) PrintLogsOnFailure()
- func (t *Testcase) ResourceLogs(filename string) *telemetry.ResourceLogs
- func (t *Testcase) ResourceMetrics(filename string) *telemetry.ResourceMetrics
- func (t *Testcase) ShutdownOTLPReceiverSink()
- func (t *Testcase) SplunkOtelCollector(configFilename string, builders ...CollectorBuilder) (collector Collector, shutdown func())
- func (t *Testcase) SplunkOtelCollectorContainer(configFilename string, builders ...CollectorBuilder) (collector *CollectorContainer, shutdown func())
- func (t *Testcase) SplunkOtelCollectorProcess(configFilename string, builders ...CollectorBuilder) (collector *CollectorProcess, shutdown func())
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertAllLogsReceived ¶
func AssertAllLogsReceived( t testing.TB, resourceLogsFilename, collectorConfigFilename string, containers []Container, builders []CollectorBuilder, )
AssertAllLogsReceived is a central helper, designed to avoid most boilerplate. Using the desired ResourceLogs and Collector Config filenames, a slice of Container builders, and a slice of CollectorBuilder AssertAllLogsReceived creates a Testcase, builds and starts all Container and CollectorBuilder-determined Collector instances, and asserts that all expected ResourceLogs are received before running validated cleanup functionality.
func AssertAllMetricsReceived ¶
func AssertAllMetricsReceived( t testing.TB, resourceMetricsFilename, collectorConfigFilename string, containers []Container, builders []CollectorBuilder, )
AssertAllMetricsReceived is a central helper, designed to avoid most boilerplate. Using the desired ResourceMetrics and Collector Config filenames, a slice of Container builders, and a slice of CollectorBuilder AssertAllMetricsReceived creates a Testcase, builds and starts all Container and CollectorBuilder-determined Collector instances, and asserts that all expected ResourceMetrics are received before running validated cleanup functionality.
func CheckGoldenFile ¶
func CheckGoldenFile(t *testing.T, configFile string, expectedFilePath string, options ...pmetrictest.CompareMetricsOption)
func CheckGoldenFileWithCollectorOptions ¶
func CheckGoldenFileWithCollectorOptions(t *testing.T, configFile string, expectedFilePath string, collectorOptionsFunc func(Collector) Collector, options ...pmetrictest.CompareMetricsOption)
func CheckGoldenFileWithMount ¶
func CheckGoldenFileWithMount(t *testing.T, configFile string, expectedFilePath string, files [][]string, options ...pmetrictest.CompareMetricsOption)
func CollectorImageIsForArm ¶
func CollectorImageIsSet ¶
func CollectorImageIsSet() bool
func GetAvailablePort ¶
GetAvailablePort finds an available local port and returns it. The port is available for opening when this function returns provided that there is no race by some other code to grab the same port immediately.
func GetCollectorImage ¶
func GetCollectorImage() string
func GetDockerGID ¶
func HasTestOption ¶
func HasTestOption(opt TestOption, opts []TestOption) bool
func SkipIfNotContainerTest ¶
Types ¶
type Collector ¶
type Collector interface { WithConfigPath(path string) Collector WithArgs(args ...string) Collector WithEnv(env map[string]string) Collector WithLogger(logger *zap.Logger) Collector WithLogLevel(level string) Collector WillFail(fail bool) Collector WithMount(path string, mountPoint string) Collector Build() (Collector, error) Start() error Shutdown() error InitialConfig(t testing.TB, port uint16) map[string]any EffectiveConfig(t testing.TB, port uint16) map[string]any }
type CollectorBuilder ¶
type CollectorContainer ¶
type CollectorContainer struct { Logger *zap.Logger Mounts map[string]string Image string ConfigPath string LogLevel string Args []string Ports []string Container Container Fail bool // contains filtered or unexported fields }
func NewCollectorContainer ¶
func NewCollectorContainer() CollectorContainer
To be used as a builder whose Build() method provides the actual instance capable of launching the process.
func (CollectorContainer) Build ¶
func (collector CollectorContainer) Build() (Collector, error)
func (*CollectorContainer) EffectiveConfig ¶
func (*CollectorContainer) InitialConfig ¶
func (*CollectorContainer) Shutdown ¶
func (collector *CollectorContainer) Shutdown() error
func (*CollectorContainer) Start ¶
func (collector *CollectorContainer) Start() error
func (CollectorContainer) WillFail ¶
func (collector CollectorContainer) WillFail(fail bool) Collector
func (CollectorContainer) WithArgs ¶
func (collector CollectorContainer) WithArgs(args ...string) Collector
[]string{} by default
func (CollectorContainer) WithConfigPath ¶
func (collector CollectorContainer) WithConfigPath(path string) Collector
Will use bundled config by default
func (CollectorContainer) WithEnv ¶
func (collector CollectorContainer) WithEnv(env map[string]string) Collector
empty by default
func (CollectorContainer) WithExposedPorts ¶
func (collector CollectorContainer) WithExposedPorts(ports ...string) CollectorContainer
func (CollectorContainer) WithImage ¶
func (collector CollectorContainer) WithImage(image string) CollectorContainer
quay.io/signalfx/splunk-otel-collector:latest by default
func (CollectorContainer) WithLogLevel ¶
func (collector CollectorContainer) WithLogLevel(level string) Collector
"info" by default, but currently a noop
func (CollectorContainer) WithLogger ¶
func (collector CollectorContainer) WithLogger(logger *zap.Logger) Collector
Nop logger by default
type CollectorProcess ¶
type CollectorProcess struct { Env map[string]string Logger *zap.Logger Process *subprocess.Subprocess Path string ConfigPath string LogLevel string Args []string Fail bool // contains filtered or unexported fields }
func NewCollectorProcess ¶
func NewCollectorProcess() CollectorProcess
To be used as a builder whose Build() method provides the actual instance capable of launching the process.
func (CollectorProcess) Build ¶
func (collector CollectorProcess) Build() (Collector, error)
func (*CollectorProcess) EffectiveConfig ¶
func (*CollectorProcess) InitialConfig ¶
func (*CollectorProcess) Shutdown ¶
func (collector *CollectorProcess) Shutdown() error
func (*CollectorProcess) Start ¶
func (collector *CollectorProcess) Start() error
func (CollectorProcess) WillFail ¶
func (collector CollectorProcess) WillFail(fail bool) Collector
noop at this time
func (CollectorProcess) WithArgs ¶
func (collector CollectorProcess) WithArgs(args ...string) Collector
[]string{"--set=service.telemetry.logs.level={collector.LogLevel}", "--config", collector.ConfigPath, "--set=service.telemetry.metrics.level=none"} by default
func (CollectorProcess) WithConfigPath ¶
func (collector CollectorProcess) WithConfigPath(path string) Collector
Required
func (CollectorProcess) WithEnv ¶
func (collector CollectorProcess) WithEnv(env map[string]string) Collector
empty by default
func (CollectorProcess) WithLogLevel ¶
func (collector CollectorProcess) WithLogLevel(level string) Collector
info by default
func (CollectorProcess) WithLogger ¶
func (collector CollectorProcess) WithLogger(logger *zap.Logger) Collector
Nop logger by default
func (CollectorProcess) WithMount ¶
func (collector CollectorProcess) WithMount(string, string) Collector
func (CollectorProcess) WithPath ¶
func (collector CollectorProcess) WithPath(path string) CollectorProcess
Nearest `bin/otelcol` by default
type Container ¶
type Container struct { Env map[string]string Labels map[string]string Dockerfile testcontainers.FromDockerfile User string Image string ContainerName string ContainerNetworkMode string Entrypoint []string Cmd []string ContainerNetworks []string ExposedPorts []string Binds []string WaitingFor []wait.Strategy Mounts []testcontainers.ContainerMount Files []testcontainers.ContainerFile HostConfigModifiers []func(*dockerContainer.HostConfig) Privileged bool // contains filtered or unexported fields }
Container is a combination builder and testcontainers.Container wrapper for convenient creation and management of docker images and containers.
func NewContainer ¶
func NewContainer() Container
To be used as a builder whose Build() method provides the actual instance capable of being started, and that implements a testcontainers.Container.
func (*Container) AssertExec ¶
func (container *Container) AssertExec(t testing.TB, timeout time.Duration, cmd ...string) (rc int, stdout, stderr string)
AssertExec will assert that the exec'ed command completes within the specified timeout, returning the return code and demuxed stdout and stderr
func (*Container) ContainerIP ¶
func (*Container) ContainerIPs ¶
func (*Container) CopyDirToContainer ¶
func (*Container) CopyFileFromContainer ¶
func (*Container) CopyFileToContainer ¶
func (*Container) CopyToContainer ¶
func (*Container) FollowOutput ¶
func (container *Container) FollowOutput(consumer testcontainers.LogConsumer)
func (*Container) GetContainerID ¶
func (*Container) MappedPort ¶
func (*Container) NetworkAliases ¶
func (*Container) PortEndpoint ¶
func (*Container) StartLogProducer ¶
func (*Container) StopLogProducer ¶
func (Container) WillWaitForHealth ¶
func (Container) WillWaitForLogs ¶
func (Container) WillWaitForPorts ¶
func (Container) WithBuildArgs ¶
func (Container) WithContext ¶
func (Container) WithContextArchive ¶
func (Container) WithDockerfile ¶
func (Container) WithEntrypoint ¶
func (Container) WithEnvVar ¶
func (Container) WithExposedPorts ¶
func (Container) WithFile ¶
func (container Container) WithFile(file testcontainers.ContainerFile) Container
func (Container) WithHostConfigModifier ¶
func (container Container) WithHostConfigModifier(cm func(*dockerContainer.HostConfig)) Container
func (Container) WithLabels ¶
func (Container) WithMount ¶
func (container Container) WithMount(mount testcontainers.ContainerMount) Container
func (Container) WithNetworkMode ¶
func (Container) WithNetworks ¶
func (Container) WithPriviledged ¶
func (Container) WithStartupTimeout ¶
type OTLPReceiverSink ¶
type OTLPReceiverSink struct { Host component.Host Logger *zap.Logger Endpoint string // contains filtered or unexported fields }
To be used as a builder whose Build() method provides the actual instance capable of starting the OTLP receiver providing received metrics to test cases.
func NewOTLPReceiverSink ¶
func NewOTLPReceiverSink() OTLPReceiverSink
func (*OTLPReceiverSink) AllLogs ¶
func (otlp *OTLPReceiverSink) AllLogs() []plog.Logs
func (*OTLPReceiverSink) AllMetrics ¶
func (otlp *OTLPReceiverSink) AllMetrics() []pmetric.Metrics
func (*OTLPReceiverSink) AllTraces ¶
func (otlp *OTLPReceiverSink) AllTraces() []ptrace.Traces
func (*OTLPReceiverSink) AssertAllLogsReceived ¶
func (otlp *OTLPReceiverSink) AssertAllLogsReceived(t testing.TB, expectedResourceLogs telemetry.ResourceLogs, waitTime time.Duration) error
func (*OTLPReceiverSink) AssertAllMetricsReceived ¶
func (otlp *OTLPReceiverSink) AssertAllMetricsReceived(t testing.TB, expectedResourceMetrics telemetry.ResourceMetrics, waitTime time.Duration) error
func (*OTLPReceiverSink) AssertAllTracesReceived ¶
func (otlp *OTLPReceiverSink) AssertAllTracesReceived(t testing.TB, expectedResourceTraces telemetry.ResourceTraces, waitTime time.Duration) error
func (OTLPReceiverSink) Build ¶
func (otlp OTLPReceiverSink) Build() (*OTLPReceiverSink, error)
Build will create, configure, and start an OTLPReceiver with GRPC listener and associated metric and log sinks
func (*OTLPReceiverSink) DataPointCount ¶
func (otlp *OTLPReceiverSink) DataPointCount() int
func (*OTLPReceiverSink) LogRecordCount ¶
func (otlp *OTLPReceiverSink) LogRecordCount() int
func (*OTLPReceiverSink) Reset ¶
func (otlp *OTLPReceiverSink) Reset()
func (*OTLPReceiverSink) Shutdown ¶
func (otlp *OTLPReceiverSink) Shutdown() error
func (*OTLPReceiverSink) SpanCount ¶
func (otlp *OTLPReceiverSink) SpanCount() int
func (*OTLPReceiverSink) Start ¶
func (otlp *OTLPReceiverSink) Start() error
func (OTLPReceiverSink) WithEndpoint ¶
func (otlp OTLPReceiverSink) WithEndpoint(endpoint string) OTLPReceiverSink
WithEndpoint is required or Build() will fail
type TestOption ¶
type TestOption int
const ( OTLPReceiverSinkAllInterfaces TestOption = iota OTLPReceiverSinkBindToBridgeGateway )
type Testcase ¶
type Testcase struct { testing.TB Logger *zap.Logger ObservedLogs *observer.ObservedLogs OTLPReceiverSink *OTLPReceiverSink OTLPEndpoint string OTLPEndpointForCollector string ID string OTLPReceiverShouldBindAllInterfaces bool }
A Testcase is a central helper utility to provide Container, OTLPReceiverSink, ResourceMetrics, SplunkOtelCollector, and ObservedLogs to integration tests with minimal boilerplate. It also embeds testing.TB for easy testing and testify usage.
func NewTestcase ¶
func NewTestcase(t testing.TB, opts ...TestOption) *Testcase
NewTestcase is the recommended constructor that will automatically configure an OTLPReceiverSink with available endpoint and ObservedLogs.
func (*Testcase) Containers ¶
Builds and starts all provided Container builder instances, returning them and a validating stop function.
func (*Testcase) PrintLogsOnFailure ¶
func (t *Testcase) PrintLogsOnFailure()
PrintLogsOnFailure will print all ObserverLogs messages if the test has failed. It's intended to be deferred after Testcase creation. There is a bug in testcontainers-go so it's not certain these are complete: https://github.com/testcontainers/testcontainers-go/pull/323
func (*Testcase) ResourceLogs ¶
func (t *Testcase) ResourceLogs(filename string) *telemetry.ResourceLogs
Loads and validates a ResourceLogs instance, assuming it's located in ./testdata/resource_metrics
func (*Testcase) ResourceMetrics ¶
func (t *Testcase) ResourceMetrics(filename string) *telemetry.ResourceMetrics
Loads and validates a ResourceMetrics instance, assuming it's located in ./testdata/resource_metrics
func (*Testcase) ShutdownOTLPReceiverSink ¶
func (t *Testcase) ShutdownOTLPReceiverSink()
Validating shutdown helper for the Testcase's OTLPReceiverSink
func (*Testcase) SplunkOtelCollector ¶
func (t *Testcase) SplunkOtelCollector(configFilename string, builders ...CollectorBuilder) (collector Collector, shutdown func())
SplunkOtelCollector builds and starts a collector container or process using the desired config filename (assuming it's in the ./testdata directory) returning it and a validating shutdown function.
func (*Testcase) SplunkOtelCollectorContainer ¶
func (t *Testcase) SplunkOtelCollectorContainer(configFilename string, builders ...CollectorBuilder) (collector *CollectorContainer, shutdown func())
SplunkOtelCollectorContainer is the same as SplunkOtelCollector but returns *CollectorContainer. If SPLUNK_OTEL_COLLECTOR_IMAGE isn't set, tests that call this will be skipped.
func (*Testcase) SplunkOtelCollectorProcess ¶
func (t *Testcase) SplunkOtelCollectorProcess(configFilename string, builders ...CollectorBuilder) (collector *CollectorProcess, shutdown func())
SplunkOtelCollectorProcess is the same as SplunkOtelCollector but returns *CollectorProcess.