github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/util/reflection/reflection_test.go (about) 1 package reflection 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "testing" 6 ) 7 8 func TestStructName(t *testing.T) { 9 tests := []struct { 10 name string 11 subject any 12 expected string 13 }{ 14 { 15 name: "handles-pointers", 16 subject: &foo{}, 17 expected: "pkg/util/reflection.foo", 18 }, 19 { 20 name: "handles-bare", 21 subject: foo{}, 22 expected: "pkg/util/reflection.foo", 23 }, 24 { 25 name: "ignore-non-bacalhau-prefix", 26 subject: assert.New(t), 27 expected: "github.com/stretchr/testify/assert.Assertions", 28 }, 29 { 30 name: "does-not-crash-with-non-structs", 31 subject: 123, 32 expected: "int", 33 }, 34 } 35 36 for _, test := range tests { 37 t.Run(test.name, func(t *testing.T) { 38 actual := StructName(test.subject) 39 assert.Equal(t, test.expected, actual) 40 }) 41 } 42 } 43 44 type foo struct { 45 }