Skip to content

Commit

Permalink
tests: rework tests for not default enabled plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Oct 8, 2024
1 parent 6404b69 commit 58e55e6
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 39 deletions.
14 changes: 6 additions & 8 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,18 @@ if(scalar @ARGV != 1 || $ARGV[0] ne '--checkdeps') {
# check plugin test symlinks
my $testlinks = {};
mkdir("t/xt") unless -d "t/xt";
for my $testdir (glob('plugins/plugins-available/*/t')) {
$testdir =~ m|/plugins-available/(.*)/t|gmx or die("test directory $testdir does not have valid format!");
for my $testdir (glob('plugins/plugins-enabled/*/t')) {
$testdir =~ m|/plugins-enabled/(.*)/t|gmx or die("test directory $testdir does not have valid format!");
my $plugin = $1;

if(!-e 't/xt/'.$plugin and !-l 't/xt/'.$plugin) {
symlink('../../plugins/plugins-available/'.$plugin.'/t', 't/xt/'.$plugin) or die("cannot create symlink ('../../plugins/plugins-available/$plugin/t', 't/xt/$plugin'): $!");
$testlinks->{$plugin} = '../../plugins/plugins-available/'.$plugin.'/t';
symlink('../../plugins/plugins-enabled/'.$plugin.'/t', 't/xt/'.$plugin) or die("cannot create symlink ('../../plugins/plugins-enabled/$plugin/t', 't/xt/$plugin'): $!");
$testlinks->{$plugin} = '../../plugins/plugins-enabled/'.$plugin.'/t';
next;
}
my $target = readlink('t/xt/'.$plugin);
if( $target ne '../../plugins/plugins-available/'.$plugin.'/t'
and $target ne '../../plugins/plugins-enabled/'.$plugin.'/t'
) {
die('t/xt/'.$plugin.' has wrong target: '.$target.' vs. ../../plugins/plugins-available/'.$plugin.'/t');
if($target ne '../../plugins/plugins-enabled/'.$plugin.'/t') {
die('t/xt/'.$plugin.' has wrong target: '.$target.' vs. ../../plugins/plugins-enabled/'.$plugin.'/t');
}
$testlinks->{$plugin} = $target;
}
Expand Down
6 changes: 0 additions & 6 deletions plugins/plugins-available/agents/t/controller_agents.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ BEGIN {
plan skip_all => 'backends required' if(!-s 'thruk_local.conf' and !defined $ENV{'PLACK_TEST_EXTERNALSERVER_URI'});
plan skip_all => 'test skipped' if defined $ENV{'NO_DISABLED_PLUGINS_TEST'};

# enable plugin
`cd plugins/plugins-enabled && ln -s ../plugins-available/agents .`;

plan tests => 39;
}

Expand Down Expand Up @@ -77,6 +74,3 @@ sub _test_json_page {

return($data);
}

# restore default
`cd plugins/plugins-enabled && rm -f agents`;
4 changes: 2 additions & 2 deletions plugins/plugins-available/agents/templates/agents_edit.tt
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@
<tr>
<td colspan="2" align="center">
<div class="flexrow flex-nowrap justify-evenly">
<button class="submit w-44 js-rescan-btn [% IF checks_num == 0 %] green[% END %]" onclick="return send_form_in_background_with_callback(this, {action: 'scan'}, scan_callback );"><i class="uil uil-search"></i> Discover Services</button>
<button class="submit w-44 js-save-btn" name="action" value="save" onClick="saveInitialFormValues()"><i class="uil uil-save"></i> Save Changes</button>
<button class="w-44 js-rescan-btn [% IF checks_num == 0 %] green[% END %]" onclick="return send_form_in_background_with_callback(this, {action: 'scan'}, scan_callback );"><i class="uil uil-search"></i> Discover Services</button>
<button class="w-44 js-save-btn" name="action" value="save" onClick="saveInitialFormValues()"><i class="uil uil-save"></i> Save Changes</button>
</div>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ BEGIN {
plan skip_all => 'local test only' if defined $ENV{'PLACK_TEST_EXTERNALSERVER_URI'};
plan skip_all => 'test skipped' if defined $ENV{'NO_DISABLED_PLUGINS_TEST'};

# enable plugin
`cd plugins/plugins-enabled && ln -s ../plugins-available/core_scheduling .`;

plan tests => 22;
}

Expand Down Expand Up @@ -56,6 +53,3 @@ for my $url (@{$json_hash_pages}) {
my $data = decode_json($page->{'content'});
is(ref $data, 'HASH', "json result is an hash: ".$url);
}

# restore default
`cd plugins/plugins-enabled && rm -f core_scheduling`;
6 changes: 0 additions & 6 deletions plugins/plugins-available/editor/t/controller_editor.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ BEGIN {
plan skip_all => 'local test only' if defined $ENV{'PLACK_TEST_EXTERNALSERVER_URI'};
plan skip_all => 'test skipped' if defined $ENV{'NO_DISABLED_PLUGINS_TEST'};

# enable plugin
`cd plugins/plugins-enabled && ln -s ../plugins-available/editor .`;

plan tests => 30;
}

Expand Down Expand Up @@ -38,6 +35,3 @@ for my $alias (qw/naemon nagios/) {
'like' => ['TextHighlightRules', 'servicegroup_members', 'NaemonHighlightRules'],
);
}

# restore default
`cd plugins/plugins-enabled && rm -f editor`;
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ BEGIN {
plan skip_all => 'local test only' if defined $ENV{'PLACK_TEST_EXTERNALSERVER_URI'};
plan skip_all => 'test skipped' if defined $ENV{'NO_DISABLED_PLUGINS_TEST'};

# enable plugin
`cd plugins/plugins-enabled && ln -s ../plugins-available/node-control .`;

plan tests => 12;
}

Expand All @@ -30,6 +27,3 @@ TestUtils::test_page(
'url' => '/thruk/cgi-bin/node_control.cgi',
'like' => 'Node Control',
);

# restore default
`cd plugins/plugins-enabled && rm -f node-control`;
3 changes: 2 additions & 1 deletion t/800-plugins.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use warnings;
use strict;
use Test::More 0.96;

use Thruk::Base ();
use Thruk::Config 'noautoload';
use Thruk::Utils::IO ();

Expand Down Expand Up @@ -55,7 +56,7 @@ TestUtils::test_command({
cmd => $BIN.' plugin search report -f',
like => ['/reports2/'],
exit => 0,
});
}) unless $filter;

my $failed = {};
for my $p (@{$plugins}) {
Expand Down
6 changes: 4 additions & 2 deletions t/TestUtils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,6 @@ sub test_command {
}

my($prg,$arg) = split(/\s+/, $test->{'cmd'}, 2);
my $t = Test::Cmd->new(prog => $prg, workdir => '') || bail_out_cmd($test, $!);
$test->{'test_cmd'} = $t;

# wait for something?
if(defined $test->{'waitfor'}) {
Expand All @@ -767,6 +765,7 @@ sub test_command {
while($now <= $end) {
alarm(15);
$expr = $waitfor;
my $t = Test::Cmd->new(prog => $prg, workdir => '') || bail_out_cmd($test, $!);
eval {
local $SIG{ALRM} = sub { die "timeout on cmd: ".$test->{'cmd'}."\n" };
$t->run(args => $arg, stdin => $test->{'stdin'});
Expand Down Expand Up @@ -796,6 +795,9 @@ sub test_command {
}
}

my $t = Test::Cmd->new(prog => $prg, workdir => '') || bail_out_cmd($test, $!);
$test->{'test_cmd'} = $t;

alarm(300);
eval {
local $SIG{ALRM} = sub { die "timeout on cmd: ".$test->{'cmd'}."\n" };
Expand Down
29 changes: 27 additions & 2 deletions t/data/800-plugins/01-css.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ for my $dir (@dirs) {

done_testing();

##########################################################
sub check_templates {
my($file) = @_;
return if($filter && $file !~ m%$filter%mx);
Expand Down Expand Up @@ -75,6 +76,7 @@ sub check_templates {
}
}

##########################################################
sub _get_classes {
my($file) = @_;
my $content = Thruk::Utils::IO::read($file);
Expand All @@ -85,24 +87,47 @@ sub _get_classes {
my @cl = split(/[,\>\s]/mx, $cls);
for my $c (@cl) {
$c = Thruk::Base::trim_whitespace($c);

# replace escaped hex numbers used at start of class name, ex.: 2xl -> .\32xl
$c =~ s/\.\\(\d+)/&_dec_class($1)/gemxis;

# replace \[\]
$c =~ s/\\\[(.*?)\\\]/[$1]/mxg;

# remove backslashes, but not before dots
$c =~ s/\\:/__ESCAPED_COLON__/gmx;
$c =~ s/\\\./__ESCAPED_DOT__/gmx;
$c =~ s/\\//gmx;

# trim leading html tag, ex.: DIV.classname
$c =~ s/\\//mx;
$c =~ s/^\w+\././mx;

# remove trailing + label
$c =~ s/\s+\+\s+\w+//mx;
$c =~ s/\s*\+\s*\w+//mx;

# remove [type=..]
$c =~ s/(\w+)\[.*?\]/$1/mx;

# remove :checked
$c =~ s/:checked//mx;

next if $c eq '';
# split by dot to catch multiple classes from ex.: DIV.cls1.cls2
for my $c1 (split/\./mx, $c) {
$c1 = Thruk::Base::trim_whitespace($c1);
$c1 =~ s/:.*$//gmx;
$c1 =~ s/__ESCAPED_DOT__/./gmx;
$c1 =~ s/__ESCAPED_COLON__/:/gmx;
next if $c1 eq '';
$classes->{$c1} = 1;
}
}
}
return($classes);
}

##########################################################
sub _dec_class {
my($hex) = @_;
return(".".pack('H*', $hex));
}

0 comments on commit 58e55e6

Please sign in to comment.