@@ -628,9 +628,9 @@ class PostgresConnectionTests: XCTestCase {
628
628
629
629
try await withThrowingTaskGroup ( of: Void . self) { taskGroup async throws -> ( ) in
630
630
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
632
632
try await writer. write ( ByteBuffer ( staticString: " 1 \t Alice \n " ) )
633
- } , logger : . psqlTest )
633
+ }
634
634
}
635
635
636
636
let copyMessage = try await channel. waitForUnpreparedRequest ( )
@@ -656,9 +656,9 @@ class PostgresConnectionTests: XCTestCase {
656
656
try await withThrowingTaskGroup ( of: Void . self) { taskGroup async throws -> ( ) in
657
657
taskGroup. addTask {
658
658
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
660
660
throw MyError ( )
661
- } , logger : . psqlTest )
661
+ }
662
662
) { error in
663
663
XCTAssert ( error is MyError , " Expected error of type MyError, got \( error) " )
664
664
}
@@ -691,9 +691,9 @@ class PostgresConnectionTests: XCTestCase {
691
691
try await withThrowingTaskGroup ( of: Void . self) { taskGroup async throws -> ( ) in
692
692
taskGroup. addTask {
693
693
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
695
695
try await writer. write ( ByteBuffer ( staticString: " 1Alice \n " ) )
696
- } , logger : . psqlTest )
696
+ }
697
697
) { error in
698
698
XCTAssertEqual ( ( error as? PSQLError ) ? . serverInfo? . underlying. fields [ . sqlState] , " 22P02 " )
699
699
}
@@ -724,11 +724,11 @@ class PostgresConnectionTests: XCTestCase {
724
724
try await withThrowingTaskGroup ( of: Void . self) { taskGroup async throws -> ( ) in
725
725
taskGroup. addTask {
726
726
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
728
728
try await writer. write ( ByteBuffer ( staticString: " 1Alice \n " ) )
729
729
channel. flush ( )
730
730
_ = await XCTWaiter . fulfillment ( of: [ backendDidSendErrorExpectation] )
731
- } , logger : . psqlTest )
731
+ }
732
732
) { error in
733
733
XCTAssertEqual ( ( error as? PSQLError ) ? . serverInfo? . underlying. fields [ . sqlState] , " 22P02 " )
734
734
}
@@ -764,7 +764,7 @@ class PostgresConnectionTests: XCTestCase {
764
764
try await withThrowingTaskGroup ( of: Void . self) { taskGroup async throws -> ( ) in
765
765
taskGroup. addTask {
766
766
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
768
768
try await writer. write ( ByteBuffer ( staticString: " 1Alice \n " ) )
769
769
channel. flush ( )
770
770
_ = await XCTWaiter . fulfillment ( of: [ expectation] )
@@ -775,7 +775,7 @@ class PostgresConnectionTests: XCTestCase {
775
775
XCTAssert ( error is PostgresCopyFromWriter . CopyCancellationError , " Received unexpected error: \( error) " )
776
776
throw error
777
777
}
778
- } , logger : . psqlTest )
778
+ }
779
779
) { error in
780
780
XCTAssertEqual ( ( error as? PSQLError ) ? . serverInfo? . underlying. fields [ . sqlState] , " 22P02 " )
781
781
}
@@ -803,6 +803,29 @@ class PostgresConnectionTests: XCTestCase {
803
803
}
804
804
}
805
805
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
+
806
829
func makeTestConnectionWithAsyncTestingChannel( ) async throws -> ( PostgresConnection , NIOAsyncTestingChannel ) {
807
830
let eventLoop = NIOAsyncTestingEventLoop ( )
808
831
let channel = try await NIOAsyncTestingChannel ( loop: eventLoop) { channel in
0 commit comments