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

Function TestNewEncoder_OpenMetricsVersionDispatch

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

Source from the content-addressed store, hash-verified

763}
764
765func TestNewEncoder_OpenMetricsVersionDispatch(t *testing.T) {
766 counterMetric := &dto.MetricFamily{
767 Name: proto.String("test_counter"),
768 Type: dto.MetricType_COUNTER.Enum(),
769 Metric: []*dto.Metric{
770 {
771 Counter: &dto.Counter{
772 Value: proto.Float64(42),
773 CreatedTimestamp: &timestamppb.Timestamp{
774 Seconds: 1234567890,
775 Nanos: 0,
776 },
777 },
778 },
779 },
780 }
781
782 tests := []struct {
783 name string
784 format Format
785 expectedLine string
786 }{
787 {
788 name: "OpenMetrics 1.0.0",
789 format: FmtOpenMetrics_1_0_0,
790 expectedLine: "# TYPE test_counter unknown\ntest_counter 42.0\n",
791 },
792 {
793 name: "OpenMetrics 0.0.1",
794 format: FmtOpenMetrics_0_0_1,
795 expectedLine: "# TYPE test_counter unknown\ntest_counter 42.0\n",
796 },
797 {
798 name: "OpenMetrics 2.0.0-rc standard",
799 format: FmtOpenMetrics_2_0_0_rc,
800 expectedLine: "# TYPE test_counter counter\ntest_counter 42.0 st@1234567890\n",
801 },
802 {
803 name: "OpenMetrics 2.0.0 standard",
804 format: FmtOpenMetrics_2_0_0,
805 expectedLine: "# TYPE test_counter counter\ntest_counter 42.0 st@1234567890\n",
806 },
807 {
808 name: "OpenMetrics 2.0.0 reordered parameters",
809 format: Format("application/openmetrics-text; charset=utf-8; version=2.0.0"),
810 expectedLine: "# TYPE test_counter counter\ntest_counter 42.0 st@1234567890\n",
811 },
812 {
813 name: "OpenMetrics 2.0.0 quoted version parameter",
814 format: Format(`application/openmetrics-text; version="2.0.0"; charset=utf-8`),
815 expectedLine: "# TYPE test_counter counter\ntest_counter 42.0 st@1234567890\n",
816 },
817 {
818 name: "OpenMetrics 2.0.0 with escaping scheme",
819 format: Format("application/openmetrics-text; version=2.0.0; charset=utf-8; escaping=values"),
820 expectedLine: "# TYPE test_counter counter\ntest_counter 42.0 st@1234567890\n",
821 },
822 }

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