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

Function TestEscapedEncode

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

Source from the content-addressed store, hash-verified

505}
506
507func TestEscapedEncode(t *testing.T) {
508 tests := []struct {
509 name string
510 format Format
511 }{
512 {
513 name: "ProtoDelim",
514 format: FmtProtoDelim,
515 },
516 {
517 name: "ProtoDelim with escaping underscores",
518 format: FmtProtoDelim + "; escaping=underscores",
519 },
520 {
521 name: "ProtoCompact",
522 format: FmtProtoCompact,
523 },
524 {
525 name: "ProtoText",
526 format: FmtProtoText,
527 },
528 {
529 name: "Text",
530 format: FmtText,
531 },
532 }
533
534 metric := &dto.MetricFamily{
535 Name: proto.String("foo.metric"),
536 Type: dto.MetricType_UNTYPED.Enum(),
537 Metric: []*dto.Metric{
538 {
539 Untyped: &dto.Untyped{
540 Value: proto.Float64(1.234),
541 },
542 },
543 {
544 Label: []*dto.LabelPair{
545 {
546 Name: proto.String("dotted.label.name"),
547 Value: proto.String("my.label.value"),
548 },
549 },
550 Untyped: &dto.Untyped{
551 Value: proto.Float64(8),
552 },
553 },
554 },
555 }
556
557 for _, tt := range tests {
558 t.Run(tt.name, func(t *testing.T) {
559 var buff bytes.Buffer
560 encoder := NewEncoder(&buff, tt.format)
561 err := encoder.Encode(metric)
562 require.NoError(t, err)
563
564 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