Test::Net::LDAP(3pm)

πŸ“¦
version 0.07 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 πŸ’–)


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