Changeset 6594
- Timestamp:
- Mar 15, 2006, 12:02:55 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/DataStore/t/07_file.t (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/DataStore/t/07_file.t
r6541 r6594 3 3 # Copyright (C) 2006 Joshua Hoblitt 4 4 # 5 # $Id: 07_file.t,v 1. 1 2006-03-08 01:14:14jhoblitt Exp $5 # $Id: 07_file.t,v 1.2 2006-03-15 22:02:53 jhoblitt Exp $ 6 6 7 7 use strict; … … 10 10 use lib qw( ./lib ./t ); 11 11 12 use Test::More tests => 6;12 use Test::More tests => 14; 13 13 14 14 =head1 NAME … … 23 23 24 24 use DataStore::File; 25 use File::Temp (); 25 26 26 27 can_ok('DataStore::File', qw( … … 69 70 70 71 eval { 71 my $ds p= DataStore::File->new;72 my $dsf = DataStore::File->new; 72 73 }; 73 74 like($@, qr/Mandatory parameters/, … … 76 77 # ->request() 77 78 79 use Net::HTTPServer; 80 81 sub bar 82 { 83 my $req = shift; # Net::HTTPServer::Request object 84 my $res = $req->Response(); # Net::HTTPServer::Response object 85 86 my $string = "foobarbaz"; 87 88 $res->Print($string); 89 90 return $res; 91 } 92 93 $|++; 94 95 $SIG{CHLD} = 'IGNORE'; 96 my $pid = open(my $child, "-|"); 97 98 unless ($pid) { 99 my $server = new Net::HTTPServer( port => 'scan' ); 100 101 # send port number to parent 102 print $server->Start(), "\n"; 103 104 $server->RegisterURL('/somefile', \&bar); 105 $server->Process(); # Run forever 106 107 exit -1; 108 } 109 110 my $port = <$child>; 111 chomp $port; 112 113 { 114 my $dsf = DataStore::File->new( 115 uri => "http://localhost:$port/somefile", 116 fileid => '12buckelyourshoe', 117 bytes => 9, 118 md5sum => 'a0a6e1a375117c58d77221f10c5ce12e', 119 type => 'foo', 120 ); 121 122 my $fh = File::Temp->new( UNLINK => 1 ); 123 $fh->autoflush(1); 124 isa_ok($dsf->request( filename => $fh->filename ), 'DataStore::Response'); 125 } 126 127 { 128 my $dsf = DataStore::File->new( 129 uri => "http://localhost:$port/somefile", 130 fileid => '12buckelyourshoe', 131 bytes => 9, 132 md5sum => 'a0a6e1a375117c58d77221f10c5ce12e', 133 type => 'foo', 134 ); 135 136 my $fh = File::Temp->new( UNLINK => 1 ); 137 $fh->autoflush(1); 138 my $dsr = $dsf->request( filename => $fh->filename ); 139 140 ok($dsr->is_success, "response->is_success() is correct"); 141 is($dsr->code, 200, "response->code() is correct"); 142 is($dsr->status_line, "200 OK", "response->status_line() is correct"); 143 is($dsr->data, $fh->filename, "response->data is arrayref is correct"); 144 isa_ok($dsr->request, 'DataStore::Record'); 145 } 146 147 # stop HTTP server 148 kill 9, $pid; 149 150 eval { 151 my $dsf = DataStore::File->new( 152 uri => 'http://example.org/foo', 153 fileid => '12buckelyourshoe', 154 bytes => 12345, 155 md5sum => 'fe6a2b6564c0d4cfb3bbf1db813824ba', 156 type => 'foo', 157 ); 158 159 $dsf->request; 160 }; 161 like($@, qr/Mandatory parameter/, 162 '->request() fails when passed no params'); 163 164 eval { 165 my $dsf = DataStore::File->new( 166 uri => 'http://example.org/foo', 167 fileid => '12buckelyourshoe', 168 bytes => 12345, 169 md5sum => 'fe6a2b6564c0d4cfb3bbf1db813824ba', 170 type => 'foo', 171 ); 172 173 my $fh = File::Temp->new( UNLINK => 1 ); 174 $dsf->request( 175 filename => $fh->filename, 176 foo => 1, 177 ); 178 }; 179 like($@, qr/not listed in the validation options/, 180 '->request() fails whe passed extra params');
Note:
See TracChangeset
for help on using the changeset viewer.
