github.com/cilium/ebpf@v0.10.0/cmd/bpf2go/output_test.go (about) 1 package main 2 3 import ( 4 "testing" 5 6 "github.com/cilium/ebpf/btf" 7 qt "github.com/frankban/quicktest" 8 ) 9 10 func TestOrderTypes(t *testing.T) { 11 a := &btf.Int{} 12 b := &btf.Int{} 13 c := &btf.Int{} 14 15 for _, test := range []struct { 16 name string 17 in map[btf.Type]string 18 out []btf.Type 19 }{ 20 { 21 "order", 22 map[btf.Type]string{ 23 a: "foo", 24 b: "bar", 25 c: "baz", 26 }, 27 []btf.Type{b, c, a}, 28 }, 29 } { 30 t.Run(test.name, func(t *testing.T) { 31 result, err := sortTypes(test.in) 32 qt.Assert(t, err, qt.IsNil) 33 qt.Assert(t, len(result), qt.Equals, len(test.out)) 34 for i, o := range test.out { 35 if result[i] != o { 36 t.Fatalf("Index %d: expected %p got %p", i, o, result[i]) 37 } 38 } 39 }) 40 } 41 42 for _, test := range []struct { 43 name string 44 in map[btf.Type]string 45 }{ 46 { 47 "duplicate names", 48 map[btf.Type]string{ 49 a: "foo", 50 b: "foo", 51 }, 52 }, 53 } { 54 t.Run(test.name, func(t *testing.T) { 55 result, err := sortTypes(test.in) 56 qt.Assert(t, err, qt.IsNotNil) 57 qt.Assert(t, result, qt.IsNil) 58 }) 59 } 60 }