Skip to content

Commit c5e489a

Browse files
committed
Test malformed input error during COPY
1 parent 2800db2 commit c5e489a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

test/Main.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,9 @@ testCopy TestEnv{..} = do
325325
testCopyFailures :: TestEnv -> TestTree
326326
testCopyFailures env = testGroup "Copy failures"
327327
$ map ($ env)
328-
[ testCopyUniqueConstraintError ]
328+
[ testCopyUniqueConstraintError
329+
, testCopyMalformedError
330+
]
329331

330332
goldenTest :: TestName -> IO BL.ByteString -> TestTree
331333
goldenTest testName =
@@ -351,6 +353,20 @@ testCopyUniqueConstraintError TestEnv{..} =
351353
,"2,bar\n"
352354
,"1,baz\n"]
353355

356+
testCopyMalformedError :: TestEnv -> TestTree
357+
testCopyMalformedError TestEnv{..} =
358+
goldenTest "malformed input"
359+
$ handle (\(SomeException exc) -> return $ BL.pack $ show exc) $ do
360+
execute_ conn "CREATE TEMPORARY TABLE copy_malformed_input_error_test (x int PRIMARY KEY, y text)"
361+
copy_ conn "COPY copy_unique_constraint_error_test FROM STDIN (FORMAT CSV)"
362+
mapM_ (putCopyData conn) copyRows
363+
_n <- putCopyEnd conn
364+
return BL.empty
365+
where
366+
copyRows = ["1,foo\n"
367+
,"2,bar\n"
368+
,"z,baz\n"]
369+
354370
testDouble :: TestEnv -> Assertion
355371
testDouble TestEnv{..} = do
356372
[Only (x :: Double)] <- query_ conn "SELECT 'NaN'::float8"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
user error (Database.PostgreSQL.Simple.Copy.putCopyEnd: failed to parse command status
2+
Connection error: ERROR: invalid input syntax for integer: "z"
3+
CONTEXT: COPY copy_unique_constraint_error_test, line 3, column x: "z"
4+
)

0 commit comments

Comments
 (0)