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

Function TestEncode

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

Source from the content-addressed store, hash-verified

394}
395
396func TestEncode(t *testing.T) {
397 metric1 := &dto.MetricFamily{
398 Name: proto.String("foo_metric"),
399 Type: dto.MetricType_UNTYPED.Enum(),
400 Unit: proto.String("seconds"),
401 Metric: []*dto.Metric{
402 {
403 Untyped: &dto.Untyped{
404 Value: proto.Float64(1.234),
405 },
406 },
407 },
408 }
409
410 scenarios := []struct {
411 metric *dto.MetricFamily
412 format Format
413 options []EncoderOption
414 expOut string
415 }{
416 // 1: Untyped ProtoDelim
417 {
418 metric: metric1,
419 format: FmtProtoDelim,
420 },
421 // 2: Untyped FmtProtoCompact
422 {
423 metric: metric1,
424 format: FmtProtoCompact,
425 },
426 // 3: Untyped FmtProtoText
427 {
428 metric: metric1,
429 format: FmtProtoText,
430 },
431 // 4: Untyped FmtText
432 {
433 metric: metric1,
434 format: FmtText,
435 expOut: `# TYPE foo_metric untyped
436foo_metric 1.234
437`,
438 },
439 // 5: Untyped FmtOpenMetrics_0_0_1
440 {
441 metric: metric1,
442 format: FmtOpenMetrics_0_0_1,
443 expOut: `# TYPE foo_metric unknown
444# UNIT foo_metric seconds
445foo_metric 1.234
446`,
447 },
448 // 6: Untyped FmtOpenMetrics_1_0_0
449 {
450 metric: metric1,
451 format: FmtOpenMetrics_1_0_0,
452 expOut: `# TYPE foo_metric unknown
453# 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