testutil

package
v0.99.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package testutil contains the test util functions

Index

Constants

View Source
const (
	ValidateAPIKeyEndpoint = "/api/v1/validate" // nolint G101
	MetricV1Endpoint       = "/api/v1/series"
	MetricV2Endpoint       = "/api/v2/series"
	SketchesMetricEndpoint = "/api/beta/sketches"
	MetadataEndpoint       = "/intake"
	TraceEndpoint          = "/api/v0.2/traces"
	APMStatsEndpoint       = "/api/v0.2/stats"
)

#nosec G101 -- This is a false positive, these are API endpoints rather than credentials

Variables

View Source
var (

	// TestMetrics metrics for tests.
	TestMetrics = newMetricsWithAttributeMap(testAttributes)
	// TestTraces traces for tests.
	TestTraces = newTracesWithAttributeMap(testAttributes)
)
View Source
var StatsPayloads = []*pb.ClientStatsPayload{
	{
		Hostname:         "host",
		Env:              "prod",
		Version:          "v1.2",
		Lang:             "go",
		TracerVersion:    "v44",
		RuntimeID:        "123jkl",
		Sequence:         2,
		AgentAggregation: "blah",
		Service:          "mysql",
		ContainerID:      "abcdef123456",
		Tags:             []string{"a:b", "c:d"},
		Stats: []*pb.ClientStatsBucket{
			{
				Start:    10,
				Duration: 1,
				Stats: []*pb.ClientGroupedStats{
					{
						Service:        "kafka",
						Name:           "queue.add",
						Resource:       "append",
						HTTPStatusCode: 220,
						Type:           "queue",
						Hits:           15,
						Errors:         3,
						Duration:       143,
						OkSummary:      testSketchBytes(1, 2, 3),
						ErrorSummary:   testSketchBytes(4, 5, 6),
						TopLevelHits:   5,
					},
				},
			},
		},
	},
	{
		Hostname:         "host2",
		Env:              "prod2",
		Version:          "v1.22",
		Lang:             "go2",
		TracerVersion:    "v442",
		RuntimeID:        "123jkl2",
		Sequence:         22,
		AgentAggregation: "blah2",
		Service:          "mysql2",
		ContainerID:      "abcdef1234562",
		Tags:             []string{"a:b2", "c:d2"},
		Stats: []*pb.ClientStatsBucket{
			{
				Start:    102,
				Duration: 12,
				Stats: []*pb.ClientGroupedStats{
					{
						Service:        "kafka2",
						Name:           "queue.add2",
						Resource:       "append2",
						HTTPStatusCode: 2202,
						Type:           "queue2",
						Hits:           152,
						Errors:         32,
						Duration:       1432,
						OkSummary:      testSketchBytes(7, 8),
						ErrorSummary:   testSketchBytes(9, 10, 11),
						TopLevelHits:   52,
					},
				},
			},
		},
	},
}

StatsPayloads contains a couple of *pb.ClientStatsPayloads used for testing.

Functions

func NewAttributeMap

func NewAttributeMap(mp map[string]string) pcommon.Map

NewAttributeMap creates a new attribute map (string only) from a Go map

func NewGaugeMetrics

func NewGaugeMetrics(tgs []TestGauge) pmetric.Metrics

NewGaugeMetrics creates a set of pmetric.Metrics containing all the specified test gauges.

func ValidateAPIKeyEndpointInvalid

func ValidateAPIKeyEndpointInvalid() (string, http.HandlerFunc)

ValidateAPIKeyEndpointInvalid returns a handler function that returns an invalid API key response

Types

type DataPoint

type DataPoint struct {
	Value      float64
	Attributes map[string]string
}

DataPoint specifies a DoubleVal data point and its attributes.

type DatadogLogsServer

type DatadogLogsServer struct {
	*httptest.Server
	// LogsData is the array of json requests sent to datadog backend
	LogsData JSONLogs
}

func DatadogLogServerMock

func DatadogLogServerMock(overwriteHandlerFuncs ...OverwriteHandleFunc) *DatadogLogsServer

DatadogLogServerMock mocks a Datadog Logs Intake backend server

type DatadogServer

type DatadogServer struct {
	*httptest.Server
	MetadataChan chan []byte
}

func DatadogServerMock

func DatadogServerMock(overwriteHandlerFuncs ...OverwriteHandleFunc) *DatadogServer

DatadogServerMock mocks a Datadog backend server

type HTTPRequestRecorder

type HTTPRequestRecorder struct {
	Pattern  string
	Header   http.Header
	ByteBody []byte
}

HTTPRequestRecorder records a HTTP request.

func (*HTTPRequestRecorder) HandlerFunc

func (rec *HTTPRequestRecorder) HandlerFunc() (string, http.HandlerFunc)

type HTTPRequestRecorderWithChan added in v0.89.0

type HTTPRequestRecorderWithChan struct {
	Pattern string
	ReqChan chan []byte
}

HTTPRequestRecorderWithChan puts all incoming HTTP request bytes to the given channel.

func (*HTTPRequestRecorderWithChan) HandlerFunc added in v0.89.0

func (rec *HTTPRequestRecorderWithChan) HandlerFunc() (string, http.HandlerFunc)

type JSONLogs added in v0.72.0

type JSONLogs []map[string]any

JSONLogs is the type for the array of processed JSON log data from each request

func MockLogsEndpoint added in v0.72.0

func MockLogsEndpoint(w http.ResponseWriter, r *http.Request) JSONLogs

MockLogsEndpoint returns the processed JSON log data for each endpoint call

func (*JSONLogs) HasDDTag added in v0.72.0

func (jsonLogs *JSONLogs) HasDDTag(ddtags string) bool

HasDDTag returns true if every log has the given ddtags

type MockSourceProvider

type MockSourceProvider struct {
	Src source.Source
}

func (*MockSourceProvider) Source

type MockStatsProcessor added in v0.68.0

type MockStatsProcessor struct {
	In []*pb.ClientStatsPayload
}

func (*MockStatsProcessor) ProcessStats added in v0.68.0

func (s *MockStatsProcessor) ProcessStats(in *pb.ClientStatsPayload, _, _ string)

type OverwriteHandleFunc

type OverwriteHandleFunc func() (string, http.HandlerFunc)

OverwriteHandleFuncs allows to overwrite the default handler functions

type TestGauge

type TestGauge struct {
	Name       string
	DataPoints []DataPoint
}

TestGauge holds the definition of a basic gauge.

Jump to

Keyboard shortcuts

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