Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Monitor-Simple CPAN distribution.

Report information
The Basics
Id: 77095
Status: patched
Priority: 0/
Queue: Monitor-Simple

People
Owner: Nobody in particular
Requestors: GWS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.2.5
Fixed in: (no value)



Subject: Patches on tests for use under Windows
Hi Martin – I just started to fiddle around with your Monitor::Simple, which came in really handy. Thank you! It seems to be running under Windows (version 7, in my case), although the tests reported several problems. It seems this were, however, mostly due to different directory delimiters, which are hard-coded as forward slashes in the test scripts. If you’re interested, please, find enclosed fixed versions of the affected test scripts.
Subject: 04-plugins.t
#!perl -w BEGIN { # skip all these tests if the default perl is not the same as the # perl used to start this test (because in such cases there may be # missing Perl modules during invocation the external plugins) use File::Which; use File::Spec; my $default_perl = which ('perl'); my $test_perl = $^X; if (File::Spec->case_tolerant()) { $default_perl = lc($default_perl); $test_perl = lc($test_perl); } unless ($default_perl and $default_perl eq $test_perl) { require Test::More; Test::More::plan (skip_all => 'default perl differs from the one used for testing'); } } #use Test::More qw(no_plan); use Test::More tests => 23; use File::Slurp; use File::Temp qw/ tempfile /; #----------------------------------------------------------------- # Return a fully qualified name of the given file in the test # directory "t/data" - if such file really exists. With no arguments, # it returns the path of the test directory itself. # ----------------------------------------------------------------- use FindBin qw( $Bin ); use File::Spec; sub test_file { my $file = File::Spec->catfile ('t', 'data', @_); return $file if -e $file; $file = File::Spec->catfile ($Bin, 'data', @_); return $file if -e $file; return File::Spec->catfile (@_); } #----------------------------------------------------------------- # Return a configuration extracted from the given file. # ----------------------------------------------------------------- sub get_config { my $filename = shift; my $config_file = test_file ($filename); my $config = Monitor::Simple::Config->get_config ($config_file); ok ($config, "Failed configuration taken from '$config_file'"); return $config; } # ----------------------------------------------------------------- # Tests start here... # ----------------------------------------------------------------- ok(1); use Monitor::Simple; diag( "Testing external plugins" ); my $config = get_config ('plugins.xml'); my $config_file = test_file ('plugins.xml'); sub do_checking { my ($title, $args, $filename, $expected_lines) = @_; Monitor::Simple->check_services ($args); my @lines = read_file ($filename); # diag ($title); # diag (join ("\n", map { chomp; $_ } @lines)); is (scalar @lines, $expected_lines, "Number of parallel service checks [$title]"); foreach my $line (@lines) { my @fields = split (/\t/, $line, 4); is (scalar @fields, 4, "Found only partional line [$title]: $line"); } } # report and exit (one by one); filter as SCALAR { my $report_tests = { ok => 0, warning => 1, critical => 2, unknown => 3, }; foreach my $service (keys %$report_tests) { my ($fh, $filename) = tempfile(); my $args = { config_file => $config_file, filter => $service, outputter => Monitor::Simple::Output->new (outfile => $filename, 'format' => 'tsv', config => $config), }; do_checking ("In SCALAR [$service]:", $args, $filename, 1); unlink $filename; } } # report and exit (in parallel); filters as HASH { my ($fh, $filename) = tempfile(); my $filters = { ok => 0, warning => 1, critical => 2, unknown => 3, }; my $args = { config_file => $config_file, filter => $filters, outputter => Monitor::Simple::Output->new (outfile => $filename, 'format' => 'tsv', config => $config), }; do_checking ('In HASH:', $args, $filename, 4); unlink $filename; } # report and exit (in parallel); filters as ARRAY { my ($fh, $filename) = tempfile(); my $filters = ['ok', 'warning', 'critical', 'unknown']; my $args = { config_file => $config_file, filter => $filters, outputter => Monitor::Simple::Output->new (outfile => $filename, 'format' => 'tsv', config => $config), }; do_checking ('In ARRAY:', $args, $filename, 4); unlink $filename; } # plugin: check-prg.pl { my ($fh, $filename) = tempfile(); my $filters = { prg => 0, prgbad => 3, }; my $outputter = Monitor::Simple::Output->new (outfile => $filename, 'format' => 'tsv', config => $config); my $args = { config_file => $config_file, filter => $filters, outputter => $outputter, }; do_checking ('In PRG:', $args, $filename, 2); unlink $filename; } __END__
Subject: 03-utils.t
#!perl -w #use Test::More qw(no_plan); use Test::More tests => 17; #----------------------------------------------------------------- # Return a fully qualified name of the given file in the test # directory "t/data" - if such file really exists. With no arguments, # it returns the path of the test directory itself. # ----------------------------------------------------------------- use FindBin qw( $Bin ); use File::Spec; sub test_file { my $file = File::Spec->catfile ('t', 'data', @_); return $file if -e $file; $file = File::Spec->catfile ($Bin, 'data', @_); return $file if -e $file; return File::Spec->catfile (@_); } # ----------------------------------------------------------------- # Tests start here... # ----------------------------------------------------------------- ok(1); use Monitor::Simple; use Monitor::Simple::Utils; diag( "Testing utilities" ); # parse plugin's args { my $config_file = File::Spec->catfile (test_file(), 'config.xml'); my @result = Monitor::Simple::Utils->parse_plugin_args ('default', '-cfg', $config_file, '-service', 's1'); is_deeply (\@result, [ $config_file, 's1' ], "Parse plugin arguments 1"); @result = Monitor::Simple::Utils->parse_plugin_args (undef, '-cfg', $config_file, '-service', 's1'); is_deeply (\@result, [ $config_file, 's1' ], "Parse plugin arguments 2"); @result = Monitor::Simple::Utils->parse_plugin_args ('s1', '-cfg', $config_file); is_deeply (\@result, [ $config_file, 's1' ], "Parse plugin arguments 3"); @result = Monitor::Simple::Utils->parse_plugin_args (undef, '-cfg', $config_file); is_deeply (\@result, [ $config_file, undef ], "Parse plugin arguments 4"); } # parse notifier's args { my @result = Monitor::Simple::Utils->parse_notifier_args (['-service', 's1', '-msg', 'file', '-emails', 'address']); is_deeply (\@result, [ 's1', 'file', [ 'address' ] ], "Parse notifier arguments 1"); @result = Monitor::Simple::Utils->parse_notifier_args (['-service', 's1', '-msg', 'file']); is_deeply (\@result, [ 's1', 'file', [] ], "Parse notifier arguments 2"); } # process exit { my @result; @result = Monitor::Simple::Utils->process_exit ('dummy', 0, 'msg'); is_deeply (\@result, [ 0, 'msg' ], "Process exit code 0"); @result = Monitor::Simple::Utils->process_exit ('dummy', 256, 'msg'); is_deeply (\@result, [ 1, 'msg' ], "Process exit code 256"); @result = Monitor::Simple::Utils->process_exit ('dummy', -1, 'msg'); is ($result[0], -1, "Process exit code -1"); } # is integer my $integer_tests = { 2 => 1, 0 => 1, '-0' => 1, '-2' => 1, a => '', '1.2' => '', '0.5' => '', }; foreach my $str (keys %$integer_tests) { is (Monitor::Simple::Utils->is_integer ($str), $integer_tests->{$str}, "Integer: '$str'"); } __END__
Subject: 01-config.t
#!perl -w #use Test::More qw(no_plan); use Test::More tests => 36; #----------------------------------------------------------------- # Return a fully qualified name of the given file in the test # directory "t/data" - if such file really exists. With no arguments, # it returns the path of the test directory itself. # ----------------------------------------------------------------- use FindBin qw( $Bin ); use File::Spec; sub test_file { my $file = File::Spec->catfile ('t', 'data', @_); return $file if -e $file; $file = File::Spec->catfile ($Bin, 'data', @_); return $file if -e $file; return File::Spec->catfile (@_); } # ----------------------------------------------------------------- # Tests start here... # ----------------------------------------------------------------- ok(1); use Monitor::Simple; use Monitor::Simple::Config; diag( "Testing the configuration" ); # resolving configuration file { my $existing_file = File::Spec->catfile (test_file(), 'c1.empty'); is (Monitor::Simple::Config->resolve_config_file ($existing_file), $existing_file, "Resolving file - ad a) failed"); $ENV{$Monitor::Simple::Config::ENV_CONFIG_DIR} = File::Spec->catfile ($Bin, 'data'); is (Monitor::Simple::Config->resolve_config_file ('c2.empty'), File::Spec->catfile ($Bin, 'data', 'c2.empty'), "Resolving file - ad b) failed"); delete $ENV{$Monitor::Simple::Config::ENV_CONFIG_DIR}; push (@INC, File::Spec->catfile ($Bin, 'data')); is (Monitor::Simple::Config->resolve_config_file ('c3.empty'), File::Spec->catfile ($Bin, 'data', 'c3.empty'), "Resolving file - ad d) failed"); pop @INC; is (Monitor::Simple::Config->resolve_config_file ('non-existing'), undef, "Resolving file - ad e) failed"); } # bad XML { my $bad_xml_file = test_file ('bad.xml'); eval { Monitor::Simple::Config->get_config ($bad_xml_file) }; ok ($@, "There should be an error in '$bad_xml_file'"); } # validating configuration file { my $bad_config_file = test_file ('bad-config.xml'); eval { my $config = Monitor::Simple::Config->get_config ($bad_config_file) }; my $errors = $@; ok ($errors, "There should be errors in '$bad_config_file'"); my @error_msgs = ( "Service number 1 does not have an ID attribute", "Service number 1 does not have any plugin section", "Service 'Letter A' has a plugin without any 'command' attribute", "Notifier number 1 in service 'Letter A' has no 'command' attribute", "Service 'Letter B' has more than one plugin tag", "General notifier number 1 has no 'command' attribute", ); foreach my $msg (@error_msgs) { my $qmsg = "\Q$msg"; ok ($errors =~ m{$qmsg}, "Missing error: $msg"); } } # general section of a configuration file my $filename = 'config.xml'; my $config_file = test_file ($filename); my $config = Monitor::Simple::Config->get_config ($config_file); ok ($config, "Failed configuration taken from '$config_file'"); is (ref ($config->{services}), 'ARRAY', "Services should be an arrayref"); is (ref ($config->{general}->{'email-group'}), 'ARRAY', "email-group should be an arrayref"); is (ref ($config->{general}->{'email-group'}->[0]->{email}), 'ARRAY', "email-group/email should be an arrayref"); is (ref ($config->{general}->{notifier}), 'ARRAY', "notifier should be an arrayref"); is (ref ($config->{general}->{notifier}->[0]->{args}), 'ARRAY', "notifier/args should be an arrayref"); # setting default values my $plugindir = File::Spec->catdir(qw(Monitor Simple plugins)); $plugindir =~ s/\\/\\\\/g; ok ($config->{general}->{'plugins-dir'} =~ m{$plugindir$}, "Bad default value for plugins directory: $config->{general}->{'plugins-dir'}"); my $notifiersdir = File::Spec->catdir(qw(Monitor Simple notifiers)); $notifiersdir =~ s/\\/\\\\/g; ok ($config->{general}->{'notifiers-dir'} =~ m{$notifiersdir$}, "Bad default value for notifiers directory: $config->{general}->{'notifiers-dir'}"); { my $service_id = 'no-name-service'; my $service = Monitor::Simple::Config->extract_service_config ($service_id, $config); ok ($service, "Missing service configuration for service '$service_id'"); is ($service->{name}, $service_id, "Bad default value for service name"); } # section with an individual service { my $service_id = 'XXX.no-name-service'; my $savewarn = $SIG{'__WARN__'}; $SIG{'__WARN__'} = sub {}; my $service = Monitor::Simple::Config->extract_service_config ($service_id, $config); is ($service, undef, "Should return undef for service '$service_id'"); $SIG{'__WARN__'} = $savewarn; } { my $service_id = 's1'; my $service = Monitor::Simple::Config->extract_service_config ($service_id, $config); ok ($service, "Configuration for service '$service_id'"); } { my $service_id = 'copy'; my $service = Monitor::Simple::Config->extract_service_config ($service_id, $config); ok ($service, "Configuration for service '$service_id'"); is ($service->{name}, '<Moderated> "exit"', "Service name with unusual chars"); } { my $service_id = 's1'; my $service = Monitor::Simple::Config->extract_service_config ($service_id, $config); ok ($service, "Configuration for service '$service_id'"); is (ref ($service->{plugin}->{'head-test'}), 'ARRAY', "head-test should be an arrayref"); is (ref ($service->{plugin}->{'get-test'}), 'ARRAY', "get-test should be an arrayref"); is (ref ($service->{plugin}->{'post-test'}), 'ARRAY', "post-test should be an arrayref"); is (ref ($service->{plugin}->{'get-test'}->[0]->{response}->{contains}), 'ARRAY', "response/contains should be an arrayref"); } # creation of the arguments for plugins { my $savewarn = $SIG{'__WARN__'}; $SIG{'__WARN__'} = sub {}; my @args = Monitor::Simple::Config->create_plugin_args ('config.file', $config, 'unknown-service'); is (scalar @args, 0, "No arguments for unknown service"); $SIG{'__WARN__'} = $savewarn; } { my @args = Monitor::Simple::Config->create_plugin_args ('config.file', $config, 's1'); is (scalar @args, 4, "Number of arguments for a standard plugin"); is_deeply (\@args, [qw(-cfg config.file -service s1)], "Create standard plugin arguments"); } { my @args = Monitor::Simple::Config->create_plugin_args ('whatever', $config, 'copy'); is_deeply (\@args, ['2', 'This is an <"artificial"> error'], "Create user-defined plugin arguments"); } __END__
Thanks a lot. I gratefully used your patches in version 0.2.7. Martin
Subject: AW: [rt.cpan.org #77095] Patches on tests for use under Windows
Date: Tue, 4 Jun 2013 10:28:03 +0200
To: <bug-Monitor-Simple [...] rt.cpan.org>
From: "Selke, Gisbert W." <gisbert.selke [...] wido.bv.aok.de>
Happily -- thanks for fixing it! \Gisbert Show quoted text
> -----Ursprüngliche Nachricht----- > Von: Martin Senger via RT [mailto:bug-Monitor-Simple@rt.cpan.org] > Gesendet: Montag, 3. Juni 2013 09:37 > An: GWS@cpan.org > Betreff: [rt.cpan.org #77095] Patches on tests for use under Windows > > <URL: https://rt.cpan.org/Ticket/Display.html?id=77095 > > > Thanks a lot. I gratefully used your patches in version 0.2.7. > Martin