Paws XXXV (Well not a wrap but close)

Well it looks like a wrap for Paws S3

I made up my own test creation caller. No rocket science in this one. I just added in a few useful attributes;


has [
    qw(make_response_test
      make_request_test
      warn_response
      warn_request
      )
  ] => (
    is      => 'ro',
    isa     => 'Bool',
    default => 0,
  );

has [
qw(response_test_dir
request_test_dir
)
] => (
is => 'ro',
isa => 'Str',
default => "",
);

and split the test creation into two seperate subs to make the code a little easier to read. Now as I am working on new (at least to me) parts of PAWS all I need to do is invoke my new caller (FullTestMakerLWPCaller) like this;


use FullTestMakerLWPCaller;

my $s3 = Paws->service('S3', region => 'us-east-1', caller=>FullTestMakerLWPCaller->new(make_response_test=>1,
make_request_test=>1,
warn_response=>1,
warn_request=>1,
response_test_dir=>'/home/scolesj/S3',
request_test_dir=>'/home/scolesj/S3'));

$ListObjectsV2Output = $s3->PutBucketLifecycleConfiguration

and I will get my canned test files as part of my regular real world test.

The only issue I ran into when creating the above was that simply doing this;


 my $flat = $o->flatten($result_oject);

was not recursive on embedded objects. So something like the 'GetBucketLifecycleConfiguration' that returned an embedded object like this


 'Rules' => [
  bless( {
    'Expiration' => bless( {
           'Days' => '365'
         }, 'Paws::S3::LifecycleExpiration' ),
     'Filter' => bless( {
           'And' => bless( {
           'Tags' => [],
            'Prefix' => 'test'
          }, 'Paws::S3::LifecycleRuleAndOperator' ),
      'Prefix' => 'test'
     }, 'Paws::S3::LifecycleRuleFilter' ),
    'ID' => 'Rule1',

I would not convert that embedded item into a hash for me.

I did not waste a great deal of time on this as I had a snoop about figuring a previous developer would have had the same problems and I quickly found a 'sub to_hash' in 'Paws.pm' which worked just fine as all I needed to do was


  my $result_hash = $service->to_hash($result_oject);
…
  my $o = DataStruct::Flat->new(
        {
            HashDelimiter  => '.',
            ArrayDelimiter => '.',
        }
    );

my $flat = $o->flatten($result_hash);

and my tests all come out correctly.

The only other blip along the way was the file names. I was just a little too much work to get the get the file names to come out like 's3-get-bucket-lifecycleconfiguration'. Way to many edge cases for the amount of effort it takes to just rename a bunch of files on a dir.

In the end it works out a little better for me to keep it this way as I had to spend some time 'Obfuscateing' my tests anyway so I just change the name once I was done.

Just for info the 'Obfuscateing' that I had to do was mostly to change the bucket name to one that does not exists, changing in one or two places some log-in info and some logging locations and changing the 'region' over to the default EU one used by the tests suite.

All that being done I really only took me a few hours to come up with some 70 missing response tests.

Unfortunately I still can't do this


--warn "[% c.api %] is not stable / supported / entirely developed" unless  
  $ENV{'PAWS_SILENCE_UNSTABLE_WARNINGS'};

as I still have 'CloudFront', “Route53”, and “S3Control” to clean up first.

I guess I know what my next blog posts will be about.

hC3EAE813.jpg

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