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

Function TestNewEncoder_OpenMetricsVersionDispatch

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

Source from the content-addressed store, hash-verified

618}
619
620func TestNewEncoder_OpenMetricsVersionDispatch(t *testing.T) {
621 counterMetric := &dto.MetricFamily{
622 Name: proto.String("test_counter"),
623 Type: dto.MetricType_COUNTER.Enum(),
624 Metric: []*dto.Metric{
625 {
626 Counter: &dto.Counter{
627 Value: proto.Float64(42),
628 CreatedTimestamp: &timestamppb.Timestamp{
629 Seconds: 1234567890,
630 Nanos: 0,
631 },
632 },
633 },
634 },
635 }
636
637 tests := []struct {
638 name string
639 format Format
640 expectedLine string
641 }{
642 {
643 name: "OpenMetrics 1.0.0",
644 format: FmtOpenMetrics_1_0_0,
645 expectedLine: "# TYPE test_counter unknown\ntest_counter 42.0\n",
646 },
647 {
648 name: "OpenMetrics 0.0.1",
649 format: FmtOpenMetrics_0_0_1,
650 expectedLine: "# TYPE test_counter unknown\ntest_counter 42.0\n",
651 },
652 {
653 name: "OpenMetrics 2.0.0 standard",
654 format: fmtOpenMetrics_2_0_0,
655 expectedLine: "# TYPE test_counter counter\ntest_counter 42.0 st@1234567890\n",
656 },
657 {
658 name: "OpenMetrics 2.0.0 reordered parameters",
659 format: Format("application/openmetrics-text; charset=utf-8; version=2.0.0"),
660 expectedLine: "# TYPE test_counter counter\ntest_counter 42.0 st@1234567890\n",
661 },
662 {
663 name: "OpenMetrics 2.0.0 quoted version parameter",
664 format: Format(`application/openmetrics-text; version="2.0.0"; charset=utf-8`),
665 expectedLine: "# TYPE test_counter counter\ntest_counter 42.0 st@1234567890\n",
666 },
667 {
668 name: "OpenMetrics 2.0.0 with escaping scheme",
669 format: Format("application/openmetrics-text; version=2.0.0; charset=utf-8; escaping=values"),
670 expectedLine: "# TYPE test_counter counter\ntest_counter 42.0 st@1234567890\n",
671 },
672 }
673
674 for _, tt := range tests {
675 t.Run(tt.name, func(t *testing.T) {
676 var buf bytes.Buffer
677 enc := NewEncoder(&buf, tt.format)

Callers

nothing calls this directly

Calls 5

EncodeMethod · 0.95
NewEncoderFunction · 0.85
FormatTypeAlias · 0.70
StringMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected