(t *testing.T)
| 693 | } |
| 694 | |
| 695 | func TestNegotiateAcceptEncodeUTF8Names(t *testing.T) { |
| 696 | mf := &dto.MetricFamily{ |
| 697 | Name: proto.String("my.metric"), |
| 698 | Type: dto.MetricType_GAUGE.Enum(), |
| 699 | Metric: []*dto.Metric{ |
| 700 | { |
| 701 | Label: []*dto.LabelPair{{Name: proto.String("my.label"), Value: proto.String("v")}}, |
| 702 | Gauge: &dto.Gauge{Value: proto.Float64(1)}, |
| 703 | }, |
| 704 | }, |
| 705 | } |
| 706 | |
| 707 | tests := []struct { |
| 708 | name string |
| 709 | accept string |
| 710 | expected string |
| 711 | }{ |
| 712 | { |
| 713 | name: "OM 2.0-rc without escaping keeps UTF-8 names", |
| 714 | accept: "application/openmetrics-text;version=2.0.0-rc", |
| 715 | expected: `{"my.metric","my.label"="v"} 1.0`, |
| 716 | }, |
| 717 | { |
| 718 | name: "OM 2.0-rc with escaping=underscores escapes", |
| 719 | accept: "application/openmetrics-text;version=2.0.0-rc;escaping=underscores", |
| 720 | expected: `my_metric{my_label="v"} 1.0`, |
| 721 | }, |
| 722 | { |
| 723 | name: "OM 2.0 without escaping keeps UTF-8 names", |
| 724 | accept: "application/openmetrics-text;version=2.0.0", |
| 725 | expected: `{"my.metric","my.label"="v"} 1.0`, |
| 726 | }, |
| 727 | { |
| 728 | name: "OM 2.0 with escaping=underscores escapes", |
| 729 | accept: "application/openmetrics-text;version=2.0.0;escaping=underscores", |
| 730 | expected: `my_metric{my_label="v"} 1.0`, |
| 731 | }, |
| 732 | { |
| 733 | name: "OM 1.0 without escaping escapes", |
| 734 | accept: "application/openmetrics-text;version=1.0.0", |
| 735 | expected: `my_metric{my_label="v"} 1.0`, |
| 736 | }, |
| 737 | { |
| 738 | name: "text without escaping escapes", |
| 739 | accept: "text/plain;version=0.0.4", |
| 740 | expected: `my_metric{my_label="v"} 1`, |
| 741 | }, |
| 742 | } |
| 743 | |
| 744 | oldDefault := model.NameEscapingScheme |
| 745 | model.NameEscapingScheme = model.UnderscoreEscaping |
| 746 | defer func() { |
| 747 | model.NameEscapingScheme = oldDefault |
| 748 | }() |
| 749 | |
| 750 | for _, tt := range tests { |
| 751 | t.Run(tt.name, func(t *testing.T) { |
| 752 | h := http.Header{} |
nothing calls this directly
no test coverage detected