MCPcopy
hub / github.com/cloudflare/ebpf_exporter / TestDecodeLabels

Function TestDecodeLabels

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

Source from the content-addressed store, hash-verified

10)
11
12func TestDecodeLabels(t *testing.T) {
13 cases := []struct {
14 in []byte
15 labels []config.Label
16 out []string
17 err bool
18 }{
19 {
20 in: append([]byte{0x8, 0x0, 0x0, 0x0}, zeroPaddedString("potatoes", 16)...),
21 labels: []config.Label{
22 {
23 Name: "number",
24 Size: 4,
25 Decoders: []config.Decoder{
26 {
27 Name: "uint",
28 },
29 },
30 },
31 },
32 out: []string{"8"},
33 err: true, // not all labels are decoded
34 },
35 {
36 in: append([]byte{0x8, 0x0, 0x0, 0x0}, zeroPaddedString("bananas", 32)...),
37 labels: []config.Label{
38 {
39 Name: "number",
40 Size: 4,
41 Decoders: []config.Decoder{
42 {
43 Name: "uint",
44 },
45 },
46 },
47 {
48 Name: "fruit",
49 Size: 32,
50 Decoders: []config.Decoder{
51 {
52 Name: "string",
53 },
54 },
55 },
56 },
57 out: []string{"8", "bananas"},
58 err: false,
59 },
60 {
61 in: append([]byte{0x8, 0x1, 0x1, 0x1}, zeroPaddedString("bananas", 32)...),
62 labels: []config.Label{
63 {
64 Name: "number",
65 Size: 1,
66 Padding: 3, // only first byte should be used for the label
67 Decoders: []config.Decoder{
68 {
69 Name: "uint",

Callers

nothing calls this directly

Calls 3

zeroPaddedStringFunction · 0.85
NewSetFunction · 0.85

Tested by

no test coverage detected