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

Function TestEscapedEncode

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

Source from the content-addressed store, hash-verified

303}
304
305func TestEscapedEncode(t *testing.T) {
306 tests := []struct {
307 name string
308 format Format
309 }{
310 {
311 name: "ProtoDelim",
312 format: FmtProtoDelim,
313 },
314 {
315 name: "ProtoDelim with escaping underscores",
316 format: FmtProtoDelim + "; escaping=underscores",
317 },
318 {
319 name: "ProtoCompact",
320 format: FmtProtoCompact,
321 },
322 {
323 name: "ProtoText",
324 format: FmtProtoText,
325 },
326 {
327 name: "Text",
328 format: FmtText,
329 },
330 }
331
332 metric := &dto.MetricFamily{
333 Name: proto.String("foo.metric"),
334 Type: dto.MetricType_UNTYPED.Enum(),
335 Metric: []*dto.Metric{
336 {
337 Untyped: &dto.Untyped{
338 Value: proto.Float64(1.234),
339 },
340 },
341 {
342 Label: []*dto.LabelPair{
343 {
344 Name: proto.String("dotted.label.name"),
345 Value: proto.String("my.label.value"),
346 },
347 },
348 Untyped: &dto.Untyped{
349 Value: proto.Float64(8),
350 },
351 },
352 },
353 }
354
355 for _, tt := range tests {
356 t.Run(tt.name, func(t *testing.T) {
357 var buff bytes.Buffer
358 encoder := NewEncoder(&buff, tt.format)
359 err := encoder.Encode(metric)
360 require.NoError(t, err)
361
362 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…