@@ -6,6 +6,7 @@ import Control.Monad
6
6
import Data.Maybe
7
7
import Data.Either
8
8
import qualified Data.ByteString as B
9
+ import qualified Data.ByteString.Lazy as BL
9
10
import qualified Data.ByteString.Char8 as BS
10
11
import qualified Data.Vector as V
11
12
@@ -31,7 +32,6 @@ testDriver = testGroup "Driver"
31
32
, testCase " Describe statement with no data" testDescribeStatementNoData
32
33
, testCase " Describe empty statement" testDescribeStatementEmpty
33
34
, testCase " SimpleQuery" testSimpleQuery
34
- , testCase " SimpleAndExtendedQuery" testSimpleAndExtendedQuery
35
35
, testCase " PreparedStatementCache" testPreparedStatementCache
36
36
, testCase " Query with large response" testLargeQuery
37
37
]
@@ -48,8 +48,9 @@ fromRight :: Either e a -> a
48
48
fromRight (Right v) = v
49
49
fromRight _ = error " fromRight"
50
50
51
- fromMessage :: Either e DataMessage -> B. ByteString
52
- fromMessage (Right (DataMessage [v])) = fromJust $ V. head v
51
+ fromMessage :: Either e DataRows -> B. ByteString
52
+ -- TODO
53
+ fromMessage (Right (DataRows bs)) = B. drop 9 $ BL. toStrict bs
53
54
fromMessage _ = error " from message"
54
55
55
56
-- | Single batch.
@@ -111,16 +112,16 @@ assertQueryNoData q = withConnection $ \c -> do
111
112
sendBatchAndSync c [q]
112
113
r <- fromRight <$> readNextData c
113
114
waitReadyForQuery c
114
- DataMessage [] @=? r
115
+ DataRows " " @=? r
115
116
116
- -- | Asserts that all the received data rows are in form (Right _)
117
+ -- | Asserts that all the received data messages are in form (Right _)
117
118
checkRightResult :: Connection -> Int -> Assertion
118
119
checkRightResult conn 0 = pure ()
119
120
checkRightResult conn n = readNextData conn >>=
120
121
either (const $ assertFailure " Result is invalid" )
121
122
(const $ checkRightResult conn (n - 1 ))
122
123
123
- -- | Asserts that (Left _) as result exists in the received data rows .
124
+ -- | Asserts that (Left _) as result exists in the received data messages .
124
125
checkInvalidResult :: Connection -> Int -> Assertion
125
126
checkInvalidResult conn 0 = assertFailure " Result is right"
126
127
checkInvalidResult conn n = readNextData conn >>=
@@ -149,7 +150,7 @@ testInvalidBatch = do
149
150
150
151
-- | Describes usual statement.
151
152
testDescribeStatement :: IO ()
152
- testDescribeStatement = withConnection $ \ c -> do
153
+ testDescribeStatement = withConnectionCommon $ \ c -> do
153
154
r <- describeStatement c $
154
155
" select typname, typnamespace, typowner, typlen, typbyval,"
155
156
<> " typcategory, typispreferred, typisdefined, typdelim, typrelid,"
@@ -159,21 +160,21 @@ testDescribeStatement = withConnection $ \c -> do
159
160
160
161
-- | Describes statement that returns no data.
161
162
testDescribeStatementNoData :: IO ()
162
- testDescribeStatementNoData = withConnection $ \ c -> do
163
+ testDescribeStatementNoData = withConnectionCommon $ \ c -> do
163
164
r <- fromRight <$> describeStatement c " SET client_encoding TO UTF8"
164
165
assertBool " Should be empty" $ V. null (fst r)
165
166
assertBool " Should be empty" $ V. null (snd r)
166
167
167
168
-- | Describes statement that is empty string.
168
169
testDescribeStatementEmpty :: IO ()
169
- testDescribeStatementEmpty = withConnection $ \ c -> do
170
+ testDescribeStatementEmpty = withConnectionCommon $ \ c -> do
170
171
r <- fromRight <$> describeStatement c " "
171
172
assertBool " Should be empty" $ V. null (fst r)
172
173
assertBool " Should be empty" $ V. null (snd r)
173
174
174
175
-- | Query using simple query protocol.
175
176
testSimpleQuery :: IO ()
176
- testSimpleQuery = withConnection $ \ c -> do
177
+ testSimpleQuery = withConnectionCommon $ \ c -> do
177
178
r <- sendSimpleQuery c $
178
179
" DROP TABLE IF EXISTS a;"
179
180
<> " CREATE TABLE a(v int);"
@@ -182,25 +183,6 @@ testSimpleQuery = withConnection $ \c -> do
182
183
<> " DROP TABLE a;"
183
184
assertBool " Should be Right" $ isRight r
184
185
185
- -- | Simple and extended queries in a sinle connection.
186
- testSimpleAndExtendedQuery :: IO ()
187
- testSimpleAndExtendedQuery = withConnection $ \ c -> do
188
- let a = " 7"
189
- b = " 2"
190
- d = " 5"
191
- sendBatchAndSync c [ makeQuery1 a , makeQuery1 b]
192
- waitReadyForQuery c
193
- checkRightResult c 2
194
-
195
- rs <- sendSimpleQuery c " SELECT * FROM generate_series(1, 10)"
196
- assertBool " Should be Right" $ isRight rs
197
-
198
- sendBatchAndSync c [makeQuery1 d]
199
- fr <- waitReadyForQuery c
200
- assertBool " Should be Right" $ isRight fr
201
- r <- fromMessage <$> readNextData c
202
- r @=? d
203
-
204
186
-- | Test that cache of statements works.
205
187
testPreparedStatementCache :: IO ()
206
188
testPreparedStatementCache = withConnection $ \ c -> do
0 commit comments