support configuration as first argument
[virtual-ldap] / t / ldap-rewrite.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Test::More tests => 8;
7 use Data::Dump qw(dump);
8
9 BEGIN {
10         use_ok 'Net::LDAP';
11 }
12
13 our $config;
14 ok( require( ( shift @ARGV || 't/config.pl' ) ), 'config.pl' );
15
16 sub ldap_check_error {
17         my $o = shift;
18         ok( ! $o->code, 'no errror' );
19         diag $o->error if $o->code;
20 }
21
22 ok( my $ldap = Net::LDAP->new( $config->{server} ), 'new Net::LDAP ' . dump( $config->{server} ) );
23
24 ok( my $bind = $ldap->bind( $config->{bind_as}, password => $config->{password} ), 'bind ' . $config->{bind_as} );
25 ldap_check_error $bind;
26
27 ok( my $search = $ldap->search( %{ $config->{search} } ), 'search ' . dump( $config->{search} ) );
28 ldap_check_error $search;
29
30 foreach my $entry ( $search->entries ) {
31         diag dump $entry;
32 }
33
34 ok( $ldap->unbind, 'unbind' );