Test::Net::LDAP(3pm)
π Test::Net::LDAP β bestie edition π
okay so this is a page from the User Contributed Perl Documentation for Test::Net::LDAP(3pm), and honestly? it's giving "your fave testing sidekick". let's get into it π«Ά
β¨ NAME β¨
Test::Net::LDAP β literally just a Net::LDAP subclass that exists so you can test stuff. no cap.
π VERSION π
Version 0.07. iconic. that's the one we're talking about.
πΈ SYNOPSIS πΈ
so like, two whole moods here. pick your fighter π
the basic testing utility vibe
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...);
the mocking vibe (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 π¦
so this module hands you a bunch of testing methods for LDAP operations β think search, add, and modify β except every single one of them comes with a glow-up suffix: either _ok or _is. adorable, right? β¨
and here's the tea: Test::Net::LDAP is a subclass of Net::LDAP, which means every method that Net::LDAP defines is still right there waiting for you, plus the extra ones like search_ok, add_is, etc. you're not losing anything, you're just gaining β¨
if you want in-memory testing with fake data β like, no actual connecting to real LDAP servers, we're staying cozy β go peek at Test::Net::LDAP::Mock. and if you want some helper subroutines, Test::Net::LDAP::Util has your back.
π METHODS π
π§ new
makes you a brand new object. the parameters are literally the same as Net::LDAP::new. periodt.
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 β a whole roster, we love a group π
Synopsis:
$ldap->search_ok(@params);
$ldap->search_ok(\@params, $name);
what it does: it invokes the corresponding method with @params passed as arguments, then tests the result to see if the code is LDAP_SUCCESS. slay.
alternatively, @params can be handed over as an array ref, so that the second argument $name gets specified as the test name. flexible, we stan.
$name is an optional test name, and if you leave it out, the test name is automatically configured based on $method and @params. so it's got your back either way π«Ά
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);
it invokes the corresponding method with @params passed as arguments, and then tests the result to see if the code is equal to $expect. (yes bestie, this one actually checks the value, not just "did it work" π
)
$expect can be a result code like LDAP_NO_SUCH_OBJECT, OR an object of Net::LDAP::Message returned by LDAP operations. either one, your choice.
$name is an optional test name, and if you omit it, 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);
it invokes the method as $ldap->$method(@params) and then tests the result to see if the code is LDAP_SUCCESS. the generic queen of the _ok family π
$name is an optional test name, and if it's omitted, the test name is automatically configured based on $method and @params.
β method_is
$ldap->method_is($method, \@params, $expect, $name);
it invokes the method as $ldap->$method(@params) and then tests the result to see if the code is equal to $expect.
$expect can be a result code like LDAP_NO_SUCH_OBJECT, or an object of Net::LDAP::Message returned by LDAP operations.
$name is an optional test name, and if you omit it, the test name is automatically configured based on $method and @params. consistent king behavior fr fr π
π₯ SEE ALSO π₯
- Test::More
- Net::LDAP
- Test::Net::LDAP::Mock
- Test::Net::LDAP::Util
go read them, they're all part of the friend group π«Ά
π AUTHOR π
Mahiro Ando, "<mahiro at cpan.org>" β legend behavior π
π 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.
not me asking you to file bugs but like... pls do π₯Ί they get to me and then you get updates automatically. it's a whole system. it works.
πΈ 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)
<https://github.com/mahiro/perl-Test-Net-LDAP>
- RT: CPAN's request tracker (report bugs here, alternatively)
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Net-LDAP>
- AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/Test-Net-LDAP>
- CPAN Ratings
<http://cpanratings.perl.org/d/Test-Net-LDAP>
- Search CPAN
<http://search.cpan.org/dist/Test-Net-LDAP/>
like five whole places to find us. we're everywhere. main character energy β¨
π ACKNOWLEDGEMENTS π
(okay so this section is genuinely empty in the original β nothing here bestie, but we're keeping the heading because rules are rules and we respect the outline π)
π 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.
and that's the whole page bestie!! π¦ this doc shipped as part of perl v5.34.0, dated 2022-06-28, under the Test::Net::LDAP(3pm) manual. go forth and test your LDAP stuff, you're gonna eat π
β¨
π¦ where this page comes from
- debian bookworm: libtest-net-ldap-perl 0.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtest-net-ldap-perl 0.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtest-net-ldap-perl 0.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-net-ldap-perl 0.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-net-ldap-perl 0.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms