Documentation ¶
Overview ¶
Package testutil contains the test util functions
Index ¶
- Constants
- Variables
- func NewAttributeMap(mp map[string]string) pcommon.Map
- func NewGaugeMetrics(tgs []TestGauge) pmetric.Metrics
- func ValidateAPIKeyEndpointInvalid() (string, http.HandlerFunc)
- type DataPoint
- type DatadogLogsServer
- type DatadogServer
- type HTTPRequestRecorder
- type HTTPRequestRecorderWithChan
- type JSONLog
- type JSONLogs
- type MockSourceProvider
- type MockStatsProcessor
- type OverwriteHandleFunc
- type TestGauge
Constants ¶
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 ¶
var ( // TestMetrics metrics for tests. TestMetrics = newMetricsWithAttributeMap(testAttributes) // TestTraces traces for tests. TestTraces = newTracesWithAttributeMap(testAttributes) )
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 ¶
NewAttributeMap creates a new attribute map (string only) from a Go map
func NewGaugeMetrics ¶
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 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 payload.HostMetadata }
func DatadogServerMock ¶
func DatadogServerMock(overwriteHandlerFuncs ...OverwriteHandleFunc) *DatadogServer
DatadogServerMock mocks a Datadog backend server
type HTTPRequestRecorder ¶
HTTPRequestRecorder records a HTTP request.
func (*HTTPRequestRecorder) HandlerFunc ¶
func (rec *HTTPRequestRecorder) HandlerFunc() (string, http.HandlerFunc)
type HTTPRequestRecorderWithChan ¶ added in v0.89.0
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 JSONLog ¶ added in v0.100.0
JSONLog is the type for the processed JSON log data from a single log
type JSONLogs ¶ added in v0.72.0
type JSONLogs []JSONLog
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 ProcessLogsAgentRequest ¶ added in v0.100.0
func ProcessLogsAgentRequest(w http.ResponseWriter, r *http.Request) JSONLogs
type MockSourceProvider ¶
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