From c877d87fca1b0aaf6bfb8aa628d0aa237d231d1f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 10 Mar 2025 11:22:23 +0100 Subject: [PATCH] Bug 34070: Add tests Content-Type: text/plain; charset=utf-8 Signed-off-by: Jonathan Druart Signed-off-by: Marcel de Rooy --- t/db_dependent/Koha/BackgroundJob.t | 39 +++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/t/db_dependent/Koha/BackgroundJob.t b/t/db_dependent/Koha/BackgroundJob.t index 3e4e0354e9..035823d6f7 100755 --- a/t/db_dependent/Koha/BackgroundJob.t +++ b/t/db_dependent/Koha/BackgroundJob.t @@ -303,17 +303,36 @@ subtest 'decoded_data() and set_encoded_data() tests' => sub { $schema->storage->txn_rollback; }; -subtest 'decoded_data() and set_encoded_data() tests' => sub { - plan tests => 3; +subtest 'connect' => sub { + plan tests => 2; + + subtest 'JobsNotificationMethod' => sub { + plan tests => 3; + t::lib::Mocks::mock_config( 'message_broker', { hostname => 'not_localhost', port => '99999' } ); + + t::lib::Mocks::mock_preference( 'JobsNotificationMethod', 'STOMP' ); + my $job; + warning_like { $job = Koha::BackgroundJob->connect() } qr{Cannot connect to broker}; + is( $job, undef, "Return undef if unable to connect when using stomp" ); - t::lib::Mocks::mock_config( 'message_broker', { hostname => 'not_localhost', port => '99999' } ); + t::lib::Mocks::mock_preference( 'JobsNotificationMethod', 'polling' ); + $job = Koha::BackgroundJob->connect(); + is( $job, undef, "Return undef if using polling" ); + }; + + subtest 'wrong credentials' => sub { + plan tests => 2; + t::lib::Mocks::mock_preference( 'JobsNotificationMethod', 'STOMP' ); - t::lib::Mocks::mock_preference( 'JobsNotificationMethod', 'STOMP' ); - my $job; - warning_like { $job = Koha::BackgroundJob->connect() } qr{Cannot connect to broker}; - is( $job, undef, "Return undef if unable to connect when using stomp" ); + t::lib::Mocks::mock_config( + 'message_broker', + { hostname => 'localhost', port => '61613', username => 'guest', password => 'wrong_password' } + ); - t::lib::Mocks::mock_preference( 'JobsNotificationMethod', 'polling' ); - $job = Koha::BackgroundJob->connect(); - is( $job, undef, "Return undef if using polling" ); + my $job; + warning_is { $job = Koha::BackgroundJob->connect() } + q{Cannot connect to broker (Access refused for user 'guest')}; + is( $job, undef, "Return undef if unable to connect when using stomp" ); + + }; }; -- 2.39.5