-
-
Save xantus/76da6a824defd8cb8f08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# get AutoMojo: http://xant.us/files/AutoMojo.pm | |
use AutoMojo qw( Mojo::Client ); | |
use Data::Dumper; | |
my $id = '68201531b8da714334f47f947cd85050'; | |
my $file = '/tmp/test.gif'; | |
system("wget http://xant.us/favicon.ico -O $file") unless -e $file; | |
my $client = Mojo::Client->new; | |
# delete db | |
$client->delete( 'http://127.0.0.1:5984/test' )->success; | |
# create db | |
$client->put( 'http://127.0.0.1:5984/test' )->success; | |
# insert file in this record | |
my $tx = $client->build_tx(PUT => "http://127.0.0.1:5984/test/$id/test.gif"); | |
$tx->req->content(Mojo::Content::Single->new->asset(Mojo::Asset::File->new(path => $file))); | |
$tx->req->headers->content_type( 'image/gif' ); | |
$client->process( $tx ); | |
my $ret = $tx->success->json; | |
warn Data::Dumper->Dump([$ret]); | |
if ( $ret->{ok} ) { | |
my $res = $client->get( "http://127.0.0.1:5984/test/$id/test.gif" )->success; | |
my $size = $res->headers->content_length; | |
my $fsize = -s $file; | |
die "failed, length of file in db is: $size not the same as $fsize" unless $size == $fsize; | |
die "failed, content type of file in db is: ".$res->headers->content_type." not image/gif" | |
unless $res->headers->content_length ne 'image/gif'; | |
print "test passed, image is at http://127.0.0.1:5984/test/$id/test.gif\n"; | |
} else { | |
die "test failed\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment