Bugzilla – Attachment 179148 Details for
Bug 39286
BackgroundJob.t should mock_config
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39286: Use mock_config instead of env vars
Bug-39286-Use-mockconfig-instead-of-env-vars.patch (text/plain), 3.07 KB, created by
Magnus Enger
on 2025-03-11 09:23:47 UTC
(
hide
)
Description:
Bug 39286: Use mock_config instead of env vars
Filename:
MIME Type:
Creator:
Magnus Enger
Created:
2025-03-11 09:23:47 UTC
Size:
3.07 KB
patch
obsolete
>From 445c545aaa0b9d4801569cbe6ef4eec481d06d15 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 10 Mar 2025 11:14:42 +0100 >Subject: [PATCH] Bug 39286: Use mock_config instead of env vars > >Bug 35655 needed to mock the config, but instead introduced new env variables. > >Test plan: > prove t/db_dependent/Koha/BackgroundJob.t >should still return green > >Bonus 1: no more warning >t/db_dependent/Koha/BackgroundJob.t .. 1/6 Cannot connect to broker Failed to connect: Error connecting to not_localhost:99999: Invalid argument at /usr/share/perl5/Net/Stomp.pm line 27.; giving up at /usr/share/perl5/Net/Stomp.pm line 27. > >Bonus 2: tests are passing even if you have 'message_broker' in the >config >To test this, add the following entry to $KOHA_CONf then prove again > <message_broker> > <hostname>localhost</hostname> > <port>61613</port> > <username>guest</username> > <password>guest</password> > <vhost></vhost> > </message_broker> >=> Without this patch the tests fail because the config will overwrite >the env vars. > >Signed-off-by: Magnus Enger <magnus@libriotech.no> >Warning goes away and prove works even with the message_broker config. >--- > Koha/BackgroundJob.pm | 4 ++-- > t/db_dependent/Koha/BackgroundJob.t | 11 ++++++----- > 2 files changed, 8 insertions(+), 7 deletions(-) > >diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm >index 211e2e32f3..154c00e1e8 100644 >--- a/Koha/BackgroundJob.pm >+++ b/Koha/BackgroundJob.pm >@@ -69,8 +69,8 @@ sub connect { > return > unless $notification_method eq 'STOMP'; > >- my $hostname = $ENV{KOHA_STOMP_HOSTNAME} // 'localhost'; >- my $port = $ENV{KOHA_STOMP_PORT} // '61613'; >+ my $hostname = 'localhost'; >+ my $port = '61613'; > > my $config = C4::Context->config('message_broker'); > my $credentials = { >diff --git a/t/db_dependent/Koha/BackgroundJob.t b/t/db_dependent/Koha/BackgroundJob.t >index c70a69184c..3e4e0354e9 100755 >--- a/t/db_dependent/Koha/BackgroundJob.t >+++ b/t/db_dependent/Koha/BackgroundJob.t >@@ -22,6 +22,7 @@ use Encode; > use Test::More tests => 6; > use Test::MockModule; > use Test::Exception; >+use Test::Warn; > > use Koha::Database; > use Koha::BackgroundJobs; >@@ -303,16 +304,16 @@ subtest 'decoded_data() and set_encoded_data() tests' => sub { > }; > > subtest 'decoded_data() and set_encoded_data() tests' => sub { >- plan tests => 2; >+ plan tests => 3; > >- $ENV{KOHA_STOMP_HOSTNAME} = "not_localhost"; >- $ENV{KOHA_STOMP_PORT} = "99999"; >+ t::lib::Mocks::mock_config( 'message_broker', { hostname => 'not_localhost', port => '99999' } ); > > t::lib::Mocks::mock_preference( 'JobsNotificationMethod', 'STOMP' ); >- my $job = Koha::BackgroundJob->connect(); >+ 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_preference( 'JobsNotificationMethod', 'polling' ); > $job = Koha::BackgroundJob->connect(); > is( $job, undef, "Return undef if using polling" ); >- } >+}; >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39286
:
179093
|
179148
|
179161