@@ -8,7 +8,8 @@ var prepareTable = function (client, callback) {
8
8
client . query (
9
9
'CREATE TEMP TABLE copy_test (id SERIAL, name CHARACTER VARYING(10), age INT)' ,
10
10
assert . calls ( function ( err , result ) {
11
- assert . equal ( err , null , "create table query should not fail" ) ;
11
+ assert . equal ( err , null ,
12
+ err && err . message ? "create table query should not fail: " + err . message : null ) ;
12
13
callback ( ) ;
13
14
} )
14
15
) ;
@@ -19,7 +20,7 @@ test('COPY FROM', function () {
19
20
prepareTable ( client , function ( ) {
20
21
var stream = client . copyFrom ( "COPY copy_test (name, age) FROM stdin WITH CSV" ) ;
21
22
stream . on ( 'error' , function ( error ) {
22
- assert . ok ( false , "COPY FROM stream should not emit errors" + helper . sys . inspect ( error ) ) ;
23
+ assert . ok ( false , "COPY FROM stream should not emit errors" + helper . sys . inspect ( error ) ) ;
23
24
} ) ;
24
25
for ( var i = 0 ; i < ROWS_TO_INSERT ; i ++ ) {
25
26
stream . write ( String ( Date . now ( ) + Math . random ( ) ) . slice ( 0 , 10 ) + ',' + i + '\n' ) ;
@@ -44,11 +45,11 @@ test('COPY TO', function () {
44
45
var stream = client . copyTo ( "COPY person (id, name, age) TO stdin WITH CSV" ) ;
45
46
var buf = new Buffer ( 0 ) ;
46
47
stream . on ( 'error' , function ( error ) {
47
- assert . ok ( false , "COPY TO stream should not emit errors" + helper . sys . inspect ( error ) ) ;
48
+ assert . ok ( false , "COPY TO stream should not emit errors" + helper . sys . inspect ( error ) ) ;
48
49
} ) ;
49
50
assert . emits ( stream , 'data' , function ( chunk ) {
50
- buf = Buffer . concat ( [ buf , chunk ] ) ;
51
- } , "COPY IN stream should emit data event for each row" ) ;
51
+ buf = Buffer . concat ( [ buf , chunk ] ) ;
52
+ } , "COPY IN stream should emit data event for each row" ) ;
52
53
assert . emits ( stream , 'end' , function ( ) {
53
54
var lines = buf . toString ( ) . split ( '\n' ) ;
54
55
assert . equal ( lines . length >= 0 , true , "copy in should return rows saved by copy from" ) ;
@@ -73,19 +74,19 @@ test('COPY TO, queue queries', function () {
73
74
} ) ;
74
75
var stream = client . copyTo ( "COPY person (id, name, age) TO stdin WITH CSV" ) ;
75
76
//imitate long query, to make impossible,
76
- //that copy query end callback runs after
77
+ //that copy query end callback runs after
77
78
//second query callback
78
79
client . query ( "SELECT pg_sleep(1)" , function ( ) {
79
80
query2Done = true ;
80
81
assert . ok ( copyQueryDone && query2Done , "second query has to be executed after others" ) ;
81
82
} ) ;
82
83
var buf = new Buffer ( 0 ) ;
83
84
stream . on ( 'error' , function ( error ) {
84
- assert . ok ( false , "COPY TO stream should not emit errors" + helper . sys . inspect ( error ) ) ;
85
+ assert . ok ( false , "COPY TO stream should not emit errors" + helper . sys . inspect ( error ) ) ;
85
86
} ) ;
86
87
assert . emits ( stream , 'data' , function ( chunk ) {
87
- buf = Buffer . concat ( [ buf , chunk ] ) ;
88
- } , "COPY IN stream should emit data event for each row" ) ;
88
+ buf = Buffer . concat ( [ buf , chunk ] ) ;
89
+ } , "COPY IN stream should emit data event for each row" ) ;
89
90
assert . emits ( stream , 'end' , function ( ) {
90
91
copyQueryDone = true ;
91
92
assert . ok ( query1Done && ! query2Done , "copy query has to be executed before second query and after first" ) ;
@@ -100,14 +101,14 @@ test('COPY TO, queue queries', function () {
100
101
101
102
test ( "COPY TO incorrect usage with large data" , function ( ) {
102
103
if ( helper . config . native ) return false ;
103
- //when many data is loaded from database (and it takes a lot of time)
104
+ //when many data is loaded from database (and it takes a lot of time)
104
105
//there are chance, that query will be canceled before it ends
105
- //but if there are not so much data, cancel message may be
106
+ //but if there are not so much data, cancel message may be
106
107
//send after copy query ends
107
108
//so we need to test both situations
108
109
pg . connect ( helper . config , assert . calls ( function ( error , client , done ) {
109
110
assert . equal ( error , null , "Failed to connect: " + helper . sys . inspect ( error ) ) ;
110
- //intentionally incorrect usage of copy.
111
+ //intentionally incorrect usage of copy.
111
112
//this has to report error in standart way, instead of just throwing exception
112
113
client . query (
113
114
"COPY (SELECT GENERATE_SERIES(1, 10000000)) TO STDOUT WITH CSV" ,
@@ -127,7 +128,7 @@ test("COPY TO incorrect usage with small data", function () {
127
128
if ( helper . config . native ) return false ;
128
129
pg . connect ( helper . config , assert . calls ( function ( error , client , done ) {
129
130
assert . equal ( error , null , "Failed to connect: " + helper . sys . inspect ( error ) ) ;
130
- //intentionally incorrect usage of copy.
131
+ //intentionally incorrect usage of copy.
131
132
//this has to report error in standart way, instead of just throwing exception
132
133
client . query (
133
134
"COPY (SELECT GENERATE_SERIES(1, 1)) TO STDOUT WITH CSV" ,
@@ -147,7 +148,7 @@ test("COPY FROM incorrect usage", function () {
147
148
pg . connect ( helper . config , function ( error , client , done ) {
148
149
assert . equal ( error , null , "Failed to connect: " + helper . sys . inspect ( error ) ) ;
149
150
prepareTable ( client , function ( ) {
150
- //intentionally incorrect usage of copy.
151
+ //intentionally incorrect usage of copy.
151
152
//this has to report error in standart way, instead of just throwing exception
152
153
client . query (
153
154
"COPY copy_test from STDIN WITH CSV" ,
@@ -157,7 +158,7 @@ test("COPY FROM incorrect usage", function () {
157
158
assert . isNull ( error , "incorrect copy usage should not break connection: " + error ) ;
158
159
assert . ok ( result , "incorrect copy usage should not break connection" ) ;
159
160
done ( ) ;
160
- pg . end ( helper . config ) ;
161
+ pg . end ( helper . config ) ;
161
162
} ) ) ;
162
163
} )
163
164
) ;
0 commit comments