From 9a449a0633e33ed48eca6576046d2b5966942afb Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 24 Jan 2020 09:16:09 -0300 Subject: [PATCH] Bug 24509: Fix tests failing on MySQL8 This patch makes a trivial change to the tests so they catch the way MySQL 8 reports the duplicate key message. The difference on the API error message is irrelevant and so it is ok to just make the tests try both MySQL 8 output and the rest of the supported engines. To test: 1. Run: $ kshell k$ prove t/db_dependent/api/v1/acquisitions_orders.t \ t/db_dependent/api/v1/libraries.t \ t/db_dependent/api/v1/patrons.t => FAIL: Tests fail due to warning and conflict message differences 2. Apply this patch 3. Repeat 1 => SUCCESS: Tests pass! 4. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/api/v1/acquisitions_orders.t | 4 ++-- t/db_dependent/api/v1/libraries.t | 4 ++-- t/db_dependent/api/v1/patrons.t | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/t/db_dependent/api/v1/acquisitions_orders.t b/t/db_dependent/api/v1/acquisitions_orders.t index f8c51d3134..4fae8e440d 100644 --- a/t/db_dependent/api/v1/acquisitions_orders.t +++ b/t/db_dependent/api/v1/acquisitions_orders.t @@ -211,8 +211,8 @@ subtest 'add() tests' => sub { $t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/orders" => json => $order ) ->status_is(409) ->json_has( '/error' => "Fails when trying to add an existing order_id") - ->json_is( '/conflict', 'PRIMARY' ); } # WTF - qr/^DBD::mysql::st execute failed: Duplicate entry '(.*)' for key 'PRIMARY'/; + ->json_like( '/conflict' => qr/(aqorders\.)?PRIMARY/ ); } + qr/^DBD::mysql::st execute failed: Duplicate entry '(.*)' for key '(aqorders\.)?PRIMARY'/; $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/api/v1/libraries.t b/t/db_dependent/api/v1/libraries.t index 8cdac30dfe..590bbdfc63 100644 --- a/t/db_dependent/api/v1/libraries.t +++ b/t/db_dependent/api/v1/libraries.t @@ -199,8 +199,8 @@ subtest 'add() tests' => sub { $t->post_ok( "//$auth_userid:$password@/api/v1/libraries" => json => $library ) ->status_is(409) ->json_has( '/error' => "Fails when trying to add an existing library_id") - ->json_is( '/conflict', 'PRIMARY' ); } # WTF - qr/^DBD::mysql::st execute failed: Duplicate entry '(.*)' for key 'PRIMARY'/; + ->json_like( '/conflict' => qr/(branches\.)?PRIMARY/ ); } + qr/^DBD::mysql::st execute failed: Duplicate entry '(.*)' for key '(branches\.)?PRIMARY'/; $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index 9579229bb4..86f6bd5e90 100644 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -207,8 +207,8 @@ subtest 'add() tests' => sub { $t->post_ok("//$userid:$password@/api/v1/patrons" => json => $newpatron) ->status_is(409) ->json_has( '/error', 'Fails when trying to POST duplicate cardnumber' ) - ->json_has( '/conflict', 'cardnumber' ); } - qr/^DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key 'cardnumber'/; + ->json_like( '/conflict' => qr/(borrowers\.)?cardnumber/ ); } + qr/^DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key '(borrowers\.)?cardnumber'/; $schema->storage->txn_rollback; }; @@ -311,8 +311,8 @@ subtest 'update() tests' => sub { $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->borrowernumber => json => $newpatron ) ->status_is(409) ->json_has( '/error' => "Fails when trying to update to an existing cardnumber or userid") - ->json_is( '/conflict', 'cardnumber' ); } - qr/^DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key 'cardnumber'/; + ->json_like( '/conflict' => qr/(borrowers\.)?cardnumber/ ); } + qr/^DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key '(borrowers\.)?cardnumber'/; $newpatron->{ cardnumber } = $patron_1->id . $patron_2->id; $newpatron->{ userid } = "user" . $patron_1->id.$patron_2->id; -- 2.25.0