(t *testing.T)
| 618 | } |
| 619 | |
| 620 | func 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: ×tamppb.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) |
nothing calls this directly
no test coverage detected