Amazon-DynamoDB

 view release on metacpan or  search on metacpan

t/03-simple-get-put.t  view on Meta::CPAN

#!perl
use strict;
use warnings;
use lib ('lib', './t');
use Test::Most;
use Test::Differences;
use TestSettings;
use Data::Dumper;

unless ( $ENV{'AMAZON_DYNAMODB_EXPENSIVE_TESTS'} ) {
    plan skip_all => 'Testing this module for real costs money.';
} else {
    plan tests => 84;
}

bail_on_fail;

my $ddb = TestSettings::get_ddb();
my $table_name = TestSettings::random_table_name();

my $create = $ddb->create_table(TableName => $table_name,
                                ReadCapacityUnits => 2,
                                WriteCapacityUnits => 2,
                                AttributeDefinitions => {
                                    user_id => 'N',
                                },
                                KeySchema => ['user_id'],
                            );

ok($create->is_done, "Create request was completed");

my $wait = $ddb->wait_for_table_status(TableName => $table_name);

ok($wait->is_done, "Created table is ready");


my $source_data = {
    email => 'test@example.com',
    user_id => 1,
    name => 'Rusty Conover',
    names => ['R. Conover', 'Rusty Conover'],
    numbers => [1, 3, 5, 5.002],
    numbers_and_strings => [1, 3, 5, "5.002.3.2.3"],
    test_binary => \'Rusty Conover',
    test_binary_array => [\'rusty', \'conover'],
};


{
    my $put = $ddb->put_item(TableName => $table_name,
                             Item => $source_data);
    ok($put->is_done, "put_item completed successfully");
    is_deeply($put->get(), {}, "Results of put_item with no attributes returned didn't return any.");
}


{
    my $put = $ddb->put_item(TableName => $table_name,
                             ReturnItemCollectionMetrics => 'SIZE',
                             Item => $source_data);
    ok($put->is_done, "put_item completed successfully");
    is_deeply($put->get(), {}, "Results of put_item with no attributes returned didn't return any.");
}



( run in 2.108 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )