|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This test is db dependent: SIPServer needs MsgType which needs Auth. |
| 4 |
# And Auth needs config vars and prefences in its BEGIN block. |
| 5 |
|
| 6 |
# This file is part of Koha. |
| 7 |
# |
| 8 |
# Koha is free software; you can redistribute it and/or modify it |
| 9 |
# under the terms of the GNU General Public License as published by |
| 10 |
# the Free Software Foundation; either version 3 of the License, or |
| 11 |
# (at your option) any later version. |
| 12 |
# |
| 13 |
# Koha is distributed in the hope that it will be useful, but |
| 14 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 20 |
|
| 21 |
use Modern::Perl; |
| 22 |
|
| 23 |
use Test::More tests => 1; |
| 24 |
use Test::Warn; |
| 25 |
|
| 26 |
my ( $mockConfig, $mockPrefork ); |
| 27 |
|
| 28 |
BEGIN { |
| 29 |
# In order to test SIPServer::get_timeout, we need to mock |
| 30 |
# Configuration->new and PreFork->run. |
| 31 |
use Test::MockModule; |
| 32 |
use C4::SIP::Sip::Configuration; |
| 33 |
$mockConfig = Test::MockModule->new( 'C4::SIP::Sip::Configuration' ); |
| 34 |
$mockConfig->mock( 'new', sub { return {}; } ); |
| 35 |
use Net::Server::PreFork; |
| 36 |
$mockPrefork = Test::MockModule->new( 'Net::Server::PreFork' ); |
| 37 |
$mockPrefork->mock( 'run', sub {} ); |
| 38 |
} |
| 39 |
|
| 40 |
use C4::SIP::SIPServer; |
| 41 |
|
| 42 |
# Start testing ! |
| 43 |
# TODO We should include more tests here. |
| 44 |
|
| 45 |
subtest 'Get_timeout' => sub { |
| 46 |
plan tests => 11; |
| 47 |
|
| 48 |
my $server = { policy => { timeout => 1 }, |
| 49 |
config => { timeout => 2 }, |
| 50 |
service => { |
| 51 |
timeout => 3, |
| 52 |
client_timeout => 4, |
| 53 |
}, |
| 54 |
}; |
| 55 |
|
| 56 |
is( C4::SIP::SIPServer::get_timeout(), 30, "Default fallback" ); |
| 57 |
is( C4::SIP::SIPServer::get_timeout( undef, { fallback => 25 } ), 25, "Fallback parameter" ); |
| 58 |
is( C4::SIP::SIPServer::get_timeout( $server, { transport => 1 } ), 3, "Transport value" ); |
| 59 |
is( C4::SIP::SIPServer::get_timeout( $server, { client => 1 } ), 4, "Client value" ); |
| 60 |
is( C4::SIP::SIPServer::get_timeout( $server, { policy => 1 } ), '001', "Policy value" ); |
| 61 |
|
| 62 |
delete $server->{policy}->{timeout}; |
| 63 |
is( C4::SIP::SIPServer::get_timeout( $server, { policy => 1 } ), '000', "No policy" ); |
| 64 |
|
| 65 |
$server->{service}->{client_timeout} = '0'; |
| 66 |
is( C4::SIP::SIPServer::get_timeout( $server, { client => 1 } ), 0, "Client zero" ); |
| 67 |
$server->{service}->{client_timeout} = 'no'; |
| 68 |
is( C4::SIP::SIPServer::get_timeout( $server, { client => 1 } ), 0, "Client no" ); |
| 69 |
delete $server->{service}->{client_timeout}; |
| 70 |
is( C4::SIP::SIPServer::get_timeout( $server, { client => 1 } ), 3, "Fallback to service" ); |
| 71 |
|
| 72 |
delete $server->{service}->{timeout}; |
| 73 |
is( C4::SIP::SIPServer::get_timeout( $server, { transport => 1 } ), 2, "Back to old config" ); |
| 74 |
delete $server->{config}->{timeout}; |
| 75 |
is( C4::SIP::SIPServer::get_timeout( $server, { transport => 1 } ), 30, "Fallback again" ); |
| 76 |
}; |
| 77 |
|
| 78 |
1; |