@@ -628,9 +628,9 @@ class PostgresConnectionTests: XCTestCase {
628628
629629 try await withThrowingTaskGroup ( of: Void . self) { taskGroup async throws -> ( ) in
630630 taskGroup. addTask {
631- try await connection. copyFrom ( " COPY copy_table FROM STDIN " , writeData : { writer in
631+ try await connection. copyFrom ( table : " copy_table " , logger : . psqlTest ) { writer in
632632 try await writer. write ( ByteBuffer ( staticString: " 1 \t Alice \n " ) )
633- } , logger : . psqlTest )
633+ }
634634 }
635635
636636 let copyMessage = try await channel. waitForUnpreparedRequest ( )
@@ -656,9 +656,9 @@ class PostgresConnectionTests: XCTestCase {
656656 try await withThrowingTaskGroup ( of: Void . self) { taskGroup async throws -> ( ) in
657657 taskGroup. addTask {
658658 await assertThrowsError (
659- try await connection. copyFrom ( " COPY copy_table FROM STDIN " , writeData : { writer in
659+ try await connection. copyFrom ( table : " copy_table " , logger : . psqlTest ) { writer in
660660 throw MyError ( )
661- } , logger : . psqlTest )
661+ }
662662 ) { error in
663663 XCTAssert ( error is MyError , " Expected error of type MyError, got \( error) " )
664664 }
@@ -691,9 +691,9 @@ class PostgresConnectionTests: XCTestCase {
691691 try await withThrowingTaskGroup ( of: Void . self) { taskGroup async throws -> ( ) in
692692 taskGroup. addTask {
693693 await assertThrowsError (
694- try await connection. copyFrom ( " COPY copy_table FROM STDIN " , writeData : { writer in
694+ try await connection. copyFrom ( table : " copy_table " , logger : . psqlTest ) { writer in
695695 try await writer. write ( ByteBuffer ( staticString: " 1Alice \n " ) )
696- } , logger : . psqlTest )
696+ }
697697 ) { error in
698698 XCTAssertEqual ( ( error as? PSQLError ) ? . serverInfo? . underlying. fields [ . sqlState] , " 22P02 " )
699699 }
@@ -724,11 +724,11 @@ class PostgresConnectionTests: XCTestCase {
724724 try await withThrowingTaskGroup ( of: Void . self) { taskGroup async throws -> ( ) in
725725 taskGroup. addTask {
726726 await assertThrowsError (
727- try await connection. copyFrom ( " COPY copy_table FROM STDIN " , writeData : { writer in
727+ try await connection. copyFrom ( table : " copy_table " , logger : . psqlTest ) { writer in
728728 try await writer. write ( ByteBuffer ( staticString: " 1Alice \n " ) )
729729 channel. flush ( )
730730 _ = await XCTWaiter . fulfillment ( of: [ backendDidSendErrorExpectation] )
731- } , logger : . psqlTest )
731+ }
732732 ) { error in
733733 XCTAssertEqual ( ( error as? PSQLError ) ? . serverInfo? . underlying. fields [ . sqlState] , " 22P02 " )
734734 }
@@ -764,7 +764,7 @@ class PostgresConnectionTests: XCTestCase {
764764 try await withThrowingTaskGroup ( of: Void . self) { taskGroup async throws -> ( ) in
765765 taskGroup. addTask {
766766 await assertThrowsError (
767- try await connection. copyFrom ( " COPY copy_table FROM STDIN " , writeData : { writer in
767+ try await connection. copyFrom ( table : " copy_table " , logger : . psqlTest ) { writer in
768768 try await writer. write ( ByteBuffer ( staticString: " 1Alice \n " ) )
769769 channel. flush ( )
770770 _ = await XCTWaiter . fulfillment ( of: [ expectation] )
@@ -775,7 +775,7 @@ class PostgresConnectionTests: XCTestCase {
775775 XCTAssert ( error is PostgresCopyFromWriter . CopyCancellationError , " Received unexpected error: \( error) " )
776776 throw error
777777 }
778- } , logger : . psqlTest )
778+ }
779779 ) { error in
780780 XCTAssertEqual ( ( error as? PSQLError ) ? . serverInfo? . underlying. fields [ . sqlState] , " 22P02 " )
781781 }
@@ -803,6 +803,29 @@ class PostgresConnectionTests: XCTestCase {
803803 }
804804 }
805805
806+ func testCopyDataWithOptions( ) async throws {
807+ let ( connection, channel) = try await self . makeTestConnectionWithAsyncTestingChannel ( )
808+
809+ try await withThrowingTaskGroup ( of: Void . self) { taskGroup async throws -> ( ) in
810+ taskGroup. addTask {
811+ try await connection. copyFrom ( table: " copy_table " , columns: [ " id " , " name " ] , options: CopyFromOptions ( delimiter: " , " ) , logger: . psqlTest) { writer in
812+ try await writer. write ( ByteBuffer ( staticString: " 1,Alice \n " ) )
813+ }
814+ }
815+
816+ let copyMessage = try await channel. waitForUnpreparedRequest ( )
817+ XCTAssertEqual ( copyMessage. parse. query, " COPY copy_table(id,name) FROM STDIN WITH (DELIMITER ',') " )
818+ XCTAssertEqual ( copyMessage. bind. parameters, [ ] )
819+ try await channel. sendUnpreparedRequestWithNoParametersBindResponse ( )
820+ try await channel. sendCopyInResponseForTwoTextualColumns ( )
821+ let data = try await channel. waitForCopyData ( )
822+ XCTAssertEqual ( String ( buffer: data. data) , " 1,Alice \n " )
823+ XCTAssertEqual ( data. result, . done)
824+ try await channel. writeInbound ( PostgresBackendMessage . commandComplete ( " COPY 1 " ) )
825+ try await channel. writeInbound ( PostgresBackendMessage . readyForQuery ( . idle) )
826+ }
827+ }
828+
806829 func makeTestConnectionWithAsyncTestingChannel( ) async throws -> ( PostgresConnection , NIOAsyncTestingChannel ) {
807830 let eventLoop = NIOAsyncTestingEventLoop ( )
808831 let channel = try await NIOAsyncTestingChannel ( loop: eventLoop) { channel in
0 commit comments