Skip to content

Commit

Permalink
test: add test case for custom vars in details page
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Jun 5, 2024
1 parent 0e3c0e0 commit 0a9fb4c
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,7 @@ t/scenarios/backend_naemon/omd/test.cfg
t/scenarios/backend_naemon/t/300-controller_extinfo.t
t/scenarios/backend_naemon/t/300-controller_status.t
t/scenarios/backend_naemon/t/300-controller_tac.t
t/scenarios/backend_naemon/t/local/010-custom_vars_default_view.t
t/scenarios/backend_naemon/thruk.conf
t/scenarios/backend_naemon/thruk_local.conf
t/scenarios/backend_nagios4/docker-compose.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ if [ "x$1" != "x" ]; then
shift
fi

# make sure we have test files
if ! ls $TESTS >/dev/null 2>&1; then
echo "no test files found for $TESTS"
exit 1
fi

THRUK_CONFIG=$(pwd)/etc/thruk \
TEST_AUTHOR=1 \
PERL_DL_NONLAZY=1 \
Expand Down
6 changes: 6 additions & 0 deletions t/scenarios/backend_naemon/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
include ../_common/Makefile.common

extra_test:
docker compose exec $(DOCKER_COMPOSE_TTY) --user root omd sudo -iu demo /usr/local/bin/local_test.sh 0

extra_test_verbose:
docker compose exec $(DOCKER_COMPOSE_TTY) --user root omd sudo -iu demo /usr/local/bin/local_test.sh 1
1 change: 1 addition & 0 deletions t/scenarios/backend_naemon/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ services:
- "127.0.0.3:60557:6557"
volumes:
- ../../../:/thruk:ro
- ./:/test:ro
1 change: 1 addition & 0 deletions t/scenarios/backend_naemon/omd/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- hosts: all
roles:
- role: common
- role: local_tests
- role: thruk_developer
- role: test-config-generator
tasks:
Expand Down
28 changes: 28 additions & 0 deletions t/scenarios/backend_naemon/omd/test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,31 @@ define hostgroup {
members *
}

define host {
host_name test
alias test host
address 127.0.0.2
use host-pnp,generic-host
contact_groups example
_TEST test var hst
__IMPACT dbl underscore hst
}

define service {
service_description Load
host_name test
use srv-pnp,generic-service
check_command check_local_load!5,5,5!10,10,10
contact_groups example
}

define service {
service_description Ping
host_name test
use srv-pnp,generic-service
check_command check_ping!1000,20%!2000,30%
contact_groups example
_TEST test var svc
__IMPACT dbl underscore svc
}

59 changes: 59 additions & 0 deletions t/scenarios/backend_naemon/t/local/010-custom_vars_default_view.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use warnings;
use strict;
use Test::More;

BEGIN {
use lib('t');
require TestUtils;
import TestUtils;
}

plan tests => 35;

$ENV{'THRUK_TEST_AUTH'} = 'omdadmin:omd';
$ENV{'PLACK_TEST_EXTERNALSERVER_URI'} = 'http://127.0.0.1/demo';

use_ok("Thruk::Utils::IO");

###########################################################
# verify that we use the correct thruk binary
TestUtils::test_command({
cmd => '/bin/bash -c "type thruk"',
like => ['/\/thruk\/script\/thruk/'],
}) or BAIL_OUT("wrong thruk path");

###########################################################
# thruk roles
TestUtils::test_command({
cmd => '/usr/bin/env thruk user.cgi',
like => ['/>User<.*?>\(cli\)</', '/authorized_for_admin/'],
});

###########################################################
# create example config and reload apache
my $rc = Thruk::Utils::IO::write("etc/thruk/thruk_local.d/custom_var.conf", '
show_custom_vars = _TEST
show_custom_vars = __IMPACT
default_service_columns = host_name,description,state,last_check,cust__IMPACT:ImpactAlias,cust_TEST:TestAlias
');
ok($rc, 'etc/thruk/thruk_local.d/custom_var.conf');
TestUtils::test_command({
cmd => '/usr/bin/env omd reload apache',
like => ['/Reloading apache.*OK/'],
});
sleep(3);

###########################################################
TestUtils::test_page(
url => '/thruk/cgi-bin/status.cgi?host=test',
like => ['ImpactAlias', 'TestAlias', 'dbl underscore hst', 'dbl underscore svc', 'test var hst', 'test var svc'],
);

###########################################################
# cleanup test config
unlink("etc/thruk/thruk_local.d/custom_var.conf");
TestUtils::test_command({
cmd => '/usr/bin/env omd reload apache',
like => ['/Reloading apache.*OK/'],
});
sleep(3);

0 comments on commit 0a9fb4c

Please sign in to comment.