@@ -2,6 +2,7 @@ package table
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "reflect"
78 "testing"
@@ -14,13 +15,16 @@ import (
1415 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Operations"
1516 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Scheme"
1617 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Table"
18+ "google.golang.org/grpc"
1719 "google.golang.org/protobuf/proto"
20+ "google.golang.org/protobuf/types/known/durationpb"
1821
1922 "github.com/ydb-platform/ydb-go-sdk/v3/internal/allocator"
2023 "github.com/ydb-platform/ydb-go-sdk/v3/internal/operation"
2124 "github.com/ydb-platform/ydb-go-sdk/v3/internal/table/config"
2225 "github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
2326 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
27+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
2428 "github.com/ydb-platform/ydb-go-sdk/v3/table"
2529 "github.com/ydb-platform/ydb-go-sdk/v3/table/options"
2630 "github.com/ydb-platform/ydb-go-sdk/v3/table/types"
@@ -624,3 +628,138 @@ func TestDescribeTableRegression(t *testing.T) {
624628
625629 assert .Equal (t , exp , act )
626630}
631+
632+ var errUnexpectedRequest = errors .New ("unexpected request" )
633+
634+ type copyTablesMock struct {
635+ * Ydb_Table.CopyTablesRequest
636+ }
637+
638+ func (mock * copyTablesMock ) CopyTables (
639+ _ context.Context , in * Ydb_Table.CopyTablesRequest , opts ... grpc.CallOption ,
640+ ) (* Ydb_Table.CopyTablesResponse , error ) {
641+ if in .String () == mock .String () {
642+ return & Ydb_Table.CopyTablesResponse {}, nil
643+ }
644+ return nil , fmt .Errorf ("%w: %s, exp: %s" , errUnexpectedRequest , in , mock .String ())
645+ }
646+
647+ func Test_copyTables (t * testing.T ) {
648+ ctx := xtest .Context (t )
649+ for _ , tt := range []struct {
650+ sessionID string
651+ operationTimeout time.Duration
652+ operationCancelAfter time.Duration
653+ service * copyTablesMock
654+ opts []options.CopyTablesOption
655+ err error
656+ }{
657+ {
658+ sessionID : "1" ,
659+ operationTimeout : time .Second ,
660+ operationCancelAfter : time .Second ,
661+ service : & copyTablesMock {
662+ CopyTablesRequest : & Ydb_Table.CopyTablesRequest {
663+ SessionId : "1" ,
664+ Tables : []* Ydb_Table.CopyTableItem {
665+ {
666+ SourcePath : "from" ,
667+ DestinationPath : "to" ,
668+ OmitIndexes : true ,
669+ },
670+ },
671+ OperationParams : & Ydb_Operations.OperationParams {
672+ OperationMode : Ydb_Operations .OperationParams_SYNC ,
673+ OperationTimeout : durationpb .New (time .Second ),
674+ CancelAfter : durationpb .New (time .Second ),
675+ },
676+ },
677+ },
678+ opts : []options.CopyTablesOption {
679+ options .CopyTablesItem ("from" , "to" , true ),
680+ },
681+ err : nil ,
682+ },
683+ {
684+ sessionID : "2" ,
685+ operationTimeout : 2 * time .Second ,
686+ operationCancelAfter : 2 * time .Second ,
687+ service : & copyTablesMock {
688+ CopyTablesRequest : & Ydb_Table.CopyTablesRequest {
689+ SessionId : "2" ,
690+ Tables : []* Ydb_Table.CopyTableItem {
691+ {
692+ SourcePath : "from1" ,
693+ DestinationPath : "to1" ,
694+ OmitIndexes : true ,
695+ },
696+ {
697+ SourcePath : "from2" ,
698+ DestinationPath : "to2" ,
699+ OmitIndexes : false ,
700+ },
701+ {
702+ SourcePath : "from3" ,
703+ DestinationPath : "to3" ,
704+ OmitIndexes : true ,
705+ },
706+ },
707+ OperationParams : & Ydb_Operations.OperationParams {
708+ OperationMode : Ydb_Operations .OperationParams_SYNC ,
709+ OperationTimeout : durationpb .New (2 * time .Second ),
710+ CancelAfter : durationpb .New (2 * time .Second ),
711+ },
712+ },
713+ },
714+ opts : []options.CopyTablesOption {
715+ options .CopyTablesItem ("from1" , "to1" , true ),
716+ options .CopyTablesItem ("from2" , "to2" , false ),
717+ options .CopyTablesItem ("from3" , "to3" , true ),
718+ },
719+ err : nil ,
720+ },
721+ {
722+ sessionID : "3" ,
723+ operationTimeout : time .Second ,
724+ operationCancelAfter : time .Second ,
725+ service : & copyTablesMock {
726+ CopyTablesRequest : & Ydb_Table.CopyTablesRequest {
727+ SessionId : "1" ,
728+ Tables : []* Ydb_Table.CopyTableItem {
729+ {
730+ SourcePath : "from" ,
731+ DestinationPath : "to" ,
732+ OmitIndexes : true ,
733+ },
734+ },
735+ OperationParams : & Ydb_Operations.OperationParams {
736+ OperationMode : Ydb_Operations .OperationParams_SYNC ,
737+ OperationTimeout : durationpb .New (time .Second ),
738+ CancelAfter : durationpb .New (time .Second ),
739+ },
740+ },
741+ },
742+ opts : []options.CopyTablesOption {
743+ options .CopyTablesItem ("from1" , "to1" , true ),
744+ },
745+ err : errUnexpectedRequest ,
746+ },
747+ {
748+ sessionID : "4" ,
749+ operationTimeout : time .Second ,
750+ operationCancelAfter : time .Second ,
751+ service : & copyTablesMock {},
752+ opts : nil ,
753+ err : errParamsRequired ,
754+ },
755+ } {
756+ t .Run ("" , func (t * testing.T ) {
757+ err := copyTables (ctx , tt .sessionID , tt .operationTimeout , tt .operationCancelAfter , tt .service , tt .opts ... )
758+ if tt .err != nil {
759+ require .ErrorIs (t , err , tt .err )
760+ } else {
761+ require .NoError (t , err )
762+ }
763+ })
764+ }
765+ }
0 commit comments