@@ -3,12 +3,117 @@ package tarantool_test
33import (
44 "testing"
55
6+ "github.com/stretchr/testify/assert"
7+ "github.com/stretchr/testify/mock"
68 "github.com/stretchr/testify/require"
79 "github.com/tarantool/go-iproto"
8-
910 . "github.com/tarantool/go-tarantool/v3"
1011)
1112
13+ // MockConnection - mock connection with Tarantool
14+ type MockConnection struct {
15+ mock.Mock
16+ }
17+
18+ func (m * MockConnection ) ProtocolInfo () ProtocolInfo {
19+ args := m .Called ()
20+ return args .Get (0 ).(ProtocolInfo )
21+ }
22+
23+ func (m * MockConnection ) Close () error {
24+ args := m .Called ()
25+ return args .Error (0 )
26+ }
27+
28+ func (m * MockConnection ) Addr () string {
29+ args := m .Called ()
30+ return args .String (0 )
31+ }
32+
33+ func TestProtocolFeaturesSyncAndInsertArrow_WithMocks11 (t * testing.T ) {
34+ // Creating mock connections
35+ mockConn := new (MockConnection )
36+
37+ // Configuring so that it returns ProtocolInfo with the necessary features
38+ expectedProtocolInfo := ProtocolInfo {
39+ Version : ProtocolVersion (6 ),
40+ Features : []iproto.Feature {
41+ iproto .IPROTO_FEATURE_STREAMS ,
42+ iproto .IPROTO_FEATURE_TRANSACTIONS ,
43+ iproto .IPROTO_FEATURE_ERROR_EXTENSION ,
44+ iproto .IPROTO_FEATURE_WATCHERS ,
45+ iproto .IPROTO_FEATURE_PAGINATION ,
46+ iproto .IPROTO_FEATURE_SPACE_AND_INDEX_NAMES ,
47+ iproto .IPROTO_FEATURE_WATCH_ONCE ,
48+ iproto .IPROTO_FEATURE_IS_SYNC ,
49+ iproto .IPROTO_FEATURE_INSERT_ARROW ,
50+ },
51+ }
52+
53+ // Setting expectations for the mock
54+ mockConn .On ("ProtocolInfo" ).Return (expectedProtocolInfo )
55+ mockConn .On ("Close" ).Return (nil )
56+ mockConn .On ("Addr" ).Return ("127.0.0.1:3013" )
57+
58+ // Performing the mock test
59+ protocolInfo := mockConn .ProtocolInfo ()
60+
61+ // Check that the features are present
62+ assert .Contains (t , protocolInfo .Features , iproto .IPROTO_FEATURE_IS_SYNC ,
63+ "IPROTO_FEATURE_IS_SYNC should be supported" )
64+ assert .Contains (t , protocolInfo .Features , iproto .IPROTO_FEATURE_INSERT_ARROW ,
65+ "IPROTO_FEATURE_INSERT_ARROW should be supported" )
66+
67+ mockConn .AssertCalled (t , "ProtocolInfo" )
68+ }
69+
70+ // Alternative version with testing via the interface
71+ func TestProtocolFeaturesInClientProtocolInfo (t * testing.T ) {
72+ /// Testing the global clientProtocolInfo from protocol.go
73+ // To do this, we need to either make it exportable or test it through a public API
74+
75+ // Creating an IdRequest with the current clientProtocolInfo
76+ req := NewIdRequest (ProtocolInfo {
77+ Version : ProtocolVersion (6 ),
78+ Features : []iproto.Feature {
79+ iproto .IPROTO_FEATURE_STREAMS ,
80+ iproto .IPROTO_FEATURE_TRANSACTIONS ,
81+ iproto .IPROTO_FEATURE_ERROR_EXTENSION ,
82+ iproto .IPROTO_FEATURE_WATCHERS ,
83+ iproto .IPROTO_FEATURE_PAGINATION ,
84+ iproto .IPROTO_FEATURE_SPACE_AND_INDEX_NAMES ,
85+ iproto .IPROTO_FEATURE_WATCH_ONCE ,
86+ iproto .IPROTO_FEATURE_IS_SYNC , // TESTING THIS
87+ iproto .IPROTO_FEATURE_INSERT_ARROW , // TESTING THIS
88+ },
89+ })
90+
91+ assert .NotNil (t , req )
92+ }
93+
94+ type MockMsgpackEncoder struct {
95+ mock.Mock
96+ }
97+
98+ func (m * MockMsgpackEncoder ) Encode (v interface {}) error {
99+ args := m .Called (v )
100+ return args .Error (0 )
101+ }
102+
103+ func (m * MockMsgpackEncoder ) EncodeMapLen (len int ) error {
104+ args := m .Called (len )
105+ return args .Error (0 )
106+ }
107+
108+ func (m * MockMsgpackEncoder ) EncodeUint (v uint64 ) error {
109+ args := m .Called (v )
110+ return args .Error (0 )
111+ }
112+
113+ func (m * MockMsgpackEncoder ) EncodeArrayLen (len int ) error {
114+ args := m .Called (len )
115+ return args .Error (0 )
116+ }
12117func TestProtocolInfoClonePreservesFeatures (t * testing.T ) {
13118 original := ProtocolInfo {
14119 Version : ProtocolVersion (100 ),
0 commit comments