@@ -874,7 +874,7 @@ func TestConn_QueryContext(t *testing.T) {
874874 client : testClient ,
875875 cfg : config .WithDefaults (),
876876 }
877- res , err := testConn .ExecContext (context .Background (), "select 1" , []driver.NamedValue {
877+ res , err := testConn .QueryContext (context .Background (), "select 1" , []driver.NamedValue {
878878 {Value : 1 , Name : "name" },
879879 })
880880
@@ -909,7 +909,7 @@ func TestConn_QueryContext(t *testing.T) {
909909 client : testClient ,
910910 cfg : config .WithDefaults (),
911911 }
912- res , err := testConn .ExecContext (context .Background (), "select 1" , []driver.NamedValue {})
912+ res , err := testConn .QueryContext (context .Background (), "select 1" , []driver.NamedValue {})
913913
914914 assert .Error (t , err )
915915 assert .Nil (t , res )
@@ -960,6 +960,121 @@ func TestConn_QueryContext(t *testing.T) {
960960 })
961961}
962962
963+ func TestConn_Ping (t * testing.T ) {
964+ t .Run ("ping returns ErrBadConn when executeStatement fails" , func (t * testing.T ) {
965+ var executeStatementCount int
966+ executeStatement := func (ctx context.Context , req * cli_service.TExecuteStatementReq ) (r * cli_service.TExecuteStatementResp , err error ) {
967+ executeStatementCount ++
968+ executeStatementResp := & cli_service.TExecuteStatementResp {
969+ Status : & cli_service.TStatus {
970+ StatusCode : cli_service .TStatusCode_ERROR_STATUS ,
971+ },
972+ OperationHandle : & cli_service.TOperationHandle {
973+ OperationId : & cli_service.THandleIdentifier {
974+ GUID : []byte ("2" ),
975+ Secret : []byte ("b" ),
976+ },
977+ },
978+ }
979+ return executeStatementResp , nil
980+ }
981+
982+ testClient := & client.TestClient {
983+ FnExecuteStatement : executeStatement ,
984+ }
985+ testConn := & conn {
986+ session : getTestSession (),
987+ client : testClient ,
988+ cfg : config .WithDefaults (),
989+ }
990+ err := testConn .Ping (context .Background ())
991+
992+ assert .Error (t , err )
993+ assert .Equal (t , driver .ErrBadConn , err )
994+ assert .Equal (t , 1 , executeStatementCount )
995+ })
996+
997+ t .Run ("ping returns nil error when driver can establish connection" , func (t * testing.T ) {
998+ var executeStatementCount int
999+ executeStatement := func (ctx context.Context , req * cli_service.TExecuteStatementReq ) (r * cli_service.TExecuteStatementResp , err error ) {
1000+ executeStatementCount ++
1001+ executeStatementResp := & cli_service.TExecuteStatementResp {
1002+ Status : & cli_service.TStatus {
1003+ StatusCode : cli_service .TStatusCode_SUCCESS_STATUS ,
1004+ },
1005+ OperationHandle : & cli_service.TOperationHandle {
1006+ OperationId : & cli_service.THandleIdentifier {
1007+ GUID : []byte ("2" ),
1008+ Secret : []byte ("b" ),
1009+ },
1010+ },
1011+ }
1012+ return executeStatementResp , nil
1013+ }
1014+
1015+ getOperationStatus := func (ctx context.Context , req * cli_service.TGetOperationStatusReq ) (r * cli_service.TGetOperationStatusResp , err error ) {
1016+ getOperationStatusResp := & cli_service.TGetOperationStatusResp {
1017+ OperationState : cli_service .TOperationStatePtr (cli_service .TOperationState_FINISHED_STATE ),
1018+ NumModifiedRows : thrift .Int64Ptr (10 ),
1019+ }
1020+ return getOperationStatusResp , nil
1021+ }
1022+
1023+ testClient := & client.TestClient {
1024+ FnExecuteStatement : executeStatement ,
1025+ FnGetOperationStatus : getOperationStatus ,
1026+ }
1027+
1028+ testConn := & conn {
1029+ session : getTestSession (),
1030+ client : testClient ,
1031+ cfg : config .WithDefaults (),
1032+ }
1033+ err := testConn .Ping (context .Background ())
1034+
1035+ assert .Nil (t , err )
1036+ assert .Equal (t , 1 , executeStatementCount )
1037+ })
1038+ }
1039+
1040+ func TestConn_Begin (t * testing.T ) {
1041+ t .Run ("Begin not supported" , func (t * testing.T ) {
1042+ testConn := & conn {
1043+ session : getTestSession (),
1044+ client : & client.TestClient {},
1045+ cfg : config .WithDefaults (),
1046+ }
1047+ res , err := testConn .Begin ()
1048+ assert .Nil (t , res )
1049+ assert .Error (t , err )
1050+ })
1051+ }
1052+
1053+ func TestConn_BeginTx (t * testing.T ) {
1054+ t .Run ("BeginTx not supported" , func (t * testing.T ) {
1055+ testConn := & conn {
1056+ session : getTestSession (),
1057+ client : & client.TestClient {},
1058+ cfg : config .WithDefaults (),
1059+ }
1060+ res , err := testConn .BeginTx (context .Background (), driver.TxOptions {})
1061+ assert .Nil (t , res )
1062+ assert .Error (t , err )
1063+ })
1064+ }
1065+
1066+ func TestConn_ResetSession (t * testing.T ) {
1067+ t .Run ("ResetSession not currently supported" , func (t * testing.T ) {
1068+ testConn := & conn {
1069+ session : getTestSession (),
1070+ client : & client.TestClient {},
1071+ cfg : config .WithDefaults (),
1072+ }
1073+ res := testConn .ResetSession (context .Background ())
1074+ assert .Nil (t , res )
1075+ })
1076+ }
1077+
9631078func getTestSession () * cli_service.TOpenSessionResp {
9641079 return & cli_service.TOpenSessionResp {SessionHandle : & cli_service.TSessionHandle {
9651080 SessionId : & cli_service.THandleIdentifier {
0 commit comments