summaryrefslogtreecommitdiff
path: root/t/lib
diff options
context:
space:
mode:
Diffstat (limited to 't/lib')
-rw-r--r--t/lib/CPANServer.pm46
-rw-r--r--t/lib/filenames.pl46
2 files changed, 92 insertions, 0 deletions
diff --git a/t/lib/CPANServer.pm b/t/lib/CPANServer.pm
new file mode 100644
index 0000000..90a5cc9
--- /dev/null
+++ b/t/lib/CPANServer.pm
@@ -0,0 +1,46 @@
+package CPANServer;
+
+use strict;
+use warnings;
+use base qw(HTTP::Server::Simple::CGI);
+use File::Spec::Functions;
+
+sub handle_request {
+ my $self = shift;
+ my $cgi = shift;
+
+ my $file = ( split( '/', $cgi->path_info ) )[-1];
+ $file = 'index.html' unless ( $file );
+ open( INFILE, catfile( 't', 'html', $file ) )
+ or die "Can't open file $file: $@";
+ print $_ while ( <INFILE> );
+ close( INFILE );
+}
+
+our %env_mapping = (
+ protocol => "SERVER_PROTOCOL",
+ localport => "SERVER_PORT",
+ localname => "SERVER_NAME",
+ path => "PATH_INFO",
+ request_uri => "REQUEST_URI",
+ method => "REQUEST_METHOD",
+ peeraddr => "REMOTE_ADDR",
+ peername => "REMOTE_HOST",
+ query_string => "QUERY_STRING",
+);
+
+sub setup {
+ no warnings 'uninitialized';
+ my $self = shift;
+
+ while ( my ( $item, $value ) = splice @_, 0, 2 ) {
+ if ( $self->can( $item ) ) {
+ $self->$item( $value );
+ }
+ if ( my $k = $env_mapping{$item} ) {
+ $ENV{$k} = $value;
+ }
+ }
+}
+
+1;
diff --git a/t/lib/filenames.pl b/t/lib/filenames.pl
new file mode 100644
index 0000000..504b4bf
--- /dev/null
+++ b/t/lib/filenames.pl
@@ -0,0 +1,46 @@
+$WriteRepo = catfile( qw(t local WRITEREPO) );
+
+%MYCPAN => ( dir => catfile( qw(t read MYCPAN) ), );
+
+my @files = qw(modulelist test-0.01.tar.gz);
+$MYCPAN{@files} = map { catfile( $MYCPAN{dir}, $_ ) } @files;
+
+return 1 if ( -r '/usr/local/etc/mcpani' );
+return 1 if ( -r '/etc/mcpani' );
+
+# parsecfg()
+dies_ok { $mcpi->parsecfg( catfile( qw(t .mcpani config_bad) ) ); }
+'Missing config option';
+
+mkdir catfile( qw(t local MYCPAN) );
+$mcpi->parsecfg( catfile( qw(t .mcpani config_noread) ) );
+dies_ok { $mcpi->readlist } 'unreadable file';
+
+$mcpi->parsecfg( catfile( qw(t .mcpani config) ) );
+
+$mcpi->parsecfg( catfile( qw(t .mcpani config_norepo) ) );
+
+dies_ok {
+ $mcpi->add(
+ module => 'CPAN::Mini::Inject',
+ authorid => 'SSORICHE',
+ version => '0.01',
+ file => 'test-0.01.tar.gz'
+ );
+}
+'Missing config repository';
+
+$mcpi->parsecfg( catfile( qw(t .mcpani config_read) ) );
+
+$mcpi->parsecfg( catfile( qw(t .mcpani config_nowrite) ) );
+dies_ok { $mcpi->writelist } 'fail write file';
+
+mkdir catfile( qw(t local WRITEREPO) );
+open WRITEFILE, '>', catfile( qw(t local WRITEREPO modulelist) );
+close WRITEFILE;
+chmod 0222, catfile( qw(t local WRITEREPO modulelist) );
+
+chmod 0555, catfile( qw(t read MYCPAN) );
+chmod 0444, catfile( qw(t read MYCPAN modulelist) );
+chmod 0444, catfile( qw(t read MYCPAN test-0.01.tar.gz) );
+