testConfBackend.pl 2.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/usr/bin/perl

use lib 'lemonldap-ng-common/lib';

use strict;
use Getopt::Long;
use Lemonldap::NG::Common::Conf;
use Test::More tests => 12;

my %opts;
my $result = GetOptions( \%opts, 'help|h', 'ini|i=s', 'module|m=s', 'options|o=s' );

if ( $opts{help} or not( $opts{module} ) ) {
    print STDERR qq(
               ## Lemonldap::NG configuration module tester ##

Usage:
    $0 --module=<New> --ini=path/to/lemonldap-ng.ini --options='{ some => "parameter" }'

<New> must be the last word of Perl package: file must be named
Xavier Guimard's avatar
Xavier Guimard committed
21
Lemonldap::NG::Common::Conf::Backend::<New>
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

);
    exit 1;
}

my $module = $opts{module};

my $args = eval $opts{options} // {};

my $currentConf;

# 1
ok(
    $currentConf = Lemonldap::NG::Common::Conf->new(
        {
            confFile => $opts{ini},
            noCache  => 1,
        }
    ),
    'Load test conf module'
);
$Lemonldap::NG::Common::Conf::msg = '';

# 2
my $new;
ok(
    $new = Lemonldap::NG::Common::Conf->new(
        {
            type => $module,
            %$args,
            force       => 1,
            noCache     => 1,
            cfgNumFixed => 1,
        }
    ),
    'Load new module'
);

# 3
ok( ref($new), "New conf object ($Lemonldap::NG::Common::Conf::msg)" );
$Lemonldap::NG::Common::Conf::msg = '';

# 4
my $cfgNum;
ok( $cfgNum = $currentConf->lastCfg(), 'Test configuration available' );

# 5
my $conf;
ok(
    $conf = $currentConf->getConf( { cfgNum => $cfgNum } ),
    "Get test conf ($Lemonldap::NG::Common::Conf::msg)"
);
$Lemonldap::NG::Common::Conf::msg = '';

$conf->{cfgNum}++;
my $r;

# 6
eval { $new->delete( $conf->{cfgNum} ) };
ok( $r = $new->saveConf($conf),
    "Store conf in new module ($Lemonldap::NG::Common::Conf::msg)" );
$Lemonldap::NG::Common::Conf::msg = '';

# 7
ok( $r == $conf->{cfgNum}, 'Return cfgNum' );

# 8
ok( [ $new->available() ],
    "Some conf are available ($Lemonldap::NG::Common::Conf::msg)" );
$Lemonldap::NG::Common::Conf::msg = '';

# 9
ok( $r == $new->lastCfg(),
    "New conf is available ($Lemonldap::NG::Common::Conf::msg)" );
$Lemonldap::NG::Common::Conf::msg = '';

# 10
my $nc;
ok(
    $nc = $new->getConf( { cfgNum => $r } ),
    "Get new conf ($Lemonldap::NG::Common::Conf::msg)"
);
$Lemonldap::NG::Common::Conf::msg = '';

# 11
ok( $nc->{cfgNum} == $r, 'Good cfgNum in new conf' );

# 12
ok( $new->delete($r), "Delete conf ($Lemonldap::NG::Common::Conf::msg)" );
$Lemonldap::NG::Common::Conf::msg = '';