From: Matt S Trout Date: Sun, 15 Jul 2012 22:40:57 +0000 (+0000) Subject: start of integration testing X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fb960e0eb2ad6ad19c2c695b6aa87716ae299a23;p=scpubgit%2FApp-EzPz.git start of integration testing --- diff --git a/Makefile.PL b/Makefile.PL index 8860481..af94849 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -3,6 +3,14 @@ use warnings FATAL => 'all'; use 5.008001; use ExtUtils::MakeMaker; +my $full_test = $ENV{TEST_APP_EZPZ} ||= do { + prompt("Run integration tests? (y/n)", "n") eq "y" +}; + +if ($full_test) { + mkdir('test-setup'); +} + WriteMakefile( NAME => 'App-EzPz', VERSION => 0, diff --git a/lib/App/EzPz/TestSetup.pm b/lib/App/EzPz/TestSetup.pm index 4cd3552..46acf51 100644 --- a/lib/App/EzPz/TestSetup.pm +++ b/lib/App/EzPz/TestSetup.pm @@ -3,7 +3,7 @@ package App::EzPz::TestSetup; use IO::All; use IPC::System::Simple qw(run); use Cwd; -use Exporter; +use base qw(Exporter); use strictures 1; our @EXPORT = qw(create_install create_list); @@ -12,20 +12,20 @@ sub create_install { die "Usage: ezpz-create-test-ezmlm-install ezmlm-source.tgz build-dir install-dir" unless @_ == 3; - my ($ezmlm_tarball_path, $build_dir_path, $install_to_path) = @ARGV; + my ($ezmlm_tarball_path, $build_dir_path, $install_to_path) = @_; my $ezmlm_tarball = io->file(io->file($ezmlm_tarball_path)->rel2abs); - my $orig_cwd = io->dir(cwd); + my $cwd = cwd; - my $build_dir = io->dir($build_dir_path)->absolute; - my $install_to = io->dir($install_to_path)->absolute; + my $build_dir = io->dir(io->dir($build_dir_path)->rel2abs); + my $install_to = io->dir(io->dir($install_to_path)->rel2abs); unless ($build_dir->exists) { $build_dir->mkpath; $build_dir->chdir; run 'tar', 'xzf', $ezmlm_tarball; - $orig_cwd->chdir; + chdir($cwd); } my ($src_dir) = ($build_dir->all_dirs)[0]; @@ -44,6 +44,8 @@ sub create_install { run './ezmlm-test'; $install_to->catdir('bin')->mkpath; run make => 'install'; + + chdir(cwd); } sub create_list { @@ -52,9 +54,9 @@ sub create_list { my ($ezmlm_bin_path, $list_base_path, $list_name) = @_; - my $ezmlm_bin = io->dir($ezmlm_bin_path)->absolute; + my $ezmlm_bin = io->dir(io->dir($ezmlm_bin_path)->rel2abs); - my $list_base = io->dir($list_base_path)->absolute; + my $list_base = io->dir(io->dir($list_base_path)->rel2abs); run( $ezmlm_bin->catfile('ezmlm-make'), @@ -63,3 +65,6 @@ sub create_list { $list_name, 'example.com' ); +} + +1; diff --git a/t/lists.t b/t/lists.t new file mode 100644 index 0000000..a91e5b2 --- /dev/null +++ b/t/lists.t @@ -0,0 +1,68 @@ +use if (!-d 'test-setup'), 'Test::More', skip_all => 'List testing skipped'; +use Test::More; +use IO::All; +use App::EzPz::TestSetup; +use App::EzPz::UserStore; +use App::EzPz::Web; +use strictures 1; + +unless (-d 'test-setup/ezmlm') { + create_install( + 'src/ezmlm-idx-7.1.1.tar.gz', + 'test-setup/build', + 'test-setup/ezmlm' + ); +} + +my $lists_base = io->dir('test-setup/lists'); + +$lists_base->rmtree; +$lists_base->mkpath; + +create_list('test-setup/ezmlm/bin', 'test-setup/lists', $_) + for qw(list1 list2 list3); + +pass('Setup completed successfully'); + +my $us = App::EzPz::UserStore->new( + htpasswd_file => 'test-setup/lists/htpasswd', + ezmlm_config => { + bindir => 'test-setup/ezmlm/bin', + list_base_dir => 'test-setup/lists' + } +); + +for my $user ($us->add({ username => 'mst', password => 'boromir' })) { + $user->add_list_name($_) for qw(list1 list2 list3); + for my $list ($user->get_list('list1')) { + $list->add_member('joe@example.com'); + $list->add_member('bob@example.com'); + $list->deny->add_member('evil@monkey.com'); + $list->deny->add_member('evil@gibbon.com'); + } +} + +my $app = App::EzPz::Web->new(users => $us); + +is($app->run_test_request(GET => '/')->code, 401, 'Auth fail without pw'); + +is( + $app->run_test_request(GET => 'bob:boromir@/')->code, 401, + 'Auth fail with wrong user' +); + +is( + $app->run_test_request(GET => 'mst:spoon@/')->code, 401, + 'Auth fail with wrong pw' +); + +my $res = $app->run_test_request(GET => 'mst:boromir@/'); + +is($res->code, 200, 'Auth ok with user+pass'); + +like($res->content, qr/Welcome user .*mst/, 'Welcome mst'); + +like($res->content, qr{/list/$_/}, "List $_ on /") + for qw(list1 list2 list3); + +done_testing;