@@ -3,7 +3,6 @@ package query
33import (
44 "context"
55 "errors"
6- "io"
76 "testing"
87 "time"
98
@@ -257,237 +256,3 @@ func TestDoTx(t *testing.T) {
257256 require .Equal (t , 10 , counter )
258257 })
259258}
260-
261- func TestReadRow (t * testing.T ) {
262- ctx := xtest .Context (t )
263- t .Run ("HappyWay" , func (t * testing.T ) {
264- ctrl := gomock .NewController (t )
265- row , err := readRow (ctx , testPool (ctx , func (ctx context.Context ) (* Session , error ) {
266- stream := NewMockQueryService_ExecuteQueryClient (ctrl )
267- stream .EXPECT ().Recv ().Return (& Ydb_Query.ExecuteQueryResponsePart {
268- Status : Ydb .StatusIds_SUCCESS ,
269- TxMeta : & Ydb_Query.TransactionMeta {
270- Id : "456" ,
271- },
272- ResultSetIndex : 0 ,
273- ResultSet : & Ydb.ResultSet {
274- Columns : []* Ydb.Column {
275- {
276- Name : "a" ,
277- Type : & Ydb.Type {
278- Type : & Ydb.Type_TypeId {
279- TypeId : Ydb .Type_UINT64 ,
280- },
281- },
282- },
283- {
284- Name : "b" ,
285- Type : & Ydb.Type {
286- Type : & Ydb.Type_TypeId {
287- TypeId : Ydb .Type_UTF8 ,
288- },
289- },
290- },
291- },
292- Rows : []* Ydb.Value {
293- {
294- Items : []* Ydb.Value {{
295- Value : & Ydb.Value_Uint64Value {
296- Uint64Value : 1 ,
297- },
298- }, {
299- Value : & Ydb.Value_TextValue {
300- TextValue : "1" ,
301- },
302- }},
303- },
304- },
305- },
306- }, nil )
307- stream .EXPECT ().Recv ().Return (nil , io .EOF )
308- client := NewMockQueryServiceClient (ctrl )
309- client .EXPECT ().ExecuteQuery (gomock .Any (), gomock .Any ()).Return (stream , nil )
310-
311- return & Session {
312- id : "123" ,
313- statusCode : statusIdle ,
314- cfg : config .New (),
315- grpcClient : client ,
316- }, nil
317- }), "" , nil )
318- require .NoError (t , err )
319- var (
320- a uint64
321- b string
322- )
323- err = row .Scan (& a , & b )
324- require .NoError (t , err )
325- require .EqualValues (t , 1 , a )
326- require .EqualValues (t , "1" , b )
327- })
328- t .Run ("MoreThanOneRow" , func (t * testing.T ) {
329- ctrl := gomock .NewController (t )
330- row , err := readRow (ctx , testPool (ctx , func (ctx context.Context ) (* Session , error ) {
331- stream := NewMockQueryService_ExecuteQueryClient (ctrl )
332- stream .EXPECT ().Recv ().Return (& Ydb_Query.ExecuteQueryResponsePart {
333- Status : Ydb .StatusIds_SUCCESS ,
334- TxMeta : & Ydb_Query.TransactionMeta {
335- Id : "456" ,
336- },
337- ResultSetIndex : 0 ,
338- ResultSet : & Ydb.ResultSet {
339- Columns : []* Ydb.Column {
340- {
341- Name : "a" ,
342- Type : & Ydb.Type {
343- Type : & Ydb.Type_TypeId {
344- TypeId : Ydb .Type_UINT64 ,
345- },
346- },
347- },
348- {
349- Name : "b" ,
350- Type : & Ydb.Type {
351- Type : & Ydb.Type_TypeId {
352- TypeId : Ydb .Type_UTF8 ,
353- },
354- },
355- },
356- },
357- Rows : []* Ydb.Value {
358- {
359- Items : []* Ydb.Value {{
360- Value : & Ydb.Value_Uint64Value {
361- Uint64Value : 1 ,
362- },
363- }, {
364- Value : & Ydb.Value_TextValue {
365- TextValue : "1" ,
366- },
367- }},
368- },
369- {
370- Items : []* Ydb.Value {{
371- Value : & Ydb.Value_Uint64Value {
372- Uint64Value : 2 ,
373- },
374- }, {
375- Value : & Ydb.Value_TextValue {
376- TextValue : "2" ,
377- },
378- }},
379- },
380- },
381- },
382- }, nil )
383- client := NewMockQueryServiceClient (ctrl )
384- client .EXPECT ().ExecuteQuery (gomock .Any (), gomock .Any ()).Return (stream , nil )
385-
386- return & Session {
387- id : "123" ,
388- statusCode : statusIdle ,
389- cfg : config .New (),
390- grpcClient : client ,
391- }, nil
392- }), "" , nil )
393- require .ErrorIs (t , err , errMoreThanOneRow )
394- require .Nil (t , row )
395- })
396- t .Run ("MoreThanOneResultSet" , func (t * testing.T ) {
397- ctrl := gomock .NewController (t )
398- row , err := readRow (ctx , testPool (ctx , func (ctx context.Context ) (* Session , error ) {
399- stream := NewMockQueryService_ExecuteQueryClient (ctrl )
400- stream .EXPECT ().Recv ().Return (& Ydb_Query.ExecuteQueryResponsePart {
401- Status : Ydb .StatusIds_SUCCESS ,
402- TxMeta : & Ydb_Query.TransactionMeta {
403- Id : "456" ,
404- },
405- ResultSetIndex : 0 ,
406- ResultSet : & Ydb.ResultSet {
407- Columns : []* Ydb.Column {
408- {
409- Name : "a" ,
410- Type : & Ydb.Type {
411- Type : & Ydb.Type_TypeId {
412- TypeId : Ydb .Type_UINT64 ,
413- },
414- },
415- },
416- {
417- Name : "b" ,
418- Type : & Ydb.Type {
419- Type : & Ydb.Type_TypeId {
420- TypeId : Ydb .Type_UTF8 ,
421- },
422- },
423- },
424- },
425- Rows : []* Ydb.Value {
426- {
427- Items : []* Ydb.Value {{
428- Value : & Ydb.Value_Uint64Value {
429- Uint64Value : 1 ,
430- },
431- }, {
432- Value : & Ydb.Value_TextValue {
433- TextValue : "1" ,
434- },
435- }},
436- },
437- },
438- },
439- }, nil )
440- stream .EXPECT ().Recv ().Return (& Ydb_Query.ExecuteQueryResponsePart {
441- Status : Ydb .StatusIds_SUCCESS ,
442- TxMeta : & Ydb_Query.TransactionMeta {
443- Id : "456" ,
444- },
445- ResultSetIndex : 0 ,
446- ResultSet : & Ydb.ResultSet {
447- Columns : []* Ydb.Column {
448- {
449- Name : "a" ,
450- Type : & Ydb.Type {
451- Type : & Ydb.Type_TypeId {
452- TypeId : Ydb .Type_UINT64 ,
453- },
454- },
455- },
456- {
457- Name : "b" ,
458- Type : & Ydb.Type {
459- Type : & Ydb.Type_TypeId {
460- TypeId : Ydb .Type_UTF8 ,
461- },
462- },
463- },
464- },
465- Rows : []* Ydb.Value {
466- {
467- Items : []* Ydb.Value {{
468- Value : & Ydb.Value_Uint64Value {
469- Uint64Value : 1 ,
470- },
471- }, {
472- Value : & Ydb.Value_TextValue {
473- TextValue : "1" ,
474- },
475- }},
476- },
477- },
478- },
479- }, nil )
480- client := NewMockQueryServiceClient (ctrl )
481- client .EXPECT ().ExecuteQuery (gomock .Any (), gomock .Any ()).Return (stream , nil )
482-
483- return & Session {
484- id : "123" ,
485- statusCode : statusIdle ,
486- cfg : config .New (),
487- grpcClient : client ,
488- }, nil
489- }), "" , nil )
490- require .ErrorIs (t , err , errMoreThanOneRow )
491- require .Nil (t , row )
492- })
493- }
0 commit comments