Paws XXXVI (Still not finished.)

Well finally got the last of my tests done for S3, not much of a story as most of the test cases at least for the 'PUT' actions cases were mostly made up of two tests 'load' the results class and check the value of the '_request_id'.

That being said I still had some 80 tests that where failing most of them where this '_request_id' test. Seems when I was doing my test generator I was creating the test for '_request_id' but forgot to add it to the test content.

So a little change to ''

sub write_response_test {
    my $self = shift(@_);
    my ( $call, $response, $result_oject, $service ) = @_;
    my $response_hash = {
        content => $response->content,
--        headers => [],
++        headers => {'x-amz-request-id'=>$response->{headers}->{'x-amz-request-id'}},
        status  => $response->status

I also had a few other header errors and I was a little torn between adding in all the incoming headers into my test content which will solve a few problems but 90% of these headers are never used so I just sucked it up and fixed the few tests that required content in the headers.

We shall see when I move over to the next batch of PAWs actions I plan to fix.

I did find a bug while creating the test case for DeleteObjects. It seems when it is called when deleting two objects where one is deleted and one errors it returns with this XML;

 <?xml version="1.0" encoding="UTF-8"?>
  <DeleteResult xmlns="">
      <Message>Access Denied</Message>

I then get a fail on this result object;

bless( {
    'Deleted' => [],
    '_request_id' => 'SSB1B5552784608B76',
    'Errors' => [
         bless( {
                 'Key' => 'sample3.txt',
                 'Code' => 'AccessDenied',
                 'Message' => 'Access Denied'
                 }, 'Paws::S3::Error' )
      }, 'Paws::S3::DeleteObjectsOutput' );

with this test;

not ok 3 - Got Deleted.0.Key eq sample1.txt from result
#   Failed test 'Got Deleted.0.Key eq sample1.txt from result'
#   at t/10_responses.t line 136.
#          got: undef
#     expected: 'sample1.txt'

Time to get back into go old and add in some debugging. Fortuntely I do not really need to check how the resposne it being handled I really just need to known how the XML is unserilized and the output of that was;

    'xmlns' => '',
    'Deleted' => {
                'Key' => 'sample2.txt'
    'Error' => {
                'Message' => 'Access Denied',
                'Key' => 'sample3.txt',
                'Code' => 'AccessDenied'

So I am getting a Hash-Ref for the 'Deleted' attribute with is what I want so down into the 'new_from_result_struct' sub I go. I eventully tracked it into some of the HASH handleing code to this block

if ($value_ref eq 'HASH') {
          if (exists $value->{ member }) {
            $value = $value->{ member };
          } elsif (exists $value->{ entry }) {
            $value = $value->{ entry  };
          } elsif (keys %$value == 1) {
            $value = $value->{ (keys %$value)[0] };
          } else {
            #die "Can't detect the item that has the array in the response hash";

In this case the 'Deleted' HASH is handeld by the

} elsif (keys %$value == 1) {

part as it has only one key while the ' Error' HASH has more than one key.

What it happens next is that HASH is flattened so

    'Key' => 'sample2.txt'

turns into


Well I commented out that code and my tests case give me this result;

ok 1 - Call S3->DeleteObjects from t/10_responses/s3-delete-objects.1.response
ok 2 - Got _request_id eq SSB1B5552784608B76 from result
ok 3 - Got Deleted.0.Key eq sample2.txt from result
ok 4 - Got Errors.0.Message eq Access Denied from result
ok 5 - Got Errors.0.Key eq sample3.txt from result
ok 6 - Got Errors.0.Code eq AccessDenied from result

However when I run the full suite I go from 17 fails to 66;

# Looks like you failed 66 tests of 436.

So that was not the solution. I put that code back in and looked at was failing. ListBuckets was one and when it is processed the same way as above it goes in with

    'Bucket' => [ {
         'Name' => 'botostats',
         'CreationDate' => '2012-02-20T17:45:32.000Z'

and comes out as

[ {
'Name' => 'botostats',
'CreationDate' => '2012-02-20T17:45:32.000Z'


I checked all the other failing tests they all pointed to eiterh a HASH or an ARRAY so I think I have to check the value of that first key-pair and simply do nothing if the value is a scalar;

           } elsif (keys %$value == 1) {
-            $value = $value->{ (keys %$value)[0] };
+            my @keys = keys(%{$value});
+                       $value = $value->{$keys[0]}
+                         if (ref($value->{$keys[0]}));
           } else {

It the patch I tried and my test again and I got a full pass; Time to try the full test suite again;

# Looks like you failed 16 tests of 446.

and I am back to what I was before. Well I guess there will be a few more PAWS S3 posts.


Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations