@@ -18,6 +18,7 @@ import (
1818 "net/http"
1919 "testing"
2020
21+ "github.com/stretchr/testify/assert"
2122 "github.com/stretchr/testify/require"
2223 "google.golang.org/protobuf/proto"
2324
@@ -311,50 +312,28 @@ foo_metric 1.234
311312
312313func TestEscapedEncode (t * testing.T ) {
313314 tests := []struct {
314- name string
315- format Format
316- expectedOutput string // empty means no specific output check
315+ name string
316+ format Format
317317 }{
318318 {
319- name : "ProtoDelim with escaping" ,
320- format : FmtProtoDelim + "; escaping=underscores" ,
321- expectedOutput : "M\n \n foo_metric\x18 \x03 \" \v *\t \t X9\xb4 \xc8 v\xbe \xf3 ?\" 0\n #\n \x11 dotted_label_name\x12 \x0e my.label.value*\t \t \x00 \x00 \x00 \x00 \x00 \x00 @" ,
319+ name : "ProtoDelim" ,
320+ format : FmtProtoDelim ,
321+ },
322+ {
323+ name : "ProtoDelim with escaping underscores" ,
324+ format : FmtProtoDelim + "; escaping=underscores" ,
322325 },
323326 {
324327 name : "ProtoCompact" ,
325328 format : FmtProtoCompact ,
326- expectedOutput : `name:"foo_metric" type:UNTYPED metric:{untyped:{value:1.234}} metric:{label:{name:"dotted_label_name" value:"my.label.value"} untyped:{value:8}}
327- ` ,
328329 },
329330 {
330331 name : "ProtoText" ,
331332 format : FmtProtoText ,
332- expectedOutput : `name: "foo_metric"
333- type: UNTYPED
334- metric: {
335- untyped: {
336- value: 1.234
337- }
338- }
339- metric: {
340- label: {
341- name: "dotted_label_name"
342- value: "my.label.value"
343- }
344- untyped: {
345- value: 8
346- }
347- }
348-
349- ` ,
350333 },
351334 {
352335 name : "Text" ,
353336 format : FmtText ,
354- expectedOutput : `# TYPE foo_metric untyped
355- foo_metric 1.234
356- foo_metric{dotted_label_name="my.label.value"} 8
357- ` ,
358337 },
359338 }
360339
@@ -388,10 +367,12 @@ foo_metric{dotted_label_name="my.label.value"} 8
388367 err := encoder .Encode (metric )
389368 require .NoError (t , err )
390369
391- out := buff .Bytes ()
392- require .NotEmptyf (t , out , "expected the output bytes buffer to be non-empty" )
393-
394- require .Equal (t , tt .expectedOutput , string (out ))
370+ s := buff .String ()
371+ assert .NotContains (t , s , "foo.metric" )
372+ assert .Contains (t , s , "foo_metric" )
373+ assert .NotContains (t , s , "dotted.label.name" )
374+ assert .Contains (t , s , "dotted_label_name" )
375+ assert .Contains (t , s , "my.label.value" )
395376 })
396377 }
397378}
0 commit comments