@@ -17,6 +17,8 @@ import (
1717 "testing"
1818
1919 "github.com/prometheus/common/model"
20+
21+ "github.com/stretchr/testify/require"
2022)
2123
2224// Test Format to Escapting Scheme conversion
@@ -92,9 +94,7 @@ func TestToFormatType(t *testing.T) {
9294 },
9395 }
9496 for _ , test := range tests {
95- if test .format .FormatType () != test .expected {
96- t .Errorf ("expected %v got %v" , test .expected , test .format .FormatType ())
97- }
97+ require .Equal (t , test .expected , test .format .FormatType ())
9898 }
9999}
100100
@@ -122,8 +122,43 @@ func TestToEscapingScheme(t *testing.T) {
122122 },
123123 }
124124 for _ , test := range tests {
125- if test .format .ToEscapingScheme () != test .expected {
126- t .Errorf ("expected %v got %v" , test .expected , test .format .ToEscapingScheme ())
127- }
125+ require .Equal (t , test .expected , test .format .ToEscapingScheme ())
126+ }
127+ }
128+
129+ func TestWithEscapingScheme (t * testing.T ) {
130+ tests := []struct {
131+ name string
132+ format Format
133+ scheme model.EscapingScheme
134+ expected string
135+ }{
136+ {
137+ name : "no existing term, append one" ,
138+ format : FmtProtoCompact ,
139+ scheme : model .DotsEscaping ,
140+ expected : "application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text; escaping=dots" ,
141+ },
142+ {
143+ name : "existing term at end, replace" ,
144+ format : "application/openmetrics-text; version=1.0.0; charset=utf-8; escaping=underscores" ,
145+ scheme : model .ValueEncodingEscaping ,
146+ expected : "application/openmetrics-text; version=1.0.0; charset=utf-8; escaping=values" ,
147+ },
148+ {
149+ name : "existing term in middle, replace" ,
150+ format : "application/openmetrics-text; escaping=dots; version=1.0.0; charset=utf-8; " ,
151+ scheme : model .NoEscaping ,
152+ expected : "application/openmetrics-text; version=1.0.0; charset=utf-8; escaping=allow-utf-8" ,
153+ },
154+ {
155+ name : "multiple existing terms removed" ,
156+ format : "application/openmetrics-text; escaping=dots; version=1.0.0; charset=utf-8; escaping=allow-utf-8" ,
157+ scheme : model .ValueEncodingEscaping ,
158+ expected : "application/openmetrics-text; version=1.0.0; charset=utf-8; escaping=values" ,
159+ },
160+ }
161+ for _ , test := range tests {
162+ require .Equal (t , test .expected , string (test .format .WithEscapingScheme (test .scheme )))
128163 }
129164}
0 commit comments