@@ -63,6 +63,45 @@ func TestNegotiate(t *testing.T) {
6363 }
6464}
6565
66+ func TestNegotiateOpenMetrics (t * testing.T ) {
67+ tests := []struct {
68+ name string
69+ acceptHeaderValue string
70+ expectedFmt string
71+ }{
72+ {
73+ name : "OM format, no version" ,
74+ acceptHeaderValue : "application/openmetrics-text" ,
75+ expectedFmt : string (FmtOpenMetrics_0_0_1 ),
76+ },
77+ {
78+ name : "OM format, 0.0.1 version" ,
79+ acceptHeaderValue : "application/openmetrics-text;version=0.0.1" ,
80+ expectedFmt : string (FmtOpenMetrics_0_0_1 ),
81+ },
82+ {
83+ name : "OM format, 1.0.0 version" ,
84+ acceptHeaderValue : "application/openmetrics-text;version=1.0.0" ,
85+ expectedFmt : string (FmtOpenMetrics_1_0_0 ),
86+ },
87+ {
88+ name : "OM format, invalid version" ,
89+ acceptHeaderValue : "application/openmetrics-text;version=0.0.4" ,
90+ expectedFmt : string (FmtText ),
91+ },
92+ }
93+
94+ for _ , test := range tests {
95+ t .Run (test .name , func (t * testing.T ) {
96+ h := http.Header {}
97+ h .Add (hdrAccept , test .acceptHeaderValue )
98+ actualFmt := string (NegotiateIncludingOpenMetrics (h ))
99+ if actualFmt != test .expectedFmt {
100+ t .Errorf ("expected Negotiate to return format %s, but got %s instead" , test .expectedFmt , actualFmt )
101+ }
102+ })
103+ }
104+ }
66105func TestEncode (t * testing.T ) {
67106 var buff bytes.Buffer
68107 delimEncoder := NewEncoder (& buff , FmtProtoDelim )
0 commit comments