Skip to content

Commit

Permalink
Update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedas committed Nov 13, 2021
1 parent 851bb61 commit 0377d95
Showing 1 changed file with 124 additions and 1 deletion.
125 changes: 124 additions & 1 deletion t/Request_Handler_add+del.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use strict;
use warnings;
use Data::Dumper;
use English qw(-no_match_vars);
use File::Temp qw();
use Test::More;
Expand Down Expand Up @@ -32,14 +33,18 @@ my $tempdir = File::Temp->newdir(CLEANUP => ($ENV{TEST_DEBUG} ? 0 : 1));

queuesubscribe => $tempdir . '/auth',
bounce_path => $tempdir . '/bounce',
etc => $tempdir . '/etc',
);
mkdir $Conf::Conf{queuesubscribe};
mkdir $Conf::Conf{bounce_path};
mkdir $Conf::Conf{bounce_path} . '/' . $listname . '@' . $Conf::Conf{domain};
mkdir $Conf::Conf{etc};
mkdir $Conf::Conf{etc} . '/data_sources';

my $fake_list = bless {
name => $listname,
domain => $Conf::Conf{'domain'},
dir => $tempdir . '/list',
admin => {
available_user_options => {reception => [qw(mail digest)],},
default_user_options => {
Expand All @@ -55,8 +60,17 @@ my $fake_list = bless {
reception => 'nomail',
visibility => 'conceal',
},

member_include => [{source => 'include_file',}],
owner_include => [{source => 'include_file',}],
editor_include => [{source => 'include_file',}],
},
} => 'Sympa::List';
mkdir $tempdir . '/list';
open my $fh, '>', $Conf::Conf{etc} . '/data_sources/include_file.incl'
or die $ERRNO;
print $fh "include_file $tempdir/source\n";
close $fh;

Sympa::Log->instance->{level} = -1;
do {
Expand All @@ -68,6 +82,8 @@ $SIG{__WARN__} = sub {
print STDERR @_ unless 0 == index $_[0], 'Use of uninitialized value';
};

my $sdm = Sympa::DatabaseManager->instance or die;

# Now do testing

my $member_none = '[email protected]';
Expand Down Expand Up @@ -202,6 +218,51 @@ do_test(
name => 'del moderators'
);

do_test_include(
role => 'member',
source => [$member1],
data => [$member1],
name => 'include subscriber',
);
sleep 2;
do_test_include(
role => 'member',
source => [],
data => [],
name => 'include subscriber: emptied',
);
do_test_include(
role => 'member',
source => [$member1],
data => [$member1],
name => 'include subscriber',
);
do_test_include(
role => 'owner',
source => [[@{$owner1}[1, 2]]],
data => [$owner1],
name => 'include owner',
);
do_test_include(
role => 'editor',
source => [[@{$editor1}[1, 2]]],
data => [$editor1, $owner1],
name => 'include moderator',
);
sleep 2;
do_test_include(
role => 'owner',
source => [],
data => [$editor1],
name => 'include owner: emptied',
);
do_test_include(
role => 'editor',
source => [],
data => [],
name => 'include moderator: emptied',
);

done_testing();

sub do_test {
Expand Down Expand Up @@ -243,7 +304,69 @@ sub do_test {

return unless $options{data};

my $sdm = Sympa::DatabaseManager->instance or die;
if ('member' eq $role) {
is_deeply $sdm->do_prepared_query(
q{SELECT user_subscriber, comment_subscriber,
reception_subscriber, visibility_subscriber
FROM subscriber_table
ORDER BY user_subscriber}
)->fetchall_arrayref, $options{data}, $options{name};
} else {
is_deeply $sdm->do_prepared_query(
q{SELECT role_admin, user_admin, comment_admin,
profile_admin, reception_admin, visibility_admin
FROM admin_table
ORDER BY user_admin}
)->fetchall_arrayref, $options{data}, $options{name};
}
}

sub do_test_include {
my %options = @_;

my $role = $options{role} or die 'no role specified';

open my $fh, '>', $tempdir . '/source' or die $ERRNO;
foreach my $u (@{$options{source} // []}) {
printf $fh "%s %s\n", $u->[0], $u->[1];
}
close $fh;

my @stash;
my $spindle = Sympa::Spindle::ProcessRequest->new(
context => $fake_list,
action => 'include',
role => $role,
sender => $Conf::Conf{listmaster},
stash => \@stash,
scenario_context => {skip => 1},
);
die unless $spindle and $spindle->spin;

if ($options{result}) {
unless (
grep {
my $s = $_;
grep { $_->[0] eq $s->[1] and $_->[1] eq $s->[2] }
@{$options{result}}
} @stash
) {
fail $options{name};
diag 'No result ' . join "\n",
map { sprintf '"%s" "%s"', @$_ } @{$options{result}};
diag join "\n", map { join ',', @$_ } @stash;
}
} elsif (
grep {
$_->[1] ne 'notice'
} @stash
) {
fail $options{name};
diag join "\n", map { join ',', @$_ } @stash;
}

return unless $options{data};

if ('member' eq $role) {
is_deeply $sdm->do_prepared_query(
q{SELECT user_subscriber, comment_subscriber,
Expand Down

0 comments on commit 0377d95

Please sign in to comment.