@@ -4,7 +4,6 @@ if(helper.args.native) {
4
4
pg = require ( __dirname + '/../../../lib' ) . native ;
5
5
}
6
6
var ROWS_TO_INSERT = 1000 ;
7
-
8
7
var prepareTable = function ( client , callback ) {
9
8
client . query (
10
9
'CREATE TEMP TABLE copy_test (id SERIAL, name CHARACTER VARYING(10), age INT)' ,
@@ -14,9 +13,8 @@ var prepareTable = function (client, callback) {
14
13
} )
15
14
) ;
16
15
} ;
17
-
18
16
test ( 'COPY FROM' , function ( ) {
19
- pg . connect ( helper . config , assert . calls ( function ( error , client ) {
17
+ pg . connect ( helper . config , function ( error , client ) {
20
18
assert . equal ( error , null , "Failed to connect: " + helper . sys . inspect ( error ) ) ;
21
19
prepareTable ( client , function ( ) {
22
20
var stream = client . copyFrom ( "COPY copy_test (name, age) FROM stdin WITH CSV" ) ;
@@ -27,21 +25,20 @@ test('COPY FROM', function () {
27
25
stream . write ( String ( Date . now ( ) + Math . random ( ) ) . slice ( 0 , 10 ) + ',' + i + '\n' ) ;
28
26
}
29
27
assert . emits ( stream , 'close' , function ( ) {
30
- client . query ( "SELECT count(*), sum(age) from copy_test" , assert . calls ( function ( err , result ) {
28
+ client . query ( "SELECT count(*), sum(age) from copy_test" , function ( err , result ) {
31
29
assert . equal ( err , null , "Query should not fail" ) ;
32
30
assert . lengthIs ( result . rows , 1 )
33
31
assert . equal ( result . rows [ 0 ] . sum , ROWS_TO_INSERT * ( 0 + ROWS_TO_INSERT - 1 ) / 2 ) ;
34
32
assert . equal ( result . rows [ 0 ] . count , ROWS_TO_INSERT ) ;
35
33
pg . end ( helper . config ) ;
36
- } ) ) ;
34
+ } ) ;
37
35
} , "COPY FROM stream should emit close after query end" ) ;
38
36
stream . end ( ) ;
39
37
} ) ;
40
- } ) ) ;
38
+ } ) ;
41
39
} ) ;
42
-
43
40
test ( 'COPY TO' , function ( ) {
44
- pg . connect ( helper . config , assert . calls ( function ( error , client ) {
41
+ pg . connect ( helper . config , function ( error , client ) {
45
42
assert . equal ( error , null , "Failed to connect: " + helper . sys . inspect ( error ) ) ;
46
43
prepareTable ( client , function ( ) {
47
44
var stream = client . copyTo ( "COPY person (id, name, age) TO stdin WITH CSV" ) ;
@@ -59,10 +56,11 @@ test('COPY TO', function () {
59
56
pg . end ( helper . config ) ;
60
57
} , "COPY IN stream should emit end event after all rows" ) ;
61
58
} ) ;
62
- } ) ) ;
59
+ } ) ;
63
60
} ) ;
64
61
65
62
test ( 'COPY TO, queue queries' , function ( ) {
63
+ if ( helper . config . native ) return false ;
66
64
pg . connect ( helper . config , assert . calls ( function ( error , client ) {
67
65
assert . equal ( error , null , "Failed to connect: " + helper . sys . inspect ( error ) ) ;
68
66
prepareTable ( client , function ( ) {
@@ -77,10 +75,10 @@ test('COPY TO, queue queries', function () {
77
75
//imitate long query, to make impossible,
78
76
//that copy query end callback runs after
79
77
//second query callback
80
- client . query ( "SELECT pg_sleep(1)" , assert . calls ( function ( ) {
78
+ client . query ( "SELECT pg_sleep(1)" , function ( ) {
81
79
query2Done = true ;
82
80
assert . ok ( copyQueryDone && query2Done , "second query has to be executed after others" ) ;
83
- } ) ) ;
81
+ } ) ;
84
82
var buf = new Buffer ( 0 ) ;
85
83
stream . on ( 'error' , function ( error ) {
86
84
assert . ok ( false , "COPY TO stream should not emit errors" + helper . sys . inspect ( error ) ) ;
@@ -101,6 +99,7 @@ test('COPY TO, queue queries', function () {
101
99
} ) ;
102
100
103
101
test ( "COPY TO incorrect usage with large data" , function ( ) {
102
+ if ( helper . config . native ) return false ;
104
103
//when many data is loaded from database (and it takes a lot of time)
105
104
//there are chance, that query will be canceled before it ends
106
105
//but if there are not so much data, cancel message may be
@@ -125,6 +124,7 @@ test("COPY TO incorrect usage with large data", function () {
125
124
} ) ;
126
125
127
126
test ( "COPY TO incorrect usage with small data" , function ( ) {
127
+ if ( helper . config . native ) return false ;
128
128
pg . connect ( helper . config , assert . calls ( function ( error , client ) {
129
129
assert . equal ( error , null , "Failed to connect: " + helper . sys . inspect ( error ) ) ;
130
130
//intentionally incorrect usage of copy.
@@ -144,7 +144,7 @@ test("COPY TO incorrect usage with small data", function () {
144
144
} ) ;
145
145
146
146
test ( "COPY FROM incorrect usage" , function ( ) {
147
- pg . connect ( helper . config , assert . calls ( function ( error , client ) {
147
+ pg . connect ( helper . config , function ( error , client ) {
148
148
assert . equal ( error , null , "Failed to connect: " + helper . sys . inspect ( error ) ) ;
149
149
prepareTable ( client , function ( ) {
150
150
//intentionally incorrect usage of copy.
@@ -161,6 +161,6 @@ test("COPY FROM incorrect usage", function () {
161
161
} )
162
162
) ;
163
163
} ) ;
164
- } ) ) ;
164
+ } ) ;
165
165
} ) ;
166
166
0 commit comments