1Test::Net::LDAP(3)    User Contributed Perl Documentation   Test::Net::LDAP(3)
2
3
4

NAME

6       Test::Net::LDAP - A Net::LDAP subclass for testing
7

VERSION

9       Version 0.07
10

SYNOPSIS

12       Basic testing utility
13
14           use Test::More tests => 1;
15           use Test::Net::LDAP;
16
17           # Create an object, just like Net::LDAP->new()
18           my $ldap = Test::Net::LDAP->new(...);
19
20           # Same as $ldap->search(), testing the result to see if it is success
21           my $search = $ldap->search_ok(...search args...);
22
23       Mocking (See Test::Net::LDAP::Mock)
24
25           use Test::More tests => 1;
26           use Test::Net::LDAP::Util qw(ldap_mockify);
27
28           ldap_mockify {
29               # Net::LDAP->new() will invoke Test::Net::LDAP::Mock->new()
30               my $ldap = Net::LDAP->new('ldap.example.com');
31
32               # Add entries to in-memory data tree
33               $ldap->add('uid=user1, ou=users, dc=example, dc=com');
34               $ldap->add('uid=user2, ou=users, dc=example, dc=com');
35
36               # Test your application
37               ok my_application_routine();
38           };
39

DESCRIPTION

41       This module provides some testing methods for LDAP operations, such as
42       "search", "add", and "modify", where each method is suffixed with
43       either "_ok" or "_is".
44
45       "Test::Net::LDAP" is a subclass of "Net::LDAP", so all the methods
46       defined for "Net::LDAP" are available in addition to "search_ok",
47       "add_is", etc.
48
49       See Test::Net::LDAP::Mock for in-memory testing with fake data, without
50       connecting to the real LDAP servers.
51
52       See Test::Net::LDAP::Util for some helper subroutines.
53

METHODS

55   new
56       Creates a new object. The parameters are the same as "Net::LDAP::new".
57
58           my $ldap = Test::Net::LDAP->new('ldap.example.com');
59
60   search_ok
61       Available methods: "search_ok", "compare_ok", "add_ok", "modify_ok",
62       "delete_ok", "moddn_ok", "bind_ok", "unbind_ok", "abandon_ok"
63
64       Synopsis:
65
66           $ldap->search_ok(@params);
67           $ldap->search_ok(\@params, $name);
68
69       Invokes the corresponding method with @params passed as arguments, and
70       tests the result to see if the code is "LDAP_SUCCESS".
71
72       Alternatively, @params can be given as an array ref, so that the second
73       argument $name is specified as the test name.
74
75       $name is an optional test name, and if it is omitted, the test name is
76       automatically configured based on $method and @params.
77
78           my $search = $ldap->search_ok(
79               base => 'dc=example, dc=com', scope => 'sub', filter => '(cn=*)',
80           );
81
82           my $search = $ldap->search_ok(
83               [base => 'dc=example, dc=com', scope => 'sub', filter => '(cn=*)'],
84               'Testing search (cn=*)'
85           );
86
87   search_is
88       Available methods: "search_is", "compare_is", "add_is", "modify_is",
89       "delete_is", "moddn_is", "bind_is", "unbind_is", "abandon_is"
90
91       Synopsis:
92
93           $ldap->search_is(\@params, $expect, $name);
94
95       Invokes the corresponding method with @params passed as arguments, and
96       tests the result to see if the code is equal to $expect.
97
98       $expect can be a result code such as "LDAP_NO_SUCH_OBJECT" or an object
99       of "Net::LDAP::Message" returned by LDAP operations.
100
101       $name is an optional test name, and if it is omitted, the test name is
102       automatically configured based on $method and @params.
103
104           use Net::LDAP::Constant qw(LDAP_ALREADY_EXISTS);
105
106           my $mesg = $ldap->add_is(
107               ['uid=duplicate, dc=example, dc=com'],
108               LDAP_ALREADY_EXISTS
109           );
110
111   method_ok
112           $ldap->method_ok($method, @params);
113           $ldap->method_ok($method, \@params, $name);
114
115       Invokes the method as "$ldap->$method(@params)" and tests the result to
116       see if the code is "LDAP_SUCCESS".
117
118       $name is an optional test name, and if it is omitted, the test name is
119       automatically configured based on $method and @params.
120
121   method_is
122           $ldap->method_is($method, \@params, $expect, $name);
123
124       Invokes the method as "$ldap->$method(@params)" and tests the result to
125       see if the code is equal to $expect.
126
127       $expect can be a result code such as "LDAP_NO_SUCH_OBJECT" or an object
128       of "Net::LDAP::Message" returned by LDAP operations.
129
130       $name is an optional test name, and if it is omitted, the test name is
131       automatically configured based on $method and @params.
132

SEE ALSO

134       •   Test::More
135
136       •   Net::LDAP
137
138       •   Test::Net::LDAP::Mock
139
140       •   Test::Net::LDAP::Util
141

AUTHOR

143       Mahiro Ando, "<mahiro at cpan.org>"
144

BUGS

146       Please report any bugs or feature requests to "bug-test-net-ldap at
147       rt.cpan.org", or through the web interface at
148       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Net-LDAP>.  I will
149       be notified, and then you'll automatically be notified of progress on
150       your bug as I make changes.
151

SUPPORT

153       You can find documentation for this module with the perldoc command.
154
155           perldoc Test::Net::LDAP
156
157       You can also look for information at:
158
159       •   GitHub repository (report bugs here)
160
161           <https://github.com/mahiro/perl-Test-Net-LDAP>
162
163       •   RT: CPAN's request tracker (report bugs here, alternatively)
164
165           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Net-LDAP>
166
167       •   AnnoCPAN: Annotated CPAN documentation
168
169           <http://annocpan.org/dist/Test-Net-LDAP>
170
171       •   CPAN Ratings
172
173           <http://cpanratings.perl.org/d/Test-Net-LDAP>
174
175       •   Search CPAN
176
177           <http://search.cpan.org/dist/Test-Net-LDAP/>
178

ACKNOWLEDGEMENTS

181       Copyright 2013-2015 Mahiro Ando.
182
183       This program is free software; you can redistribute it and/or modify it
184       under the terms of either: the GNU General Public License as published
185       by the Free Software Foundation; or the Artistic License.
186
187       See http://dev.perl.org/licenses/ for more information.
188
189
190
191perl v5.36.0                      2023-01-20                Test::Net::LDAP(3)
Impressum