Skip to content

Commit

Permalink
test: add scenario with lots of utf8 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Apr 19, 2024
1 parent d1bca1c commit d7fcec0
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 0 deletions.
12 changes: 12 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -2604,6 +2604,18 @@ t/scenarios/site_menu_multi_tier_e2e/omd/playbook.yml
t/scenarios/site_menu_multi_tier_e2e/omd/test.cfg
t/scenarios/site_menu_multi_tier_e2e/thruk.conf
t/scenarios/site_menu_multi_tier_e2e/thruk_local.conf
t/scenarios/utf8/docker-compose.yml
t/scenarios/utf8/Makefile
t/scenarios/utf8/omd/Dockerfile
t/scenarios/utf8/omd/playbook.yml
t/scenarios/utf8/omd/test.cfg
t/scenarios/utf8/t/000-init.t
t/scenarios/utf8/t/300-controller_extinfo.t
t/scenarios/utf8/t/300-controller_status.t
t/scenarios/utf8/t/300-controller_tac.t
t/scenarios/utf8/t/local/015-excel-export.t
t/scenarios/utf8/thruk.conf
t/scenarios/utf8/thruk_local.conf
t/test_request
t/TestUtils.pm
t/timed_test.sh
Expand Down
15 changes: 15 additions & 0 deletions lib/Thruk/Utils/IO.pm
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ sub read {

##############################################

=head2 read_decoded
read_decoded($path)
read file and return decoded content
=cut

sub read_decoded {
require Thruk::Utils::Encode;
return Thruk::Utils::Encode::decode_any(&read(@_));
}

##############################################

=head2 saferead
saferead($path)
Expand Down
8 changes: 8 additions & 0 deletions t/scenarios/utf8/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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

11 changes: 11 additions & 0 deletions t/scenarios/utf8/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
omd:
build: omd/
platform: linux/amd64
ports:
- "127.0.0.3:60080:80"
- "127.0.0.3:60443:443"
- "127.0.0.3:60557:6557"
volumes:
- ../../../:/thruk:ro
- .:/test:ro
5 changes: 5 additions & 0 deletions t/scenarios/utf8/omd/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM local/thruk-labs-rocky:nightly

COPY playbook.yml /root/ansible_dropin/
ENV ANSIBLE_ROLES_PATH /thruk/t/scenarios/_common/ansible/roles
COPY test.cfg /root/
37 changes: 37 additions & 0 deletions t/scenarios/utf8/omd/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
- hosts: all
roles:
- role: common
- role: thruk_developer
- role: local_tests
tasks:
- name: "yum install libreoffix"
include_role:
name: yum_apt_retry
vars:
package:
- libreoffice-calc

- name: "omd config change"
shell: "omd config demo change"
args:
stdin: |
APACHE_MODE=own
LIVESTATUS_TCP=on
- name: "create secret.key"
shell: echo "testkey" > /omd/sites/demo/var/thruk/secret.key
- name: "set permissions on secret.key"
file:
path: /omd/sites/demo/var/thruk/secret.key
mode: 0600
owner: demo
group: demo

- name: "copy test.cfg"
copy:
src: /root/test.cfg
dest: /omd/sites/demo/etc/naemon/conf.d/test.cfg
owner: demo
group: demo

40 changes: 40 additions & 0 deletions t/scenarios/utf8/omd/test.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
define servicegroup {
servicegroup_name Äll Service Checks
alias Äll Service Checks
members öäü߀,öäü߀
}

define hostgroup {
hostgroup_name Äll Hösts
alias Just all hösts
members *
}

define host {
host_name öäü߀
alias öäü߀
use generic-host
contact_groups töst
}

define service {
service_description öäü߀
host_name öäü߀
use generic-service
check_command check_dummy!0!"öäü߀"
}

define contactgroup {
contactgroup_name töst
alias töst group
members cöntäct
}

define contact {
contact_name cöntäct
alias cöntäct
use generic-contact
can_submit_commands 1
email mäil@localhost
}

29 changes: 29 additions & 0 deletions t/scenarios/utf8/t/000-init.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use warnings;
use strict;
use Test::More;

BEGIN {
plan tests => 17;

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

###########################################################
my($host,$service) = TestUtils::get_test_service();

###########################################################
# force reschedule so we get some performance data
TestUtils::test_page(
url => '/thruk/r/hosts/'.$host.'/cmd/schedule_forced_host_check',
post => { start_time => 'now' },
like => ['Command successfully submitted'],
);
TestUtils::test_page(
url => '/thruk/r/services/'.$host.'/'.$service.'/cmd/schedule_forced_svc_check',
post => { start_time => 'now' },
like => ['Command successfully submitted'],
);

###########################################################
1 change: 1 addition & 0 deletions t/scenarios/utf8/t/300-controller_extinfo.t
1 change: 1 addition & 0 deletions t/scenarios/utf8/t/300-controller_status.t
1 change: 1 addition & 0 deletions t/scenarios/utf8/t/300-controller_tac.t
70 changes: 70 additions & 0 deletions t/scenarios/utf8/t/local/015-excel-export.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use warnings;
use strict;
use Test::More;
use utf8;

plan tests => 27;

BEGIN {
$ENV{'THRUK_AUTHOR'} = 1;
use lib('t');
require TestUtils;
import TestUtils;
}

use 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");

###########################################################
# add downtime with utf8 characters
TestUtils::test_command({
cmd => '/usr/bin/env thruk r -d comment_data=döwnäü߀ -d end_time=+3m /hosts/öäü߀/cmd/schedule_host_downtime',
like => ['/Command successfully submitted/'],
});

###########################################################
# excel export service list
TestUtils::test_command({
cmd => '/usr/bin/env bash -c \'thruk url "status.cgi?style=detail&view_mode=xls&columns=Hostname&columns=IP&columns=Service&columns=Comments" >/tmp/test.xls\'',
like => ['/^$/'],
});

###########################################################
# check excel file
TestUtils::test_command({
cmd => '/usr/bin/env file /tmp/test.xls',
like => ['/\/tmp\/test.xls: CDFV2 Microsoft Excel/'],
});

###########################################################
# convert to csv
TestUtils::test_command({
cmd => '/usr/bin/env libreoffice --headless --convert-to "csv" --infilter="CSV:44,34,UTF-8" --outdir /tmp/ /tmp/test.xls',
like => ['/convert/', '/StarCalc/'],
});

###########################################################
# check excel file
TestUtils::test_command({
cmd => '/usr/bin/env file /tmp/test.csv',
like => ['/\/tmp\/test.csv: UTF-8 Unicode text/'],
});

###########################################################
# does the csv contain all information?
my $content = Thruk::Utils::IO::read_decoded("/tmp/test.csv");
like($content, '/öäü߀/', 'csv file contains hostname');
like($content, '/döwnäü߀/', 'csv contains downtime comment');

###########################################################
# cleanup
unlink("/tmp/test.xls");
#unlink("/tmp/test.csv");

###########################################################
1 change: 1 addition & 0 deletions t/scenarios/utf8/thruk.conf
12 changes: 12 additions & 0 deletions t/scenarios/utf8/thruk_local.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Component Thruk::Backend>
<peer>
name = naemon
id = abcd
type = livestatus
<options>
peer = 127.0.0.3:60557
</options>
</peer>
</Component>

slow_page_log_threshold = 45

0 comments on commit d7fcec0

Please sign in to comment.