@@ -6,7 +6,8 @@ use std::time::Duration;
6
6
use tokio_core:: reactor:: { Core , Interval } ;
7
7
8
8
use super :: * ;
9
- use error:: { Error , ConnectError , INVALID_PASSWORD , INVALID_AUTHORIZATION_SPECIFICATION , QUERY_CANCELED } ;
9
+ use error:: { Error , ConnectError , INVALID_PASSWORD , INVALID_AUTHORIZATION_SPECIFICATION ,
10
+ QUERY_CANCELED } ;
10
11
use params:: { ConnectParams , Host } ;
11
12
use types:: { ToSql , FromSql , Type , IsNull , Kind } ;
12
13
@@ -101,25 +102,31 @@ fn pass_user_wrong_pass() {
101
102
#[ test]
102
103
fn batch_execute_ok ( ) {
103
104
let mut l = Core :: new ( ) . unwrap ( ) ;
104
- let done = Connection :: connect ( "postgres://postgres@localhost:5433" , TlsMode :: None , & l. handle ( ) )
105
- . then ( |c| {
106
- c. unwrap ( ) . batch_execute (
107
- "CREATE TEMPORARY TABLE foo (id SERIAL);" ,
108
- )
109
- } ) ;
105
+ let done = Connection :: connect (
106
+ "postgres://postgres@localhost:5433" ,
107
+ TlsMode :: None ,
108
+ & l. handle ( ) ,
109
+ ) . then ( |c| {
110
+ c. unwrap ( ) . batch_execute (
111
+ "CREATE TEMPORARY TABLE foo (id SERIAL);" ,
112
+ )
113
+ } ) ;
110
114
l. run ( done) . unwrap ( ) ;
111
115
}
112
116
113
117
#[ test]
114
118
fn batch_execute_err ( ) {
115
119
let mut l = Core :: new ( ) . unwrap ( ) ;
116
- let done = Connection :: connect ( "postgres://postgres@localhost:5433" , TlsMode :: None , & l. handle ( ) )
117
- . then ( |r| {
118
- r. unwrap ( ) . batch_execute (
119
- "CREATE TEMPORARY TABLE foo (id SERIAL); INSERT INTO foo DEFAULT \
120
+ let done = Connection :: connect (
121
+ "postgres://postgres@localhost:5433" ,
122
+ TlsMode :: None ,
123
+ & l. handle ( ) ,
124
+ ) . then ( |r| {
125
+ r. unwrap ( ) . batch_execute (
126
+ "CREATE TEMPORARY TABLE foo (id SERIAL); INSERT INTO foo DEFAULT \
120
127
VALUES;",
121
- )
122
- } )
128
+ )
129
+ } )
123
130
. and_then ( |c| c. batch_execute ( "SELECT * FROM bogo" ) )
124
131
. then ( |r| match r {
125
132
Err ( Error :: Db ( e, s) ) => {
@@ -135,12 +142,15 @@ fn batch_execute_err() {
135
142
#[ test]
136
143
fn prepare_execute ( ) {
137
144
let mut l = Core :: new ( ) . unwrap ( ) ;
138
- let done = Connection :: connect ( "postgres://postgres@localhost:5433" , TlsMode :: None , & l. handle ( ) )
139
- . then ( |c| {
140
- c. unwrap ( ) . prepare (
141
- "CREATE TEMPORARY TABLE foo (id SERIAL PRIMARY KEY, name VARCHAR)" ,
142
- )
143
- } )
145
+ let done = Connection :: connect (
146
+ "postgres://postgres@localhost:5433" ,
147
+ TlsMode :: None ,
148
+ & l. handle ( ) ,
149
+ ) . then ( |c| {
150
+ c. unwrap ( ) . prepare (
151
+ "CREATE TEMPORARY TABLE foo (id SERIAL PRIMARY KEY, name VARCHAR)" ,
152
+ )
153
+ } )
144
154
. and_then ( |( s, c) | c. execute ( & s, & [ ] ) )
145
155
. and_then ( |( n, c) | {
146
156
assert_eq ! ( 0 , n) ;
@@ -154,22 +164,28 @@ fn prepare_execute() {
154
164
#[ test]
155
165
fn prepare_execute_rows ( ) {
156
166
let mut l = Core :: new ( ) . unwrap ( ) ;
157
- let done = Connection :: connect ( "postgres://postgres@localhost:5433" , TlsMode :: None , & l. handle ( ) )
158
- . then ( |c| c. unwrap ( ) . prepare ( "SELECT 1" ) )
167
+ let done = Connection :: connect (
168
+ "postgres://postgres@localhost:5433" ,
169
+ TlsMode :: None ,
170
+ & l. handle ( ) ,
171
+ ) . then ( |c| c. unwrap ( ) . prepare ( "SELECT 1" ) )
159
172
. and_then ( |( s, c) | c. execute ( & s, & [ ] ) ) ;
160
173
l. run ( done) . unwrap ( ) ;
161
174
}
162
175
163
176
#[ test]
164
177
fn query ( ) {
165
178
let mut l = Core :: new ( ) . unwrap ( ) ;
166
- let done = Connection :: connect ( "postgres://postgres@localhost:5433" , TlsMode :: None , & l. handle ( ) )
167
- . then ( |c| {
168
- c. unwrap ( ) . batch_execute (
169
- "CREATE TEMPORARY TABLE foo (id SERIAL, name VARCHAR);
179
+ let done = Connection :: connect (
180
+ "postgres://postgres@localhost:5433" ,
181
+ TlsMode :: None ,
182
+ & l. handle ( ) ,
183
+ ) . then ( |c| {
184
+ c. unwrap ( ) . batch_execute (
185
+ "CREATE TEMPORARY TABLE foo (id SERIAL, name VARCHAR);
170
186
INSERT INTO foo (name) VALUES ('joe'), ('bob')" ,
171
- )
172
- } )
187
+ )
188
+ } )
173
189
. and_then ( |c| c. prepare ( "SELECT id, name FROM foo ORDER BY id" ) )
174
190
. and_then ( |( s, c) | c. query ( & s, & [ ] ) . collect ( ) )
175
191
. and_then ( |( r, c) | {
@@ -187,12 +203,15 @@ fn query() {
187
203
#[ test]
188
204
fn transaction ( ) {
189
205
let mut l = Core :: new ( ) . unwrap ( ) ;
190
- let done = Connection :: connect ( "postgres://postgres@localhost:5433" , TlsMode :: None , & l. handle ( ) )
191
- . then ( |c| {
192
- c. unwrap ( ) . batch_execute (
193
- "CREATE TEMPORARY TABLE foo (id SERIAL, name VARCHAR);" ,
194
- )
195
- } )
206
+ let done = Connection :: connect (
207
+ "postgres://postgres@localhost:5433" ,
208
+ TlsMode :: None ,
209
+ & l. handle ( ) ,
210
+ ) . then ( |c| {
211
+ c. unwrap ( ) . batch_execute (
212
+ "CREATE TEMPORARY TABLE foo (id SERIAL, name VARCHAR);" ,
213
+ )
214
+ } )
196
215
. then ( |c| c. unwrap ( ) . transaction ( ) )
197
216
. then ( |t| {
198
217
t. unwrap ( ) . batch_execute (
@@ -451,13 +470,12 @@ fn notifications() {
451
470
let done = Connection :: connect ( "postgres://postgres@localhost:5433" , TlsMode :: None , & handle)
452
471
. then ( |c| c. unwrap ( ) . batch_execute ( "LISTEN test_notifications" ) )
453
472
. and_then ( |c1| {
454
- Connection :: connect ( "postgres://postgres@localhost:5433" , TlsMode :: None , & handle) . then (
455
- |c2| {
473
+ Connection :: connect ( "postgres://postgres@localhost:5433" , TlsMode :: None , & handle)
474
+ . then ( |c2| {
456
475
c2. unwrap ( )
457
476
. batch_execute ( "NOTIFY test_notifications, 'foo'" )
458
477
. map ( |_| c1)
459
- } ,
460
- )
478
+ } )
461
479
} )
462
480
. and_then ( |c| c. notifications ( ) . into_future ( ) . map_err ( |( e, _) | e) )
463
481
. map ( |( n, _) | {
0 commit comments