cvs: pear /Net_Monitor/tests alert.phpt alertSMS.phpt custom.phpt diff.phpt down.phpt multiple.phpt reset.phpt working.phpt
| From: | bertrand GUGGER | Date: | Tue, 12 Apr 2005 18:06:56 +0000 |
| Subject: | cvs: pear /Net_Monitor/tests alert.phpt alertSMS.phpt custom.phpt diff.phpt down.phpt multiple.phpt reset.phpt working.phpt | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-31121@lists.php.net to get a copy of this message | ||
toggg Tue Apr 12 14:06:56 2005 EDT
Added files:
/pear/Net_Monitor/tests alert.phpt alertSMS.phpt custom.phpt
diff.phpt down.phpt multiple.phpt
reset.phpt working.phpt
Log:
phpt unit tests for Net_Monitor
http://cvs.php.net/co.php/pear/Net_Monitor/tests/alert.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/alert.phpt +++ pear/Net_Monitor/tests/alert.phpt --TEST-- This file tests connectivity to services known not to be working on example.com - DNS, FTP, and HTTPS and attempts to send an SMTP alert to foo@example.com. --FILE-- <?PHP /** * * This file tests connectivity to services known * not to be working on example.com - DNS, FTP, and HTTPS. * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('example.com'=>array('DNS','FTP','HTTPS')); $alerts = array('foo' => array('SMTP' => 'foo@example.com')); $options = array('state_file' => 'Net_Monitor_TestSuite'); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT-- http://cvs.php.net/co.php/pear/Net_Monitor/tests/alertSMS.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/alertSMS.phpt +++ pear/Net_Monitor/tests/alertSMS.phpt --TEST-- This file tests connectivity to services known not to be working on example.com - DNS, FTP, and HTTPS and attempts to send an SMS alert to 012345678 by clickatem --FILE-- <?PHP /** * * This file tests connectivity to services known * not to be working on example.com - DNS, FTP, and HTTPS. * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('example.com'=>array('DNS','FTP','HTTPS')); $alerts = array('foo' => array('SMS' => '012345678')); $options = array('state_file' => 'Net_Monitor_TestSuite', 'SMS_default' => array( 'SMS_provider' => 'clickatell_http', 'username' => 'pique', 'password' => 'robert', 'api_id' => 'x.y.z' ), 'sms_debug' => true ); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT-- pique by clickatell_http Array ( [from] => Net_Monitor [to] => Array ( [0] => 012345678 ) ) Array ( [password] => robert [api_id] => x.y.z [user] => pique ) http://cvs.php.net/co.php/pear/Net_Monitor/tests/custom.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/custom.phpt +++ pear/Net_Monitor/tests/custom.phpt --TEST-- This file tests connectivity to services known not to be working on example.com and formats output using a custom, user-specified format. --FILE-- <?PHP /** * * This file tests connectivity to services known * not to be working on example.com and formats output * using a custom, user-specified format. * * Expected output to STDOUT is: * <pre> * Got no response from example.com checking DNS - code 0 * Got Connection to host failed from example.com checking FTP - code 0 * </pre> * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('example.com'=>array('DNS','FTP')); $alerts = array(); //use this to output to STDOUT $options = array('state_file' => 'Net_Monitor_TestSuite', 'subject_line' => 'Custom subject','alert_line' => 'Got %m from %h checking %s - code %c'); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT-- Got no response from example.com checking DNS - code 0 Got Connection to host failed from example.com checking FTP - code 0 http://cvs.php.net/co.php/pear/Net_Monitor/tests/diff.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/diff.phpt +++ pear/Net_Monitor/tests/diff.phpt --TEST-- This file tests the alerting mechanism by simulating a variety of circumstances where the previous state and current state differ in some aspects and are the same in others. This file also tests the notify_ok and notify_change options in relation to these circumstances. --FILE-- <?PHP /** * This file tests the alerting mechanism by simulating a variety of * circumstances where the previous state and current state differ * in some aspects and are the same in others. This file also tests the * notify_ok and notify_change options in relation to these circumstances. * See comments throughout the file for expected outputs. * * @package Net_Monitor */ /** * */ require_once 'Net/Monitor.php'; error_reporting(E_ALL); $primary = array( 'foo.example.com'=>array( 'SMTP'=>array( 0, 'Operation timed out' ) ) , 'bar.example.com'=>array( 'HTTP'=>array( 404, 'File Not Found' ) ) ); $secondary = array( 'foo.example.com'=>array( 'DNS'=>array(0, 'Operation timed out') , 'SMTP'=>array(0, 'Operation timed out') ) , 'bar.example.com'=>array( 'HTTP'=>array(0, 'Operation timed out') ) ); /* * In this scenario: * foo.example.com SMTP is still down (no notice) * foo.example.com DNS came back up (send notice) * bar.example.com HTTP changed from down to 404 (send notice) */ $monitor = new Net_Monitor(); $monitor->_results = $primary; $result = $monitor->stateDiff($secondary); print_r($result); /* Should produce: * * Array * ( * [0] => Array * ( * [host] => bar.example.com * [service] => HTTP * [message] => File Not Found * [code] => 404 * ) * * [1] => Array * ( * [host] => foo.example.com * [service] => DNS * [message] => OK * [code] => 200 * ) * ) */ $monitor->setOptions(array('notify_ok' => 0)); $monitor->_results = $primary; $result = $monitor->stateDiff($secondary); print_r($result); /* Should produce: * * Array * ( * [0] => Array * ( * [host] => bar.example.com * [service] => HTTP * [message] => File Not Found * [code] => 404 * ) * ) */ $monitor->setOptions(array('notify_ok' => 1, 'notify_change' => 0)); $monitor->_results = $primary; $result = $monitor->stateDiff($secondary); print_r($result); /* Should produce: * * Array * ( * [0] => Array * ( * [host] => foo.example.com * [service] => DNS * [message] => OK * [code] => 200 * ) * ) */ ?> --EXPECT-- Array ( [bar.example.com] => Array ( [HTTP] => Array ( [0] => 404 [1] => File Not Found ) ) [foo.example.com] => Array ( [DNS] => Array ( [0] => 200 [1] => Operation timed out ) ) ) Array ( [bar.example.com] => Array ( [HTTP] => Array ( [0] => 404 [1] => File Not Found ) ) ) Array ( [foo.example.com] => Array ( [DNS] => Array ( [0] => 200 [1] => Operation timed out ) ) ) http://cvs.php.net/co.php/pear/Net_Monitor/tests/down.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/down.phpt +++ pear/Net_Monitor/tests/down.phpt --TEST-- This file tests connectivity to services known not to be working on example.com - DNS, FTP, and HTTPS. --FILE-- <?PHP /** * * This file tests connectivity to services known * not to be working on example.com - DNS, FTP, and HTTPS. * * Expected output to STDOUT is: * <pre> * example.com: DNS: no response * example.com: FTP: Connection to host failed * example.com: HTTPS: Operation timed out * </pre> * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('example.com'=>array('DNS','FTP','HTTPS')); $alerts = array(); //use this to output to STDOUT $options = array('state_file' => 'Net_Monitor_TestSuite'); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT-- example.com: DNS: no response example.com: FTP: Connection to host failed example.com: HTTPS: Connection refused http://cvs.php.net/co.php/pear/Net_Monitor/tests/multiple.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/multiple.phpt +++ pear/Net_Monitor/tests/multiple.phpt --TEST-- This file tests connectivity to known working services on php.net - SMTP and HTTP and pear.php.net - HTTP. --FILE-- <?PHP /** * This file tests connectivity to known working services on php.net * - SMTP and HTTP and pear.php.net - HTTP * * Expected output to STDOUT is blank. * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('www.php.net'=>array('SMTP','HTTP'),'pear.php.net'=>array('HTTP')); $alerts = array(); //use this to output to STDOUT $options = array('state_file' => 'Net_Monitor_TestSuite'); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT-- http://cvs.php.net/co.php/pear/Net_Monitor/tests/reset.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/reset.phpt +++ pear/Net_Monitor/tests/reset.phpt --TEST-- This file tests services known not to be operating at example.com. This file also resets one of the failed states so that the warning is sent for this service (DNS) a second time. --FILE-- <?PHP /** * * This file tests services known not to be operating at example.com * This file also resets one of the failed states so that the warning * is sent for this service (DNS) a second time. * * Expected output to STDOUT is: * <pre> * example.com: DNS: no response * example.com: FTP: Connection to host failed * example.com: DNS: no response * </pre> * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('example.com'=>array('DNS','FTP')); $alerts = array(); $options = array('state_file' => 'Net_Monitor_TestSuite'); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetHostState('example.com','DNS'); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT-- example.com: DNS: no response example.com: FTP: Connection to host failed example.com: DNS: no response http://cvs.php.net/co.php/pear/Net_Monitor/tests/working.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/working.phpt +++ pear/Net_Monitor/tests/working.phpt --TEST-- This file tests connectivity to known working services on php.net - SMTP and HTTP. --FILE-- <?PHP /** * This file tests connectivity to known working services on php.net * - SMTP and HTTP. * * Expected output to STDOUT is blank. * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('www.php.net'=>array('SMTP','HTTP')); $alerts = array(); //use this to output to STDOUT $options = array('state_file' => 'Net_Monitor_TestSuite'); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT--
http://cvs.php.net/co.php/pear/Net_Monitor/tests/alert.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/alert.phpt +++ pear/Net_Monitor/tests/alert.phpt --TEST-- This file tests connectivity to services known not to be working on example.com - DNS, FTP, and HTTPS and attempts to send an SMTP alert to foo@example.com. --FILE-- <?PHP /** * * This file tests connectivity to services known * not to be working on example.com - DNS, FTP, and HTTPS. * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('example.com'=>array('DNS','FTP','HTTPS')); $alerts = array('foo' => array('SMTP' => 'foo@example.com')); $options = array('state_file' => 'Net_Monitor_TestSuite'); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT-- http://cvs.php.net/co.php/pear/Net_Monitor/tests/alertSMS.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/alertSMS.phpt +++ pear/Net_Monitor/tests/alertSMS.phpt --TEST-- This file tests connectivity to services known not to be working on example.com - DNS, FTP, and HTTPS and attempts to send an SMS alert to 012345678 by clickatem --FILE-- <?PHP /** * * This file tests connectivity to services known * not to be working on example.com - DNS, FTP, and HTTPS. * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('example.com'=>array('DNS','FTP','HTTPS')); $alerts = array('foo' => array('SMS' => '012345678')); $options = array('state_file' => 'Net_Monitor_TestSuite', 'SMS_default' => array( 'SMS_provider' => 'clickatell_http', 'username' => 'pique', 'password' => 'robert', 'api_id' => 'x.y.z' ), 'sms_debug' => true ); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT-- pique by clickatell_http Array ( [from] => Net_Monitor [to] => Array ( [0] => 012345678 ) ) Array ( [password] => robert [api_id] => x.y.z [user] => pique ) http://cvs.php.net/co.php/pear/Net_Monitor/tests/custom.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/custom.phpt +++ pear/Net_Monitor/tests/custom.phpt --TEST-- This file tests connectivity to services known not to be working on example.com and formats output using a custom, user-specified format. --FILE-- <?PHP /** * * This file tests connectivity to services known * not to be working on example.com and formats output * using a custom, user-specified format. * * Expected output to STDOUT is: * <pre> * Got no response from example.com checking DNS - code 0 * Got Connection to host failed from example.com checking FTP - code 0 * </pre> * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('example.com'=>array('DNS','FTP')); $alerts = array(); //use this to output to STDOUT $options = array('state_file' => 'Net_Monitor_TestSuite', 'subject_line' => 'Custom subject','alert_line' => 'Got %m from %h checking %s - code %c'); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT-- Got no response from example.com checking DNS - code 0 Got Connection to host failed from example.com checking FTP - code 0 http://cvs.php.net/co.php/pear/Net_Monitor/tests/diff.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/diff.phpt +++ pear/Net_Monitor/tests/diff.phpt --TEST-- This file tests the alerting mechanism by simulating a variety of circumstances where the previous state and current state differ in some aspects and are the same in others. This file also tests the notify_ok and notify_change options in relation to these circumstances. --FILE-- <?PHP /** * This file tests the alerting mechanism by simulating a variety of * circumstances where the previous state and current state differ * in some aspects and are the same in others. This file also tests the * notify_ok and notify_change options in relation to these circumstances. * See comments throughout the file for expected outputs. * * @package Net_Monitor */ /** * */ require_once 'Net/Monitor.php'; error_reporting(E_ALL); $primary = array( 'foo.example.com'=>array( 'SMTP'=>array( 0, 'Operation timed out' ) ) , 'bar.example.com'=>array( 'HTTP'=>array( 404, 'File Not Found' ) ) ); $secondary = array( 'foo.example.com'=>array( 'DNS'=>array(0, 'Operation timed out') , 'SMTP'=>array(0, 'Operation timed out') ) , 'bar.example.com'=>array( 'HTTP'=>array(0, 'Operation timed out') ) ); /* * In this scenario: * foo.example.com SMTP is still down (no notice) * foo.example.com DNS came back up (send notice) * bar.example.com HTTP changed from down to 404 (send notice) */ $monitor = new Net_Monitor(); $monitor->_results = $primary; $result = $monitor->stateDiff($secondary); print_r($result); /* Should produce: * * Array * ( * [0] => Array * ( * [host] => bar.example.com * [service] => HTTP * [message] => File Not Found * [code] => 404 * ) * * [1] => Array * ( * [host] => foo.example.com * [service] => DNS * [message] => OK * [code] => 200 * ) * ) */ $monitor->setOptions(array('notify_ok' => 0)); $monitor->_results = $primary; $result = $monitor->stateDiff($secondary); print_r($result); /* Should produce: * * Array * ( * [0] => Array * ( * [host] => bar.example.com * [service] => HTTP * [message] => File Not Found * [code] => 404 * ) * ) */ $monitor->setOptions(array('notify_ok' => 1, 'notify_change' => 0)); $monitor->_results = $primary; $result = $monitor->stateDiff($secondary); print_r($result); /* Should produce: * * Array * ( * [0] => Array * ( * [host] => foo.example.com * [service] => DNS * [message] => OK * [code] => 200 * ) * ) */ ?> --EXPECT-- Array ( [bar.example.com] => Array ( [HTTP] => Array ( [0] => 404 [1] => File Not Found ) ) [foo.example.com] => Array ( [DNS] => Array ( [0] => 200 [1] => Operation timed out ) ) ) Array ( [bar.example.com] => Array ( [HTTP] => Array ( [0] => 404 [1] => File Not Found ) ) ) Array ( [foo.example.com] => Array ( [DNS] => Array ( [0] => 200 [1] => Operation timed out ) ) ) http://cvs.php.net/co.php/pear/Net_Monitor/tests/down.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/down.phpt +++ pear/Net_Monitor/tests/down.phpt --TEST-- This file tests connectivity to services known not to be working on example.com - DNS, FTP, and HTTPS. --FILE-- <?PHP /** * * This file tests connectivity to services known * not to be working on example.com - DNS, FTP, and HTTPS. * * Expected output to STDOUT is: * <pre> * example.com: DNS: no response * example.com: FTP: Connection to host failed * example.com: HTTPS: Operation timed out * </pre> * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('example.com'=>array('DNS','FTP','HTTPS')); $alerts = array(); //use this to output to STDOUT $options = array('state_file' => 'Net_Monitor_TestSuite'); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT-- example.com: DNS: no response example.com: FTP: Connection to host failed example.com: HTTPS: Connection refused http://cvs.php.net/co.php/pear/Net_Monitor/tests/multiple.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/multiple.phpt +++ pear/Net_Monitor/tests/multiple.phpt --TEST-- This file tests connectivity to known working services on php.net - SMTP and HTTP and pear.php.net - HTTP. --FILE-- <?PHP /** * This file tests connectivity to known working services on php.net * - SMTP and HTTP and pear.php.net - HTTP * * Expected output to STDOUT is blank. * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('www.php.net'=>array('SMTP','HTTP'),'pear.php.net'=>array('HTTP')); $alerts = array(); //use this to output to STDOUT $options = array('state_file' => 'Net_Monitor_TestSuite'); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT-- http://cvs.php.net/co.php/pear/Net_Monitor/tests/reset.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/reset.phpt +++ pear/Net_Monitor/tests/reset.phpt --TEST-- This file tests services known not to be operating at example.com. This file also resets one of the failed states so that the warning is sent for this service (DNS) a second time. --FILE-- <?PHP /** * * This file tests services known not to be operating at example.com * This file also resets one of the failed states so that the warning * is sent for this service (DNS) a second time. * * Expected output to STDOUT is: * <pre> * example.com: DNS: no response * example.com: FTP: Connection to host failed * example.com: DNS: no response * </pre> * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('example.com'=>array('DNS','FTP')); $alerts = array(); $options = array('state_file' => 'Net_Monitor_TestSuite'); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetHostState('example.com','DNS'); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT-- example.com: DNS: no response example.com: FTP: Connection to host failed example.com: DNS: no response http://cvs.php.net/co.php/pear/Net_Monitor/tests/working.phpt?r=1.1&p=1 Index: pear/Net_Monitor/tests/working.phpt +++ pear/Net_Monitor/tests/working.phpt --TEST-- This file tests connectivity to known working services on php.net - SMTP and HTTP. --FILE-- <?PHP /** * This file tests connectivity to known working services on php.net * - SMTP and HTTP. * * Expected output to STDOUT is blank. * * @package Net_Monitor */ /** * */ require_once('Net/Monitor.php'); error_reporting(E_ALL); $services = array('www.php.net'=>array('SMTP','HTTP')); $alerts = array(); //use this to output to STDOUT $options = array('state_file' => 'Net_Monitor_TestSuite'); $monitor = new Net_Monitor($services,$alerts,$options); $monitor->resetState(); $monitor->checkAll(); $monitor->resetState(); ?> --EXPECT--