github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/btf_test.go (about) 1 package gobpfld 2 3 import ( 4 "bytes" 5 "testing" 6 ) 7 8 func TestBTFKind_String(t *testing.T) { 9 for i := BTFKind(0); i < btfKindMax; i++ { 10 if i.String() == "" { 11 t.Fatalf("missing string translation for BPFKind %d", i) 12 } 13 } 14 } 15 16 func TestStringTbl_ParseSerializeSymmetry(t *testing.T) { 17 type fields struct { 18 Blob []byte 19 } 20 tests := []struct { 21 name string 22 fields fields 23 }{ 24 { 25 name: "happy path", 26 fields: fields{ 27 Blob: []byte("\x00abc\x00def\x00ghi\x00"), 28 }, 29 }, 30 { 31 name: "no elements", 32 fields: fields{ 33 Blob: []byte(""), 34 }, 35 }, 36 { 37 name: "nil elem", 38 fields: fields{ 39 Blob: []byte("\x00"), 40 }, 41 }, 42 } 43 for _, tt := range tests { 44 t.Run(tt.name, func(t *testing.T) { 45 cp := make([]byte, len(tt.fields.Blob)) 46 copy(cp, tt.fields.Blob) 47 48 st := StringTblFromBlob(tt.fields.Blob) 49 st.Serialize() 50 51 if !bytes.Equal(cp, st.btfStringBlob) { 52 t.Fail() 53 } 54 }) 55 } 56 }