NAME
Test::Net::LDAP - A Net::LDAP subclass for testing
VERSION
Version 0.05
SYNOPSIS
Basic testing utility
use Test::More tests => 1;
use Test::Net::LDAP;
# Create an object, just like Net::LDAP->new()
my $ldap = Test::Net::LDAP->new(...);
# Same as $ldap->search(), testing the result to see if it is success
my $search = $ldap->search_ok(...search args...);
Mocking (See Test::Net::LDAP::Mock)
use Test::More tests => 1;
use Test::Net::LDAP::Util qw(ldap_mockify);
ldap_mockify {
# Net::LDAP->new() will invoke Test::Net::LDAP::Mock->new()
my $ldap = Net::LDAP->new('ldap.example.com');
# Add entries to in-memory data tree
$ldap->add('uid=user1, ou=users, dc=example, dc=com');
$ldap->add('uid=user2, ou=users, dc=example, dc=com');
# Test your application
ok my_application_routine();
};
DESCRIPTION
This module provides some testing methods for LDAP operations, such as search
, add
, and modify
, where each method is suffixed with either _ok
or _is
.
Test::Net::LDAP
is a subclass of Net::LDAP
, so all the methods defined for Net::LDAP
are available in addition to search_ok
, add_is
, etc.
See Test::Net::LDAP::Mock for in-memory testing with fake data, without connecting to the real LDAP servers.
See Test::Net::LDAP::Util for some helper subroutines.
METHODS
new
Creates a new object. The parameters are the same as Net::LDAP::new
.
my $ldap = Test::Net::LDAP->new('ldap.example.com');
search_ok
Available methods: search_ok
, compare_ok
, add_ok
, modify_ok
, delete_ok
, moddn_ok
, bind_ok
, unbind_ok
, abandon_ok
Synopsis:
$ldap->search_ok(@params);
$ldap->search_ok(\@params, $name);
Invokes the corresponding method with @params
passed as arguments, and tests the result to see if the code is LDAP_SUCCESS
.
Alternatively, @params
can be given as an array ref, so that the second argument $name
is specified as the test name.
$name
is an optional test name, and if it is omitted, the test name is automatically configured based on $method
and @params
.
my $search = $ldap->search_ok(
base => 'dc=example, dc=com', scope => 'sub', filter => '(cn=*)',
);
my $search = $ldap->search_ok(
[base => 'dc=example, dc=com', scope => 'sub', filter => '(cn=*)'],
'Testing search (cn=*)'
);
search_is
Available methods: search_is
, compare_is
, add_is
, modify_is
, delete_is
, moddn_is
, bind_is
, unbind_is
, abandon_is
Synopsis:
$ldap->search_is(\@params, $expect, $name);
Invokes the corresponding method with @params
passed as arguments, and tests the result to see if the code is equal to $expect
.
$expect
can be a result code such as LDAP_NO_SUCH_OBJECT
or an object of Net::LDAP::Message
returned by LDAP operations.
$name
is an optional test name, and if it is omitted, the test name is automatically configured based on $method
and @params
.
use Net::LDAP::Constant qw(LDAP_ALREADY_EXISTS);
my $mesg = $ldap->add_is(
['uid=duplicate, dc=example, dc=com'],
LDAP_ALREADY_EXISTS
);
method_ok
$ldap->method_ok($method, @params);
$ldap->method_ok($method, \@params, $name);
Invokes the method as $ldap->$method(@params)
and tests the result to see if the code is LDAP_SUCCESS
.
$name
is an optional test name, and if it is omitted, the test name is automatically configured based on $method
and @params
.
method_is
$ldap->method_is($method, \@params, $expect, $name);
Invokes the method as $ldap->$method(@params)
and tests the result to see if the code is equal to $expect
.
$expect
can be a result code such as LDAP_NO_SUCH_OBJECT
or an object of Net::LDAP::Message
returned by LDAP operations.
$name
is an optional test name, and if it is omitted, the test name is automatically configured based on $method
and @params
.
SEE ALSO
AUTHOR
Mahiro Ando, <mahiro at cpan.org>
BUGS
Please report any bugs or feature requests to bug-test-net-ldap at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Net-LDAP. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Test::Net::LDAP
You can also look for information at:
GitHub repository (report bugs here)
RT: CPAN's request tracker (report bugs here, alternatively)
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
Copyright 2013-2015 Mahiro Ando.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.