MCPcopy Create free account
hub / github.com/prometheus/common / TestEscapedEncode

Function TestEscapedEncode

expfmt/encode_test.go:432–497  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

430}
431
432func TestEscapedEncode(t *testing.T) {
433 tests := []struct {
434 name string
435 format Format
436 }{
437 {
438 name: "ProtoDelim",
439 format: FmtProtoDelim,
440 },
441 {
442 name: "ProtoDelim with escaping underscores",
443 format: FmtProtoDelim + "; escaping=underscores",
444 },
445 {
446 name: "ProtoCompact",
447 format: FmtProtoCompact,
448 },
449 {
450 name: "ProtoText",
451 format: FmtProtoText,
452 },
453 {
454 name: "Text",
455 format: FmtText,
456 },
457 }
458
459 metric := &dto.MetricFamily{
460 Name: proto.String("foo.metric"),
461 Type: dto.MetricType_UNTYPED.Enum(),
462 Metric: []*dto.Metric{
463 {
464 Untyped: &dto.Untyped{
465 Value: proto.Float64(1.234),
466 },
467 },
468 {
469 Label: []*dto.LabelPair{
470 {
471 Name: proto.String("dotted.label.name"),
472 Value: proto.String("my.label.value"),
473 },
474 },
475 Untyped: &dto.Untyped{
476 Value: proto.Float64(8),
477 },
478 },
479 },
480 }
481
482 for _, tt := range tests {
483 t.Run(tt.name, func(t *testing.T) {
484 var buff bytes.Buffer
485 encoder := NewEncoder(&buff, tt.format)
486 err := encoder.Encode(metric)
487 require.NoError(t, err)
488
489 s := buff.String()

Callers

nothing calls this directly

Calls 3

EncodeMethod · 0.95
NewEncoderFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected