@@ -639,7 +639,7 @@ func (mock *copyTablesMock) CopyTables(
639639 return nil , fmt .Errorf ("%w: %s, exp: %s" , errUnexpectedRequest , in , mock .String ())
640640}
641641
642- func Test_copyTables (t * testing.T ) {
642+ func TestCopyTables (t * testing.T ) {
643643 ctx := xtest .Context (t )
644644 for _ , tt := range []struct {
645645 sessionID string
@@ -758,3 +758,137 @@ func Test_copyTables(t *testing.T) {
758758 })
759759 }
760760}
761+
762+ type renameTablesMock struct {
763+ * Ydb_Table.RenameTablesRequest
764+ }
765+
766+ func (mock * renameTablesMock ) RenameTables (
767+ _ context.Context , in * Ydb_Table.RenameTablesRequest , opts ... grpc.CallOption ,
768+ ) (* Ydb_Table.RenameTablesResponse , error ) {
769+ if in .String () == mock .String () {
770+ return & Ydb_Table.RenameTablesResponse {}, nil
771+ }
772+
773+ return nil , fmt .Errorf ("%w: %s, exp: %s" , errUnexpectedRequest , in , mock .String ())
774+ }
775+
776+ func TestRenameTables (t * testing.T ) {
777+ ctx := xtest .Context (t )
778+ for _ , tt := range []struct {
779+ sessionID string
780+ operationTimeout time.Duration
781+ operationCancelAfter time.Duration
782+ service * renameTablesMock
783+ opts []options.RenameTablesOption
784+ err error
785+ }{
786+ {
787+ sessionID : "1" ,
788+ operationTimeout : time .Second ,
789+ operationCancelAfter : time .Second ,
790+ service : & renameTablesMock {
791+ RenameTablesRequest : & Ydb_Table.RenameTablesRequest {
792+ SessionId : "1" ,
793+ Tables : []* Ydb_Table.RenameTableItem {
794+ {
795+ SourcePath : "from" ,
796+ DestinationPath : "to" ,
797+ ReplaceDestination : true ,
798+ },
799+ },
800+ OperationParams : & Ydb_Operations.OperationParams {
801+ OperationMode : Ydb_Operations .OperationParams_SYNC ,
802+ OperationTimeout : durationpb .New (time .Second ),
803+ CancelAfter : durationpb .New (time .Second ),
804+ },
805+ },
806+ },
807+ opts : []options.RenameTablesOption {
808+ options .RenameTablesItem ("from" , "to" , true ),
809+ },
810+ err : nil ,
811+ },
812+ {
813+ sessionID : "2" ,
814+ operationTimeout : 2 * time .Second ,
815+ operationCancelAfter : 2 * time .Second ,
816+ service : & renameTablesMock {
817+ RenameTablesRequest : & Ydb_Table.RenameTablesRequest {
818+ SessionId : "2" ,
819+ Tables : []* Ydb_Table.RenameTableItem {
820+ {
821+ SourcePath : "from1" ,
822+ DestinationPath : "to1" ,
823+ ReplaceDestination : true ,
824+ },
825+ {
826+ SourcePath : "from2" ,
827+ DestinationPath : "to2" ,
828+ ReplaceDestination : false ,
829+ },
830+ {
831+ SourcePath : "from3" ,
832+ DestinationPath : "to3" ,
833+ ReplaceDestination : true ,
834+ },
835+ },
836+ OperationParams : & Ydb_Operations.OperationParams {
837+ OperationMode : Ydb_Operations .OperationParams_SYNC ,
838+ OperationTimeout : durationpb .New (2 * time .Second ),
839+ CancelAfter : durationpb .New (2 * time .Second ),
840+ },
841+ },
842+ },
843+ opts : []options.RenameTablesOption {
844+ options .RenameTablesItem ("from1" , "to1" , true ),
845+ options .RenameTablesItem ("from2" , "to2" , false ),
846+ options .RenameTablesItem ("from3" , "to3" , true ),
847+ },
848+ err : nil ,
849+ },
850+ {
851+ sessionID : "3" ,
852+ operationTimeout : time .Second ,
853+ operationCancelAfter : time .Second ,
854+ service : & renameTablesMock {
855+ RenameTablesRequest : & Ydb_Table.RenameTablesRequest {
856+ SessionId : "1" ,
857+ Tables : []* Ydb_Table.RenameTableItem {
858+ {
859+ SourcePath : "from" ,
860+ DestinationPath : "to" ,
861+ ReplaceDestination : true ,
862+ },
863+ },
864+ OperationParams : & Ydb_Operations.OperationParams {
865+ OperationMode : Ydb_Operations .OperationParams_SYNC ,
866+ OperationTimeout : durationpb .New (time .Second ),
867+ CancelAfter : durationpb .New (time .Second ),
868+ },
869+ },
870+ },
871+ opts : []options.RenameTablesOption {
872+ options .RenameTablesItem ("from1" , "to1" , true ),
873+ },
874+ err : errUnexpectedRequest ,
875+ },
876+ {
877+ sessionID : "4" ,
878+ operationTimeout : time .Second ,
879+ operationCancelAfter : time .Second ,
880+ service : & renameTablesMock {},
881+ opts : nil ,
882+ err : errParamsRequired ,
883+ },
884+ } {
885+ t .Run ("" , func (t * testing.T ) {
886+ err := renameTables (ctx , tt .sessionID , tt .operationTimeout , tt .operationCancelAfter , tt .service , tt .opts ... )
887+ if tt .err != nil {
888+ require .ErrorIs (t , err , tt .err )
889+ } else {
890+ require .NoError (t , err )
891+ }
892+ })
893+ }
894+ }
0 commit comments