MCPcopy Create free account
hub / github.com/prometheus/common / TestEncode

Function TestEncode

expfmt/encode_test.go:321–430  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

319}
320
321func TestEncode(t *testing.T) {
322 metric1 := &dto.MetricFamily{
323 Name: proto.String("foo_metric"),
324 Type: dto.MetricType_UNTYPED.Enum(),
325 Unit: proto.String("seconds"),
326 Metric: []*dto.Metric{
327 {
328 Untyped: &dto.Untyped{
329 Value: proto.Float64(1.234),
330 },
331 },
332 },
333 }
334
335 scenarios := []struct {
336 metric *dto.MetricFamily
337 format Format
338 options []EncoderOption
339 expOut string
340 }{
341 // 1: Untyped ProtoDelim
342 {
343 metric: metric1,
344 format: FmtProtoDelim,
345 },
346 // 2: Untyped FmtProtoCompact
347 {
348 metric: metric1,
349 format: FmtProtoCompact,
350 },
351 // 3: Untyped FmtProtoText
352 {
353 metric: metric1,
354 format: FmtProtoText,
355 },
356 // 4: Untyped FmtText
357 {
358 metric: metric1,
359 format: FmtText,
360 expOut: `# TYPE foo_metric untyped
361foo_metric 1.234
362`,
363 },
364 // 5: Untyped FmtOpenMetrics_0_0_1
365 {
366 metric: metric1,
367 format: FmtOpenMetrics_0_0_1,
368 expOut: `# TYPE foo_metric unknown
369# UNIT foo_metric seconds
370foo_metric 1.234
371`,
372 },
373 // 6: Untyped FmtOpenMetrics_1_0_0
374 {
375 metric: metric1,
376 format: FmtOpenMetrics_1_0_0,
377 expOut: `# TYPE foo_metric unknown
378# UNIT foo_metric seconds

Callers

nothing calls this directly

Calls 3

EncodeMethod · 0.95
NewEncoderFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected