From 4d169b86b5cf93873b8eb1ff1b9c711c50d56680 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 26 Sep 2024 15:16:44 -0400 Subject: [PATCH] Bug 35655: Add unit tests Add the ability to specify STOMP connection info via environment variables and utilize those in unit tests. Signed-off-by: Martin Renvoize --- Koha/BackgroundJob.pm | 5 +++-- t/db_dependent/Koha/BackgroundJob.t | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index c21fdd2510..99fc3bb3dd 100644 --- a/Koha/BackgroundJob.pm +++ b/Koha/BackgroundJob.pm @@ -67,8 +67,9 @@ sub connect { return undef unless $notification_method eq 'STOMP'; - my $hostname = 'localhost'; - my $port = '61613'; + my $hostname = $ENV{KOHA_STOMP_HOSTNAME} // 'localhost'; + my $port = $ENV{KOHA_STOMP_PORT} // '61613'; + my $config = C4::Context->config('message_broker'); my $credentials = { login => 'guest', diff --git a/t/db_dependent/Koha/BackgroundJob.t b/t/db_dependent/Koha/BackgroundJob.t index f34b695c49..35f8fb4e7d 100755 --- a/t/db_dependent/Koha/BackgroundJob.t +++ b/t/db_dependent/Koha/BackgroundJob.t @@ -19,7 +19,7 @@ use Modern::Perl; use utf8; use Encode; -use Test::More tests => 5; +use Test::More tests => 6; use Test::MockModule; use Test::Exception; @@ -297,3 +297,18 @@ subtest 'decoded_data() and set_encoded_data() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'decoded_data() and set_encoded_data() tests' => sub { + plan tests => 2; + + $ENV{KOHA_STOMP_HOSTNAME} = "not_localhost"; + $ENV{KOHA_STOMP_PORT} = "99999"; + + t::lib::Mocks::mock_preference('JobsNotificationMethod', 'STOMP'); + my $job = Koha::BackgroundJob->connect(); + is( $job, undef, "Return undef if unable to connect when using stomp" ); + + t::lib::Mocks::mock_preference('JobsNotificationMethod', 'polling'); + $job = Koha::BackgroundJob->connect(); + is( $job, undef, "Return undef if using polling" ); +} -- 2.39.5