github.com/ydb-platform/ydb-go-sdk/v3@v3.89.2/internal/stack/function_id_test.go (about) 1 package stack 2 3 import ( 4 "sync" 5 "testing" 6 "time" 7 8 "github.com/stretchr/testify/require" 9 ) 10 11 type genericType[T any] struct{} 12 13 type starType struct{} 14 15 func (t genericType[T]) Call() string { 16 return FunctionID("").FunctionID() 17 } 18 19 func staticCall() string { 20 return FunctionID("").FunctionID() 21 } 22 23 func (e *starType) starredCall() string { 24 return FunctionID("").FunctionID() 25 } 26 27 func anonymousFunctionCall() string { 28 var result string 29 var mu sync.Mutex 30 go func() { 31 mu.Lock() 32 defer mu.Unlock() 33 result = FunctionID("").FunctionID() 34 }() 35 time.Sleep(time.Second) 36 37 mu.Lock() 38 defer mu.Unlock() 39 40 return result 41 } 42 43 func TestFunctionIDForGenericType(t *testing.T) { 44 t.Run("StaticFunc", func(t *testing.T) { 45 require.Equal(t, 46 "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack.staticCall", 47 staticCall(), 48 ) 49 }) 50 t.Run("GenericTypeCall", func(t *testing.T) { 51 require.Equal(t, 52 "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack.genericType.Call", 53 genericType[uint64]{}.Call(), 54 ) 55 }) 56 t.Run("StarTypeCall", func(t *testing.T) { 57 x := starType{} 58 require.Equal(t, 59 "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack.(*starType).starredCall", 60 x.starredCall(), 61 ) 62 }) 63 t.Run("AnonymousFunctionCall", func(t *testing.T) { 64 require.Equal(t, 65 "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack.anonymousFunctionCall", 66 anonymousFunctionCall(), 67 ) 68 }) 69 }