mirror of https://github.com/perkeep/perkeep.git
Tests now pass on Go and App Engine.
This commit is contained in:
parent
b4654b132f
commit
fb05cf950a
|
@ -70,12 +70,24 @@ sub post {
|
||||||
|
|
||||||
sub upload_request {
|
sub upload_request {
|
||||||
my ($self, $upload_url, $blobref_to_blob_map) = @_;
|
my ($self, $upload_url, $blobref_to_blob_map) = @_;
|
||||||
|
my @content;
|
||||||
|
my $n = 0;
|
||||||
|
foreach my $key (sort keys %$blobref_to_blob_map) {
|
||||||
|
$n++;
|
||||||
|
# TODO: the App Engine client refused to work unless the Content-Type
|
||||||
|
# is set. This should be clarified in the docs (MUST?) and update the
|
||||||
|
# test suite and Go server accordingly (to fail if not present).
|
||||||
|
push @content, $key => [
|
||||||
|
undef, "filename$n",
|
||||||
|
"Content-Type" => "application/octet-stream",
|
||||||
|
Content => $blobref_to_blob_map->{$key},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return POST($upload_url,
|
return POST($upload_url,
|
||||||
"Content_Type" => 'form-data',
|
"Content_Type" => 'form-data',
|
||||||
"Authorization" => "Basic dGVzdDp0ZXN0", # test:test
|
"Authorization" => "Basic dGVzdDp0ZXN0", # test:test
|
||||||
Content => [
|
Content => \@content);
|
||||||
%$blobref_to_blob_map
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get {
|
sub get {
|
||||||
|
@ -173,7 +185,7 @@ sub test_preupload_and_upload {
|
||||||
"blob1" => $blobref,
|
"blob1" => $blobref,
|
||||||
});
|
});
|
||||||
my $jres = $self->get_json($req, "valid preupload");
|
my $jres = $self->get_json($req, "valid preupload");
|
||||||
print STDERR "preupload response: ", Dumper($jres);
|
diag("preupload response: " . Dumper($jres));
|
||||||
ok($jres, "valid preupload JSON response");
|
ok($jres, "valid preupload JSON response");
|
||||||
for my $f (qw(alreadyHave maxUploadSize uploadUrl uploadUrlExpirationSeconds)) {
|
for my $f (qw(alreadyHave maxUploadSize uploadUrl uploadUrlExpirationSeconds)) {
|
||||||
ok(defined($jres->{$f}), "required field '$f' present");
|
ok(defined($jres->{$f}), "required field '$f' present");
|
||||||
|
@ -185,12 +197,15 @@ sub test_preupload_and_upload {
|
||||||
like($jres->{uploadUrlExpirationSeconds}, qr/^\d+$/, "uploadUrlExpirationSeconds is numeric");
|
like($jres->{uploadUrlExpirationSeconds}, qr/^\d+$/, "uploadUrlExpirationSeconds is numeric");
|
||||||
my $upload_url = URI::URL->new($jres->{uploadUrl});
|
my $upload_url = URI::URL->new($jres->{uploadUrl});
|
||||||
ok($upload_url, "valid uploadUrl");
|
ok($upload_url, "valid uploadUrl");
|
||||||
# TODO: are relative URLs allowed in uploadUrl?
|
# TODO: test & clarify in spec: are relative URLs allowed in uploadUrl?
|
||||||
|
# App Engine seems to do it already, and makes it easier, so probably
|
||||||
|
# best to clarify that they're relative.
|
||||||
|
|
||||||
# Do the actual upload
|
# Do the actual upload
|
||||||
my $upreq = $self->upload_request($upload_url, {
|
my $upreq = $self->upload_request($upload_url, {
|
||||||
$blobref => $blob,
|
$blobref => $blob,
|
||||||
});
|
});
|
||||||
|
diag("upload request: " . $upreq->as_string);
|
||||||
my $upres = $self->get_upload_json($upreq);
|
my $upres = $self->get_upload_json($upreq);
|
||||||
ok($upres, "Upload was success");
|
ok($upres, "Upload was success");
|
||||||
print STDERR "# upload response: ", Dumper($upres);
|
print STDERR "# upload response: ", Dumper($upres);
|
||||||
|
@ -286,6 +301,7 @@ sub DESTROY {
|
||||||
package Impl::AppEngine;
|
package Impl::AppEngine;
|
||||||
use base 'Impl';
|
use base 'Impl';
|
||||||
use IO::Socket::INET;
|
use IO::Socket::INET;
|
||||||
|
use Time::HiRes ();
|
||||||
|
|
||||||
sub start {
|
sub start {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
@ -301,7 +317,7 @@ sub start {
|
||||||
|
|
||||||
$self->{_tempdir_blobstore_obj} = File::Temp->newdir();
|
$self->{_tempdir_blobstore_obj} = File::Temp->newdir();
|
||||||
$self->{_tempdir_datastore_obj} = File::Temp->newdir();
|
$self->{_tempdir_datastore_obj} = File::Temp->newdir();
|
||||||
my $datapath = $self->{_tempdir_blobstore_obj}->dirname . "/needs-to-be-a-file";
|
my $datapath = $self->{_tempdir_blobstore_obj}->dirname . "/datastore-file";
|
||||||
my $blobdir = $self->{_tempdir_datastore_obj}->dirname;
|
my $blobdir = $self->{_tempdir_datastore_obj}->dirname;
|
||||||
|
|
||||||
my $port;
|
my $port;
|
||||||
|
@ -337,14 +353,19 @@ sub start {
|
||||||
}
|
}
|
||||||
$self->{pid} = $pid;
|
$self->{pid} = $pid;
|
||||||
|
|
||||||
|
my $last_print = 0;
|
||||||
for (1..15) {
|
for (1..15) {
|
||||||
print STDERR "# Waiting for appengine app to start...\n";
|
my $now = time();
|
||||||
|
if ($now != $last_print) {
|
||||||
|
print STDERR "# Waiting for appengine app to start...\n";
|
||||||
|
$last_print = $now;
|
||||||
|
}
|
||||||
my $res = $self->ua->request($self->get("/"));
|
my $res = $self->ua->request($self->get("/"));
|
||||||
if ($res && $res->is_success) {
|
if ($res && $res->is_success) {
|
||||||
print STDERR "# Up.";
|
print STDERR "# Up.";
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
sleep(1);
|
Time::HiRes::sleep(0.1);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue