| 1 | package Shared::Examples::Net::Amazon::S3; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: used for testing and as example | ||||||||||||||||||||||||||||
| 3 | 90 | $Shared::Examples::Net::Amazon::S3::VERSION = '0.992'; | |||||||||||||||||||||||||||
| 4 | 90 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 90 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 90 | ▶ | use parent qw[ Exporter::Tiny ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 90 | ▶ | use Hash::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 90 | ▶ | use Ref::Util ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 90 | qw[ is_regexpref ], | |||||||||||||||||||||||||||
| 12 | 90 | ); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 90 | ▶ | use Test::Deep; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 90 | ▶ | use Test::More; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 90 | ▶ | use Test::LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 90 | ▶ | use Net::Amazon::S3; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 90 | ▶ | use Shared::Examples::Net::Amazon::S3::API; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 90 | ▶ | use Shared::Examples::Net::Amazon::S3::Client; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 90 | ▶ | use Shared::Examples::Net::Amazon::S3::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 90 | our @EXPORT_OK = ( | |||||||||||||||||||||||||||
| 25 | qw[ s3_api_with_signature_4 ], | ||||||||||||||||||||||||||||
| 26 | qw[ s3_api_with_signature_2 ], | ||||||||||||||||||||||||||||
| 27 | qw[ expect_net_amazon_s3_feature ], | ||||||||||||||||||||||||||||
| 28 | qw[ expect_net_amazon_s3_operation ], | ||||||||||||||||||||||||||||
| 29 | qw[ expect_operation_list_all_my_buckets ], | ||||||||||||||||||||||||||||
| 30 | qw[ expect_operation_bucket_create ], | ||||||||||||||||||||||||||||
| 31 | qw[ expect_operation_bucket_delete ], | ||||||||||||||||||||||||||||
| 32 | qw[ with_fixture ], | ||||||||||||||||||||||||||||
| 33 | qw[ fixture ], | ||||||||||||||||||||||||||||
| 34 | qw[ with_response_fixture ], | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 90 | my %fixtures; | |||||||||||||||||||||||||||
| 38 | 177 | ▶ | sub fixture { | ||||||||||||||||||||||||||
|
Subroutine
fixture: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 177 | my ($name) = @_; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | $fixtures{$name} = eval "require Shared::Examples::Net::Amazon::S3::Fixture::$name" | ||||||||||||||||||||||||||||
| 42 | 177 | ▶ | unless defined $fixtures{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | die "Fixture $name not found: $@" | ||||||||||||||||||||||||||||
| 45 | 177 | ▶ | unless defined $fixtures{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 177 | return +{ %{ $fixtures{$name} } }; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub with_fixture { | ||||||||||||||||||||||||||
|
Subroutine
with_fixture: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 0 | my ($name) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | my $fixture = fixture ($name); | |||||||||||||||||||||||||||
| 54 | return wantarray | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | ? %$fixture | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | : $fixture | ||||||||||||||||||||||||||||
| 57 | ; | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 167 | ▶ | sub with_response_fixture { | ||||||||||||||||||||||||||
|
Subroutine
with_response_fixture: called CC=8 SCAR=21.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 167 | my ($name) = @_; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 167 | my $fixture = fixture ($name); | |||||||||||||||||||||||||||
| 64 | 167 | my $response_fixture = {}; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 167 | for my $key (keys %$fixture) { | |||||||||||||||||||||||||||
| 67 | 556 | my $new_key; | |||||||||||||||||||||||||||
| 68 | 556 | ▶ | $new_key ||= "with_response_data" if $key eq 'content'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$new_key ||= "with_response_data"
MC/DC0%0/1
$new_key ||= "with_response_data"
$new_key
Truth table50%1/2
A
A= $new_key
| |||||||||||||||||||||||||||||
| 69 | 556 | ▶ | $new_key ||= "with_$key" if $key =~ m/^response/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$new_key ||= "with_$key"
MC/DC0%0/1
$new_key ||= "with_$key"
$new_key
Truth table50%1/2
A
A= $new_key
| |||||||||||||||||||||||||||||
| 70 | 556 | ▶ | $new_key ||= "with_response_header_$key"; | ||||||||||||||||||||||||||
|
Condition100%2/2
$new_key ||= "with_response_header_$key"
MC/DC100%1/1
$new_key ||= "with_response_header_$key"
$new_key
Truth table100%2/2
A
A= $new_key
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 556 | $response_fixture->{$new_key} = $fixture->{$key}; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | return wantarray | ||||||||||||||||||||||||||||
| 76 | 167 | ▶ | ? %$response_fixture | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | : $response_fixture | ||||||||||||||||||||||||||||
| 78 | ; | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 405 | ▶ | sub s3_api { | ||||||||||||||||||||||||||
|
Subroutine
s3_api: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 83 | 405 | my $api = Net::Amazon::S3->new (@_); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 405 | $api->ua (Test::LWP::UserAgent->new (network_fallback => 0)); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 405 | $api; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 210 | ▶ | sub s3_api_mock_http_response { | ||||||||||||||||||||||||||
|
Subroutine
s3_api_mock_http_response: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 91 | 210 | my ($self, $api, %params) = @_; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 210 | ▶ | $params{with_response_code} ||= HTTP::Status::HTTP_OK; | ||||||||||||||||||||||||||
|
Condition100%2/2
$params{"with_response_code"} ||= 200
MC/DC100%1/1
$params{"with_response_code"} ||= 200
$params{"with_response_code"}
Truth table100%2/2
A
A= $params{"with_response_code"}
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | my %headers = ( | ||||||||||||||||||||||||||||
| 96 | content_type => 'application/xml', | ||||||||||||||||||||||||||||
| 97 | ( | ||||||||||||||||||||||||||||
| 98 | map { | ||||||||||||||||||||||||||||
| 99 | 2117 | m/^with_response_header_(.*)/; | |||||||||||||||||||||||||||
| 100 | defined $1 && length $1 | ||||||||||||||||||||||||||||
| 101 | 2117 | ▶ | ? ($1 => $params{$_}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $1 and length $1
MC/DC50%1/2
defined $1 and length $1
defined $1
length $1
Truth table66%2/3
A and B
A= defined $1B= length $1
| |||||||||||||||||||||||||||||
| 102 | : () | ||||||||||||||||||||||||||||
| 103 | } keys %params | ||||||||||||||||||||||||||||
| 104 | ), | ||||||||||||||||||||||||||||
| 105 | 210 | ▶ | %{ $params{with_response_headers} || {} }, | ||||||||||||||||||||||||||
|
Condition100%2/2
$params{'with_response_headers'} || {}
MC/DC100%1/1
$params{'with_response_headers'} || {}
$params{'with_response_headers'}
Truth table100%2/2
A
A= $params{'with_response_headers'}
| |||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | $api->ua->map_response ( | ||||||||||||||||||||||||||||
| 109 | 210 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 110 | 210 | ${ $params{into} } = $_[0]; | |||||||||||||||||||||||||||
| 111 | 210 | 1; | |||||||||||||||||||||||||||
| 112 | }, | ||||||||||||||||||||||||||||
| 113 | HTTP::Response->new ( | ||||||||||||||||||||||||||||
| 114 | $params{with_response_code}, | ||||||||||||||||||||||||||||
| 115 | HTTP::Status::status_message ($params{with_response_code}), | ||||||||||||||||||||||||||||
| 116 | [ %headers ], | ||||||||||||||||||||||||||||
| 117 | $params{with_response_data}, | ||||||||||||||||||||||||||||
| 118 | 210 | ), | |||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 4 | ▶ | sub s3_api_with_signature_4 { | ||||||||||||||||||||||||||
|
Subroutine
s3_api_with_signature_4: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 123 | 4 | s3_api ( | |||||||||||||||||||||||||||
| 124 | @_, | ||||||||||||||||||||||||||||
| 125 | aws_access_key_id => 'AKIDEXAMPLE', | ||||||||||||||||||||||||||||
| 126 | aws_secret_access_key => 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY', | ||||||||||||||||||||||||||||
| 127 | authorization_method => 'Net::Amazon::S3::Signature::V4', | ||||||||||||||||||||||||||||
| 128 | secure => 1, | ||||||||||||||||||||||||||||
| 129 | use_virtual_host => 1, | ||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 401 | ▶ | sub s3_api_with_signature_2 { | ||||||||||||||||||||||||||
|
Subroutine
s3_api_with_signature_2: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 134 | 401 | s3_api ( | |||||||||||||||||||||||||||
| 135 | @_, | ||||||||||||||||||||||||||||
| 136 | aws_access_key_id => 'AKIDEXAMPLE', | ||||||||||||||||||||||||||||
| 137 | aws_secret_access_key => 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY', | ||||||||||||||||||||||||||||
| 138 | authorization_method => 'Net::Amazon::S3::Signature::V2', | ||||||||||||||||||||||||||||
| 139 | secure => 1, | ||||||||||||||||||||||||||||
| 140 | use_virtual_host => 1, | ||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 4 | ▶ | sub expect_net_amazon_s3_feature { | ||||||||||||||||||||||||||
|
Subroutine
expect_net_amazon_s3_feature: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 145 | 4 | my ($title, %params) = @_; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 4 | my $s3 = delete $params{with_s3}; | |||||||||||||||||||||||||||
| 148 | 4 | my $feature = delete $params{feature}; | |||||||||||||||||||||||||||
| 149 | 4 | my $expectation = "expect_$feature"; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 4 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 4 | ▶ | subtest $title => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.3
| |||||||||||||||||||||||||||||
| 154 | 4 | plan tests => 2; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 4 | ▶ | if (my $code = Shared::Examples::Net::Amazon::S3::API->can ($expectation)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 4 | $code->( "using S3 API" => ( | |||||||||||||||||||||||||||
| 158 | with_s3 => $s3, | ||||||||||||||||||||||||||||
| 159 | %params | ||||||||||||||||||||||||||||
| 160 | )); | ||||||||||||||||||||||||||||
| 161 | } else { | ||||||||||||||||||||||||||||
| 162 | 0 | fail "Net::Amazon::S3 feature expectation $expectation not found"; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 4 | ▶ | if (my $code = Shared::Examples::Net::Amazon::S3::Client->can ($expectation)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 4 | $code->( "using S3 Client" => ( | |||||||||||||||||||||||||||
| 167 | with_client => Net::Amazon::S3::Client->new (s3 => $s3), | ||||||||||||||||||||||||||||
| 168 | %params | ||||||||||||||||||||||||||||
| 169 | )); | ||||||||||||||||||||||||||||
| 170 | } else { | ||||||||||||||||||||||||||||
| 171 | 0 | fail "Net::Amazon::S3::Client feature expectation $expectation not found"; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | 4 | }; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub _operation_parameters { | ||||||||||||||||||||||||||
|
Subroutine
_operation_parameters: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 177 | 0 | my ($params, @names) = @_; | |||||||||||||||||||||||||||
| 178 | 0 | my $map = {}; | |||||||||||||||||||||||||||
| 179 | 0 | ▶ | $map = shift @names if Ref::Util::is_plain_hashref ($names[0]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | return | ||||||||||||||||||||||||||||
| 182 | map +( ($map->{$_} || $_) => $params->{"with_$_"} ), | ||||||||||||||||||||||||||||
| 183 | 0 | ▶ | grep exists $params->{"with_$_"}, | ||||||||||||||||||||||||||
|
Condition0%0/3
$map->{$_} || $_
MC/DC0%0/2
$map->{$_} || $_
$map->{$_}
$_
Truth table0%0/3
A || B
A= $map->{$_}B= $_
| |||||||||||||||||||||||||||||
| 184 | @names | ||||||||||||||||||||||||||||
| 185 | ; | ||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 210 | ▶ | sub _with_keys { | ||||||||||||||||||||||||||
|
Subroutine
_with_keys: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 189 | 210 | map "with_$_", @_; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 210 | ▶ | sub _keys_operation () { | ||||||||||||||||||||||||||
|
Subroutine
_keys_operation: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 193 | return ( | ||||||||||||||||||||||||||||
| 194 | 210 | qw[ -shared_examples ], | |||||||||||||||||||||||||||
| 195 | qw[ -method ], | ||||||||||||||||||||||||||||
| 196 | qw[ with_s3 ], | ||||||||||||||||||||||||||||
| 197 | qw[ with_client ], | ||||||||||||||||||||||||||||
| 198 | qw[ shared_examples ], | ||||||||||||||||||||||||||||
| 199 | qw[ with_response_code ], | ||||||||||||||||||||||||||||
| 200 | qw[ with_response_data ], | ||||||||||||||||||||||||||||
| 201 | qw[ with_response_headers ], | ||||||||||||||||||||||||||||
| 202 | qw[ with_response_header_content_type ], | ||||||||||||||||||||||||||||
| 203 | qw[ with_response_header_content_length ], | ||||||||||||||||||||||||||||
| 204 | qw[ expect_s3_err ], | ||||||||||||||||||||||||||||
| 205 | qw[ expect_s3_errstr ], | ||||||||||||||||||||||||||||
| 206 | qw[ expect_data ], | ||||||||||||||||||||||||||||
| 207 | qw[ expect_request ], | ||||||||||||||||||||||||||||
| 208 | qw[ expect_request_content ], | ||||||||||||||||||||||||||||
| 209 | qw[ expect_request_headers ], | ||||||||||||||||||||||||||||
| 210 | qw[ throws ], | ||||||||||||||||||||||||||||
| 211 | ); | ||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 201 | ▶ | sub _expect_request { | ||||||||||||||||||||||||||
|
Subroutine
_expect_request: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 215 | 201 | my ($request, $expect, $title) = @_; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 201 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 201 | my ($method, $uri) = %$expect; | |||||||||||||||||||||||||||
| 220 | 201 | ▶ | cmp_deeply | ||||||||||||||||||||||||||
|
Condition50%1/2
$title || 'expect request'
MC/DC0%0/1
$title || 'expect request'
$title
Truth table50%1/2
A
A= $title
| |||||||||||||||||||||||||||||
| 221 | $request, | ||||||||||||||||||||||||||||
| 222 | all ( | ||||||||||||||||||||||||||||
| 223 | methods (method => $method), | ||||||||||||||||||||||||||||
| 224 | methods (uri => methods (as_string => $uri)), | ||||||||||||||||||||||||||||
| 225 | ), | ||||||||||||||||||||||||||||
| 226 | $title || 'expect request' | ||||||||||||||||||||||||||||
| 227 | ; | ||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 64 | ▶ | sub _expect_request_content { | ||||||||||||||||||||||||||
|
Subroutine
_expect_request_content: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 231 | 64 | my ($request, $expected, $title) = @_; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 64 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 64 | my $got = Shared::Examples::Net::Amazon::S3::Request::_canonical_xml ($request->content); | |||||||||||||||||||||||||||
| 236 | 64 | $expected = Shared::Examples::Net::Amazon::S3::Request::_canonical_xml ($expected); | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 64 | ▶ | cmp_deeply $got, $expected, $title || "expect request content"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$title || 'expect request content'
MC/DC0%0/1
$title || 'expect request content'
$title
Truth table50%1/2
A
A= $title
| |||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 51 | ▶ | sub _expect_request_headers { | ||||||||||||||||||||||||||
|
Subroutine
_expect_request_headers: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 242 | 51 | my ($request, $expected, $title) = @_; | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 51 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 51 | my %got = map +($_ => scalar $request->header ($_)), keys %$expected; | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 51 | ▶ | cmp_deeply | ||||||||||||||||||||||||||
|
Condition50%1/2
$title || 'expect request headers'
MC/DC0%0/1
$title || 'expect request headers'
$title
Truth table50%1/2
A
A= $title
| |||||||||||||||||||||||||||||
| 249 | \ %got, | ||||||||||||||||||||||||||||
| 250 | $expected, | ||||||||||||||||||||||||||||
| 251 | $title || "expect request headers" | ||||||||||||||||||||||||||||
| 252 | ; | ||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 62 | ▶ | sub _expect_s3_err { | ||||||||||||||||||||||||||
|
Subroutine
_expect_s3_err: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||
| 256 | 62 | my ($got, $expected, $title) = @_; | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | SKIP: { | ||||||||||||||||||||||||||||
| 259 | 62 | ▶ | skip "Net::Amazon::S3->err test irrelevant for Client", 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | if eq_deeply $got, obj_isa ('Net::Amazon::S3::Client'); | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 62 | ▶ | cmp_deeply $got, methods (err => $expected), $title || 'expect S3->err'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$title || 'expect S3->err'
MC/DC0%0/1
$title || 'expect S3->err'
$title
Truth table50%1/2
A
A= $title
| |||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 62 | ▶ | sub _expect_s3_errstr { | ||||||||||||||||||||||||||
|
Subroutine
_expect_s3_errstr: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||
| 267 | 62 | my ($got, $expected, $title) = @_; | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | SKIP: { | ||||||||||||||||||||||||||||
| 270 | 62 | ▶ | skip "Net::Amazon::S3->errstr test irrelevant for Client", 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | if eq_deeply $got, obj_isa ('Net::Amazon::S3::Client'); | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 62 | ▶ | cmp_deeply $got, methods (errstr => $expected), $title || 'expect S3->errstr'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$title || 'expect S3->errstr'
MC/DC0%0/1
$title || 'expect S3->errstr'
$title
Truth table50%1/2
A
A= $title
| |||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 210 | ▶ | sub _expect_operation { | ||||||||||||||||||||||||||
|
Subroutine
_expect_operation: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 278 | 210 | my ($title, %params) = @_; | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 210 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 210 | my $class = delete $params{-shared_examples}; | |||||||||||||||||||||||||||
| 283 | 210 | my $operation = delete $params{-operation}; | |||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 210 | my $api = $class->_default_with_api (\%params); | |||||||||||||||||||||||||||
| 286 | 210 | $class->_mock_http_response ($api, %params, into => \ (my $request)); | |||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 210 | ▶ | if (my $code = $class->can ($operation)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 210 | ▶ | subtest $title => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=25.1
| |||||||||||||||||||||||||||||
| 290 | plan tests => 1 | ||||||||||||||||||||||||||||
| 291 | + int (!! exists $params{expect_request}) | ||||||||||||||||||||||||||||
| 292 | + int (!! exists $params{expect_request_content}) | ||||||||||||||||||||||||||||
| 293 | + int (!! exists $params{expect_request_headers}) | ||||||||||||||||||||||||||||
| 294 | + int (!! exists $params{expect_s3_err}) | ||||||||||||||||||||||||||||
| 295 | + int (!! exists $params{expect_s3_errstr}) | ||||||||||||||||||||||||||||
| 296 | 210 | ; | |||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 210 | my $got; | |||||||||||||||||||||||||||
| 299 | 210 | my $lives = eval { $got = $api->$code (%params); 1 }; | |||||||||||||||||||||||||||
| 300 | 210 | my $error = $@; | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 210 | ▶ | if ($lives) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | exists $params{throws} | ||||||||||||||||||||||||||||
| 304 | ? fail "operation expected to throw but lives" | ||||||||||||||||||||||||||||
| 305 | 141 | ▶ | : cmp_deeply $got, $params{expect_data}, "expect operation return data" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | ; | ||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | else { | ||||||||||||||||||||||||||||
| 309 | $params{throws} = re $params{throws} | ||||||||||||||||||||||||||||
| 310 | 69 | ▶ | if is_regexpref $params{throws}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | $params{throws} = obj_isa $params{throws} | ||||||||||||||||||||||||||||
| 312 | 69 | ▶ | if defined $params{throws} && ! ref $params{throws}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $params{"throws"} and not ref $params{"throws"}
MC/DC50%1/2
defined $params{"throws"} and not ref $params{"throws"}
defined $params{"throws"}
not ref $params{"throws"}
Truth table66%2/3
A and not(B)
A= defined $params{"throws"}B= not ref $params{"throws"}
| |||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | defined $params{throws} | ||||||||||||||||||||||||||||
| 315 | ? cmp_deeply $error, $params{throws}, "it should throw" | ||||||||||||||||||||||||||||
| 316 | 0 | ▶ | : do { fail "operation expected to live but died" ; diag $error } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | ; | ||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | _expect_request $request, $params{expect_request} | ||||||||||||||||||||||||||||
| 321 | 210 | ▶ | if exists $params{expect_request}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | _expect_request_content $request, $params{expect_request_content} | ||||||||||||||||||||||||||||
| 323 | 210 | ▶ | if exists $params{expect_request_content}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | _expect_request_headers ($request, $params{expect_request_headers}) | ||||||||||||||||||||||||||||
| 325 | 210 | ▶ | if exists $params{expect_request_headers}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | _expect_s3_err $api, $params{expect_s3_err} | ||||||||||||||||||||||||||||
| 328 | 210 | ▶ | if exists $params{expect_s3_err}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | _expect_s3_errstr $api, $params{expect_s3_errstr} | ||||||||||||||||||||||||||||
| 330 | 210 | ▶ | if exists $params{expect_s3_errstr}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 210 | }; | |||||||||||||||||||||||||||
| 332 | } else { | ||||||||||||||||||||||||||||
| 333 | 0 | ▶ | fail $title or diag "Operation ${class}::$operation not found"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 1530 | ▶ | sub _generate_operation_expectation { | ||||||||||||||||||||||||||
|
Subroutine
_generate_operation_expectation: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 338 | 1530 | my ($name, @parameters) = @_; | |||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 1530 | my @on = ( | |||||||||||||||||||||||||||
| 341 | ('bucket') x!! ($name =~ m/^ ( bucket | object )/x), | ||||||||||||||||||||||||||||
| 342 | ('key') x!! ($name =~ m/^ ( object )/x), | ||||||||||||||||||||||||||||
| 343 | ); | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 1530 | my $on = "qw[ ${ \ join ' ', @on } ]"; | |||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 1530 | ▶ | eval <<"OPERATION_DECLARATION"; | ||||||||||||||||||||||||||
|
Subroutine
expect_operation_bucket_acl_get: called CC=1 SCAR=0.0
Subroutine
expect_operation_bucket_acl_set: called CC=1 SCAR=0.0
Subroutine
expect_operation_bucket_create: called CC=1 SCAR=0.0
Subroutine
expect_operation_bucket_delete: called CC=1 SCAR=0.0
Subroutine
expect_operation_bucket_objects_delete: called CC=1 SCAR=0.0
Subroutine
expect_operation_bucket_objects_list: called CC=1 SCAR=0.0
Subroutine
expect_operation_bucket_tags_add: called CC=1 SCAR=0.0
Subroutine
expect_operation_bucket_tags_delete: called CC=1 SCAR=0.0
Subroutine
expect_operation_list_all_my_buckets: called CC=1 SCAR=0.0
Subroutine
expect_operation_object_acl_get: called CC=1 SCAR=0.0
Subroutine
expect_operation_object_acl_set: called CC=1 SCAR=0.0
Subroutine
expect_operation_object_create: called CC=1 SCAR=0.0
Subroutine
expect_operation_object_delete: called CC=1 SCAR=0.0
Subroutine
expect_operation_object_fetch: called CC=1 SCAR=0.0
Subroutine
expect_operation_object_head: called CC=1 SCAR=0.0
Subroutine
expect_operation_object_tags_add: called CC=1 SCAR=0.0
Subroutine
expect_operation_object_tags_delete: called CC=1 SCAR=0.0
Subroutine
parameters_bucket_acl_get: called CC=1 SCAR=0.0
Subroutine
parameters_bucket_acl_set: called CC=1 SCAR=0.0
Subroutine
parameters_bucket_create: called CC=1 SCAR=0.0
Subroutine
parameters_bucket_delete: called CC=1 SCAR=0.0
Subroutine
parameters_bucket_objects_delete: called CC=1 SCAR=0.0
Subroutine
parameters_bucket_objects_list: called CC=1 SCAR=0.0
Subroutine
parameters_bucket_tags_add: called CC=1 SCAR=0.0
Subroutine
parameters_bucket_tags_delete: called CC=1 SCAR=0.0
Subroutine
parameters_list_all_my_buckets: called CC=1 SCAR=0.0
Subroutine
parameters_object_acl_get: called CC=1 SCAR=0.0
Subroutine
parameters_object_acl_set: called CC=1 SCAR=0.0
Subroutine
parameters_object_create: called CC=1 SCAR=0.0
Subroutine
parameters_object_delete: called CC=1 SCAR=0.0
Subroutine
parameters_object_fetch: called CC=1 SCAR=0.0
Subroutine
parameters_object_head: called CC=1 SCAR=0.0
Subroutine
parameters_object_tags_add: called CC=1 SCAR=0.0
Subroutine
parameters_object_tags_delete: called CC=1 SCAR=0.0
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
| |||||||||||||||||||||||||||||
| 348 | sub parameters_$name { | ||||||||||||||||||||||||||||
| 349 | 1530 | qw[ ${ \ join ' ', @parameters } ] | |||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | sub expect_operation_$name { | ||||||||||||||||||||||||||||
| 353 | my (\$title, \%params) = \@_; | ||||||||||||||||||||||||||||
| 354 | local \$Test::Builder::Level = \$Test::Builder::Level + 1; | ||||||||||||||||||||||||||||
| 355 | Hash::Util::lock_keys \%params, _with_keys ($on, parameters_$name), _keys_operation; | ||||||||||||||||||||||||||||
| 356 | _expect_operation \$title, \%params, -operation => 'operation_$name'; | ||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | OPERATION_DECLARATION | ||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 90 | _generate_operation_expectation list_all_my_buckets => | |||||||||||||||||||||||||||
| 362 | ; | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 90 | _generate_operation_expectation bucket_acl_get => | |||||||||||||||||||||||||||
| 365 | ; | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 90 | _generate_operation_expectation bucket_acl_set => | |||||||||||||||||||||||||||
| 368 | qw[ acl ], | ||||||||||||||||||||||||||||
| 369 | qw[ acl_xml ], | ||||||||||||||||||||||||||||
| 370 | qw[ acl_short ], | ||||||||||||||||||||||||||||
| 371 | ; | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 90 | _generate_operation_expectation bucket_create => | |||||||||||||||||||||||||||
| 374 | qw[ acl ], | ||||||||||||||||||||||||||||
| 375 | qw[ acl_short ], | ||||||||||||||||||||||||||||
| 376 | qw[ region ], | ||||||||||||||||||||||||||||
| 377 | ; | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 90 | _generate_operation_expectation bucket_delete => | |||||||||||||||||||||||||||
| 380 | ; | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 90 | _generate_operation_expectation bucket_objects_list => | |||||||||||||||||||||||||||
| 383 | qw[ delimiter ], | ||||||||||||||||||||||||||||
| 384 | qw[ max_keys ], | ||||||||||||||||||||||||||||
| 385 | qw[ marker ], | ||||||||||||||||||||||||||||
| 386 | qw[ prefix ], | ||||||||||||||||||||||||||||
| 387 | ; | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 90 | _generate_operation_expectation bucket_objects_delete => | |||||||||||||||||||||||||||
| 390 | qw[ keys ], | ||||||||||||||||||||||||||||
| 391 | ; | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 90 | _generate_operation_expectation object_acl_get => | |||||||||||||||||||||||||||
| 394 | ; | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 90 | _generate_operation_expectation object_acl_set => | |||||||||||||||||||||||||||
| 397 | qw[ acl ], | ||||||||||||||||||||||||||||
| 398 | qw[ acl_xml ], | ||||||||||||||||||||||||||||
| 399 | qw[ acl_short ], | ||||||||||||||||||||||||||||
| 400 | ; | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 90 | _generate_operation_expectation object_create => | |||||||||||||||||||||||||||
| 403 | qw[ headers ], | ||||||||||||||||||||||||||||
| 404 | qw[ value ], | ||||||||||||||||||||||||||||
| 405 | qw[ cache_control ], | ||||||||||||||||||||||||||||
| 406 | qw[ content_disposition ], | ||||||||||||||||||||||||||||
| 407 | qw[ content_encoding ], | ||||||||||||||||||||||||||||
| 408 | qw[ content_type ], | ||||||||||||||||||||||||||||
| 409 | qw[ encryption ], | ||||||||||||||||||||||||||||
| 410 | qw[ expires ], | ||||||||||||||||||||||||||||
| 411 | qw[ storage_class ], | ||||||||||||||||||||||||||||
| 412 | qw[ user_metadata ], | ||||||||||||||||||||||||||||
| 413 | qw[ acl ], | ||||||||||||||||||||||||||||
| 414 | qw[ acl_short ], | ||||||||||||||||||||||||||||
| 415 | ; | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 90 | _generate_operation_expectation object_delete => | |||||||||||||||||||||||||||
| 418 | ; | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 90 | _generate_operation_expectation object_fetch => | |||||||||||||||||||||||||||
| 421 | qw[ range ], | ||||||||||||||||||||||||||||
| 422 | ; | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | 90 | _generate_operation_expectation object_head => | |||||||||||||||||||||||||||
| 425 | ; | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | 90 | _generate_operation_expectation bucket_tags_add => | |||||||||||||||||||||||||||
| 428 | qw[ tags ], | ||||||||||||||||||||||||||||
| 429 | ; | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | 90 | _generate_operation_expectation object_tags_add => | |||||||||||||||||||||||||||
| 432 | qw[ tags ], | ||||||||||||||||||||||||||||
| 433 | qw[ version_id ], | ||||||||||||||||||||||||||||
| 434 | ; | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 90 | _generate_operation_expectation bucket_tags_delete => | |||||||||||||||||||||||||||
| 437 | ; | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | 90 | _generate_operation_expectation object_tags_delete => | |||||||||||||||||||||||||||
| 440 | qw[ version_id ], | ||||||||||||||||||||||||||||
| 441 | ; | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 90 | 1; | |||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | __END__ | ||||||||||||||||||||||||||||