MCPcopy Index your code
hub / github.com/cloudflare/ebpf_exporter / TestDecoderSetCache

Function TestDecoderSetCache

decoder/decoder_test.go:354–412  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

352}
353
354func TestDecoderSetCache(t *testing.T) {
355 in := []byte{0xba, 0xbe, 0xba, 0xbe, 0xde, 0xad, 0xbe, 0xef}
356
357 one := []config.Label{
358 {
359 Name: "single_u64",
360 Size: 8,
361 Decoders: []config.Decoder{
362 {
363 Name: "uint",
364 },
365 },
366 },
367 }
368
369 two := []config.Label{
370 {
371 Name: "u32_one",
372 Size: 4,
373 Decoders: []config.Decoder{
374 {
375 Name: "uint",
376 },
377 },
378 },
379 {
380 Name: "u32_two",
381 Size: 4,
382 Decoders: []config.Decoder{
383 {
384 Name: "uint",
385 },
386 },
387 },
388 }
389
390 s, err := NewSet(0, nil)
391 if err != nil {
392 t.Fatal(err)
393 }
394
395 single, err := s.DecodeLabelsForMetrics(in, "one", one)
396 if err != nil {
397 t.Fatal(err)
398 }
399
400 if len(single) != 1 {
401 t.Errorf("Expected one u64 from %#v, got %#v", one, single)
402 }
403
404 double, err := s.DecodeLabelsForMetrics(in, "two", two)
405 if err != nil {
406 t.Error(err)
407 }
408
409 if len(double) != 2 {
410 t.Errorf("Expected two u32 from %#v, got %#v", two, double)
411 }

Callers

nothing calls this directly

Calls 2

NewSetFunction · 0.85

Tested by

no test coverage detected