Debian Codegraph @

lemonldap-ng-manager/t/30-DBI-Cli.t

raw
1 # Test for https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/-/issues/2493
2
3 use warnings;
4 use strict;
5 use Data::Dumper;
6 use IO::String;
7 use JSON qw(from_json);
8 use Test::More;
9
10 require 't/test-lib.pm';
11
12 my $count = 0;
13 my $file = "$main::tmpdir/conf/conf.db";
14 my $maintests = 8;
15 my ( $res, $client );
16 eval { unlink $file };
17
18 sub count {
19 my $c = shift;
20 $count += $c if ($c);
21 return $count;
22 }
23
24 SKIP: {
25 eval { require DBI; require DBD::SQLite; };
26 if ($@) {
27 skip 'DBD::SQLite not found', $maintests;
28 }
29
30 my $dbh = DBI->connect("dbi:SQLite:dbname=$file");
31 $dbh->do(
32 "CREATE TABLE lmConfig ( cfgNum int not null, field varchar(255) NOT NULL DEFAULT '', value longblob, PRIMARY KEY (cfgNum,field))"
33 ) or die $DBI::errstr;
34 use_ok('Lemonldap::NG::Common::Conf');
35 my $h;
36 ok(
37 $h = new Lemonldap::NG::Common::Conf( {
38 type => 'RDBI',
39 dbiChain => "DBI:SQLite:dbname=$file",
40 dbiUser => '',
41 dbiPassword => '',
42 }
43 ),
44 'RDBI object'
45 );
46 {
47 local $/ = undef;
48 open my $f, '<', "$main::tmpdir/conf/lmConf-1.json";
49 my $content = <$f>;
50 close $f;
51 ok( $h->store( from_json($content) ), 'Conf 1 saved' );
52 }
53
54 use_ok('Lemonldap::NG::Manager::Cli::Lib');
55 ok(
56 $client = Lemonldap::NG::Manager::Cli::Lib->new(
57 iniFile => "$main::tmpdir/lemonldap-ng-DBI-conf.ini"
58 ),
59 'Client object'
60 );
61
62 use_ok('Lemonldap::NG::Manager::Cli');
63
64 my @args = (qw(-yes 1 -force 1 set ldapSetPassword 0));
65 $ENV{LLNG_DEFAULTCONFFILE} = "$main::tmpdir/lemonldap-ng-DBI-conf.ini";
66 Lemonldap::NG::Manager::Cli->run(@args);
67 my $res = $dbh->selectrow_hashref(
68 "SELECT * FROM lmConfig WHERE field='ldapSetPassword'");
69 ok( $res, 'Key inserted' );
70 ok( $res && $res->{value} == '0', 'Value is 0' );
71 }
72
73 eval { unlink $file };
74 done_testing( count($maintests) );