Test::Net::Connect - Test::Builder based tests for network connectivity
Version 0.03
use Test::Net::Connect tests => 3; connect_ok({ host => 'smtp.example.com', port => 25, proto => 'tcp' }, 'Check tcp://smtp.example.com:25'); # proto defaults to 'tcp', the test name can be omitted, and the # port can be appended to the host name connect_ok({ host => 'smtp.example.com:25' }); connect_not_ok({ host => 'localhost:23' }, 'Telnet connections should not be accepted locally');
Test::Net::Connect automatically exports connect_ok() and connect_not_ok() to make it easier to test whether or not a network connection can be made from this host to a port on another host using TCP or UDP.
connect_ok()
connect_not_ok()
Test::Net::Connect uses Test::Builder, so plays nicely with Test::Simple, Test::More, and other Test::Builder based modules.
connect_ok() tests that a connection to a host, given in $spec, can be made.
$spec
The specification is a hashref that contains one or more keys. Valid keys are host, port, and proto. Each value associated with the key is the value that entry is supposed to have.
host
port
proto
Specifies the hostname or IP address to connect to. If a hostname is given then the A records for that host will be retrieved and connections will be made to all the A records in turn. If any of them fail then the test fails.
host is mandatory.
Specifies the port to connect to. The port may also be specified by appending a colon : and the port number to the host value. If this is done then port is optional, otherwise port is mandatory.
:
The protocol to use. tcp and udp are the only valid values. This key is optional, and defaults to tcp if it is not specified.
tcp
udp
The $test_name is optional. If it is not present then a sensible one is generated following the form
$test_name
Connecting to $proto://$host:$port
connect_not_ok() tests that a connection to a host, given in $spec, can not be made.
The arguments are handled in the same manner as for connect_ok().
NOTE: connect_not_ok() will fail (not ok) if the given host is not in the DNS. DNS.
not ok
Verify that port 25 can be reached on all the A records for smtp.example.com.
smtp.example.com
connect_ok({ host => 'smtp.example.com', port => 25, proto => 'tcp' }, "Checking mail to smtp.example.com");
Do the same thing, but shorter.
connect_ok({ host => 'smtp.example.com:25' });
Verify that the local SSH daemon is responding.
connect_ok({ host => '127.0.0.1:22' });
Verify that the host www.example.com is not running a server on port 80.
connect_not_ok({ host => 'www.example.com:80' });
Test::Simple, Test::Builder, IO::Socket::INET.
Nik Clayton, nik@FreeBSD.org
Please report any bugs or feature requests to bug-test-net-connect@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Net-Connect. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-test-net-connect@rt.cpan.org
Copyright (c) 2005 Nik Clayton All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
To install Test::Net::Connect, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Net::Connect
CPAN shell
perl -MCPAN -e shell install Test::Net::Connect
For more information on module installation, please visit the detailed CPAN module installation guide.