Test::...P::Util(3pm)

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

πŸ’– Test::Net::LDAP::Util β€” it's giving testing utilities for Test::Net::LDAP πŸ’–

okay bestie, sit down, hydrate, because this is the little module that makes testing LDAP stuff not a whole entire nightmare. it's Test::Net::LDAP::Util, a Perl manual page (3pm, perl v5.34.0, dated 2022-06-28 β€” more on that at the end πŸŽ€), and it's literally just a lil grab-bag of helper subs for poking at LDAP test results. no cap.


✨ NAME ✨

Test::Net::LDAP::Util β€” Testing utilities for Test::Net::LDAP πŸ¦‹


🌸 EXPORT 🌸

the following subroutines are exported on demand β€” like, you have to ask for them, they're not just gonna show up uninvited:

use Test::Net::LDAP::Util qw(
    ldap_result_ok
    ldap_result_is
    ldap_mockify
    ldap_dn_is
);

and if you're feeling extra and want everything, just say ":all":

use Test::Net::LDAP::Util ':all';

all the subroutines get exported if ":all" is specified. periodt. πŸ‘‘


🧚 SUBROUTINES 🧚

πŸ’… ldap_result_ok

ldap_result_ok($mesg, $name);

this one tests the result of an LDAP operation to see if the code is "LDAP_SUCCESS". like, did it work? yes or no? vibe check complete. ✨

$mesg is either a Net::LDAP::Message object returned by LDAP operation methods or a result code.

$name is the optional test name.


πŸŽ€ ldap_result_is

ldap_result_is($mesg, $expect, $name);

this one tests the result of an LDAP operation to see if the code is equal to $expect. not just "did it succeed" β€” you're checking a specific code, main character energy. πŸ’–

the values of $mesg and $expect are either a Net::LDAP::Message object returned by LDAP operation methods or a result code.

$name is the optional test name.


πŸ¦‹ ldap_mockify

ldap_mockify {
    # CODE
};

okay this one is lowkey iconic. inside the code block (recursively, so it goes all the way down), all the occurrences of "Net::LDAP::new" are replaced by "Test::Net::LDAP::Mock::new". boom, mocked. πŸ™ˆ

subclasses of "Net::LDAP" are also mockified. "Test::Net::LDAP::Mock" is inserted into @ISA of each subclass, only within the context of "ldap_mockify" β€” so when you're done, everything goes back to normal. cute, right?

see Test::Net::LDAP::Mock for more details.


🌈 ldap_dn_is

ldap_dn_is($actual_dn, $expect_dn, $name);

tests equality of two DNs that are not necessarily canonicalized. so like, they don't have to match letter-for-letter in the strictest sense β€” you're just checking they're the same DN. πŸ’«

the comparison is case-insensitive. so don't come for me about capitalization, it genuinely does not care.


πŸ’€ reminder bestie: keep your DNs, your messages, and your expectations straight. $mesg can be a Net::LDAP::Message or a result code in both ldap_result_ok and ldap_result_is, and $name is optional everywhere it shows up. iykyk.

that's the whole page, fr fr. this beauty comes to you from the User Contributed Perl Documentation, shipped as part of perl v5.34.0, dated 2022-06-28. slay, go write some tests, and remember: mock it before you clock it. 🫢✨🌸

πŸ“¦ where this page comes from