Co-authored-by: Graham Christensen <graham@grahamc.com>
5DXGOH6QPIMK5CBZ6G3MN7UOIJRGFA3MP7C6FAFWLB7V2TAS33FAC
5MVWRWHT7U57UQS4EP3AEDFUL7BDLMWFCMYK32IT6XXS7OS6MQUQC
3JXCTKEC3EXJZHWSVRZMUHYH6HGDHKQUTPHDVJ4LACRMXBNLCEIAC
2JJP76737U2JWJWQ6UDFEAQCGWRAQH46HC6OCIKWMB5QYRXF6DQQC
I6QMKSIS7HFBPONWWSGXX2IIHEYHEPA4QU2SSM6QUTDK5NKK3VXQC
JAH3UPWAVSHXIPNGL6PROQPZBYZHPJNFONWBDZX4HCX646USZXUQC
2GK5DOU7ODF4WBSN3QTD3WIO52VTL2LOAXKGCDEMMAQPTEO4A4HAC
CUFVKLLAL54OHDMYUHVJZK46LLX7RJMUJUE5HWYDCGIOQ5TIGXZQC
WQXF2T3DFC2K72OVX46TUQ4IMZNJ5BSBQ7L7AVI7QL54DXCBEKLQC
A63IHCMXH3F4V56HDXJLJVVHKXRSJCJMT2PWXXI2IW3J734J6SGQC
AFTXA575C6JTVLVXTYJUKQGPLBO3NFORLO5XDSPHNL44HXLRH4TAC
WVD3YYON22ES6LFQTX7LYBXTEBERGIN2DHOJC6M36UJ4KS4IHS2QC
N22GPKYTOLZLBGTGDATQDVZ4R5APZEAOIA7L32X4UXBH4XNI7MWAC
DODOGD7MRCMRVGX23RPY2243WG54HCMCEZ6DCHOGID3GBQB66CXQC
# Return hash of statsd configuration of the following shape:
# (
# host => string,
# port => digit
# )
sub getStatsdConfig {
my ($config) = @_;
my $cfg = $config->{statsd};
my %statsd = defined $cfg ? ref $cfg eq "HASH" ? %$cfg : ($cfg) : ();
return {
"host" => %statsd{'host'} // 'localhost',
"port" => %statsd{'port'} // 8125,
}
}
use strict;
use Setup;
my %ctx = test_init(hydra_config => q|
<statsd>
host = foo.bar
port = 18125
</statsd>
|);
require Hydra::Helper::Nix;
use Test2::V0;
is(Hydra::Helper::Nix::getStatsdConfig(Hydra::Helper::Nix::getHydraConfig()), {
'host' => "foo.bar",
'port' => 18125
}, "Reading specific configuration from the hydra.conf works");
is(Hydra::Helper::Nix::getStatsdConfig(), {
'host' => "localhost",
'port' => 8125
}, "A totally empty configuration yields default options");
is(Hydra::Helper::Nix::getStatsdConfig({
"statsd" => {
}
}), {
'host' => "localhost",
'port' => 8125
}, "A empty statsd block yields default options");
is(Hydra::Helper::Nix::getStatsdConfig({
"statsd" => {
'host' => "statsdhost"
}
}), {
'host' => "statsdhost",
'port' => 8125
}, "An overridden statsd host propogates, but the other defaults are returned");
is(Hydra::Helper::Nix::getStatsdConfig({
"statsd" => {
'port' => 5218
}
}), {
'host' => "localhost",
'port' => 5218
}, "An overridden statsd port propogates, but the other defaults are returned");
is(Hydra::Helper::Nix::getStatsdConfig({
"statsd" => {
'host' => 'my.statsd.host',
'port' => 5218
}
}), {
'host' => "my.statsd.host",
'port' => 5218
}, "An overridden statsd port and host propogate");
done_testing;