github.com/ydb-platform/ydb-go-sdk/v3@v3.89.2/internal/xtest/call_method_test.go (about)

     1  package xtest
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestCallMethod(t *testing.T) {
    11  	object := bytes.NewBuffer(nil)
    12  
    13  	result := CallMethod(object, "WriteString", "Hello world!")
    14  	n := result[0].(int)
    15  	err := result[1]
    16  
    17  	require.Equal(t, 12, n)
    18  	require.Nil(t, err)
    19  
    20  	result = CallMethod(object, "String")
    21  
    22  	str, ok := result[0].(string)
    23  	require.True(t, ok)
    24  
    25  	require.Equal(t, object.String(), str)
    26  
    27  	require.Panics(t, func() {
    28  		CallMethod(object, "NonameMethod")
    29  	})
    30  
    31  	require.Panics(t, func() {
    32  		CallMethod(object, "String", "wrong", "arguments", "count")
    33  	})
    34  
    35  	require.Panics(t, func() {
    36  		// Wrong argument type.
    37  		CallMethod(object, "WriteString", 123)
    38  	})
    39  }