diff --git a/tests/00_start.php b/tests/00_start.php index 416a2bd09791082c813d053dfac7b04d89d2da49..e36f20093f57ba912ddb947cbb48f692e2ba1918 100755 --- a/tests/00_start.php +++ b/tests/00_start.php @@ -5,7 +5,7 @@ require_once __DIR__.'/../inc_functions.php'; require_once __DIR__.'/../inc_vars.php'; $AMCLI??=__DIR__.'/../src/amcli.php'; -$AMCLI=__DIR__.'/../built_packages/amcli'; +// $AMCLI=__DIR__.'/../built_packages/amcli'; _chdir(__DIR__); diff --git a/tests/100_set_metadata.php b/tests/100_set_metadata.php index faad586998c14e964fac8b263788846bb7f3be0b..edbdd63520c72aceccea86137a9bbf123e25ad8b 100644 --- a/tests/100_set_metadata.php +++ b/tests/100_set_metadata.php @@ -5,7 +5,7 @@ echo " WHAT: Set application metadata "; -$sInifile=__DIR__."/configs/metadata.ini"; +$sInifile="configs/metadata.ini"; // -------------------------------------------------------------------- // FUNCTION @@ -52,11 +52,7 @@ foreach($aIni["notifications"]["email"]??[] as $sEmail){ _ok(); echo "\n"; } -foreach($aIni["notifications"]["slack"]??[] as $sValue){ - $aArray = json_decode($sValue, 1); - $sChannel = array_keys($aArray)[0]; - $sWebhook = array_values($aArray)[0]; - +foreach($aIni["notifications"]["slack"]??[] as $sChannel => $sWebhook){ echo "Check Slack '$sChannel'\n"; compare_strings("Check Slack '$sChannel'", $sWebhook, $aResponse["meta"]["notifications"]['slack'][$sChannel]??''); } diff --git a/tests/300_dynamic_value.php b/tests/300_dynamic_value.php new file mode 100644 index 0000000000000000000000000000000000000000..8e2936ffc3317b723bdf96ef3eb48b1c241ab7e0 --- /dev/null +++ b/tests/300_dynamic_value.php @@ -0,0 +1,31 @@ +#!/usr/bin/env php +<?php + +echo " +WHAT: Test dynamic ini value +"; + +$sInifile="configs/dynamic_values.ini"; + +echo "--- Content of ini file:\n" + .preg_replace( + "/.*(params.*\n)\n.*/s", + "$1", + file_get_contents($sInifile) + )."\n" + ; +$aIni=parse_ini_file($sInifile, 1); + +echo "--- parsed ini value for the check:\n"; +print_r($aIni["hello plugin"]['params']); +$sMessage=$aIni["hello plugin"]['params']['message']??false; +if($sMessage) +{ + if(strstr($sMessage, "\$\{")){ + _abort('in params -> message the variable $\{USER\} was not replaced'); + } else { + _ok('in params -> message the variable $\{USER\} was replaced'); + } +} else { + _abort("Message param was not found."); +} diff --git a/tests/configs/dynamic_values.ini b/tests/configs/dynamic_values.ini new file mode 100644 index 0000000000000000000000000000000000000000..dab4cb4df805910896e2f12c7e00942c9063b1d0 --- /dev/null +++ b/tests/configs/dynamic_values.ini @@ -0,0 +1,24 @@ +; ======================================================================= +; +; APPMONITOR CLI CLIENT +; +; to understand the entries of metadata see JSON in +; <https://os-docs.iml.unibe.ch/appmonitor/Client/Description_of_response.html> +; +; for the checks see its parameters +; <https://os-docs.iml.unibe.ch/appmonitor/PHP_client/Plugins/Checks/index.html> +; +; ======================================================================= + +; ----------------------------------------------------------------------- +; CHECKS +; ----------------------------------------------------------------------- + +["hello plugin"] +description='I test a dynamic value USER = ${USER}' +function="hello" + +; to have dynamic values in params do not use JSON but array syntax +params[message]="Here is ${USER}" + +; ----------------------------------------------------------------------- diff --git a/tests/configs/metadata.ini b/tests/configs/metadata.ini index 09097225a71d98ed07ae1b4d7cf449fa6d8e25eb..d81e6f8aa1a81311c128ecce15b8f9ebda540ed7 100644 --- a/tests/configs/metadata.ini +++ b/tests/configs/metadata.ini @@ -28,7 +28,7 @@ email[]="webmaster@example.com" ; for slack use the following format ; <channelname> + comma + <webhook url> -slack[]='{ "#support-channel": "https://hooks.slack.com/services/XXXXXX/YYYYYY/ZZZZZ" }' +slack["#support-channel2"]="https://hooks.slack.com/services/XXXXXX/YYYYYY/ZZZZZ" ; -----------------------------------------------------------------------