Skip to content

Commit a3dc328

Browse files
committed
Add error mappings for Go
Adjustment for Go for new tests and assertions added in #574
1 parent aa780cf commit a3dc328

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

tests/stub/configuration_hints/test_connection_recv_timeout_seconds.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ def _assert_is_tx_terminated_exception(self, e):
8282
"<class 'neo4j.exceptions.TransactionError'>",
8383
e.errorType
8484
)
85+
elif driver in ["go"]:
86+
self.assertTrue(
87+
e.errorType.startswith("cannot use this transaction")
88+
)
8589
else:
8690
self.fail("no error mapping is defined for %s driver" % driver)
8791

tests/stub/tx_run/test_tx_run.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def _test():
363363
res = tx.run("failing on pull")
364364

365365
# res fails on PULL
366-
with self.assertRaises(types.DriverError) as exc:
366+
with self.assertRaises(types.DriverError) as exc1:
367367
if iterate == "true":
368368
for _i in range(0, 3):
369369
res.next()
@@ -375,15 +375,24 @@ def _test():
375375
# only explicit iteration is tested if fetch all is
376376
# not supported
377377
list(res)
378-
self.assertEqual(exc.exception.code,
378+
self.assertEqual(exc1.exception.code,
379379
"Neo.ClientError.MadeUp.Code")
380-
self._assert_is_client_exception(exc)
380+
self._assert_is_client_exception(exc1)
381381

382-
with self.assertRaises(types.DriverError) as exc:
382+
with self.assertRaises(types.DriverError) as exc2:
383383
tx.run("invalid")
384-
# new actions on the transaction result in a tx terminated
385-
# exception, a subclass of the client exception
386-
self._assert_is_tx_terminated_exception(exc)
384+
driver = get_driver_name()
385+
if driver in ["go"]:
386+
# Go will return the same error the transaction failed with
387+
# over and over again when reusing a failed transaction
388+
self.assertEqual(exc1.exception.errorType,
389+
exc2.exception.errorType)
390+
self.assertEqual(exc1.exception.msg,
391+
exc2.exception.msg)
392+
else:
393+
# new actions on the transaction result in a tx terminated
394+
# exception, a subclass of the client exception
395+
self._assert_is_tx_terminated_exception(exc2)
387396

388397
tx.close()
389398
self._session.close()
@@ -452,6 +461,9 @@ def _assert_is_client_exception(self, e):
452461
"<class 'neo4j.exceptions.ClientError'>",
453462
e.exception.errorType
454463
)
464+
elif driver in ["go"]:
465+
self.assertEqual("Neo4jError", e.exception.errorType)
466+
self.assertIn("Neo.ClientError.", e.exception.msg)
455467
else:
456468
self.fail("no error mapping is defined for %s driver" % driver)
457469

@@ -467,5 +479,9 @@ def _assert_is_tx_terminated_exception(self, e):
467479
"<class 'neo4j.exceptions.TransactionError'>",
468480
e.exception.errorType
469481
)
482+
elif driver in ["go"]:
483+
self.assertTrue(
484+
e.exception.errorType.startswith("cannot use this transaction")
485+
)
470486
else:
471487
self.fail("no error mapping is defined for %s driver" % driver)

0 commit comments

Comments
 (0)