Skip to content

Commit

Permalink
test for 429 response
Browse files Browse the repository at this point in the history
  • Loading branch information
freyfogle committed Nov 10, 2019
1 parent b709c31 commit 5f32cb5
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions t/06-429-response.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use strict;
use warnings;
use utf8;
use Net::Ping;
use Test::More;
use Test::Warn;

binmode Test::More->builder->output, ":encoding(utf8)";
binmode Test::More->builder->failure_output, ":encoding(utf8)";
binmode Test::More->builder->todo_output, ":encoding(utf8)";

use lib './lib'; # actually use the module, not other versions installed
use Geo::Coder::OpenCage;

# TODO should move this into module to share with other tests
my $api_ip_num = '95.216.176.62';
my $p = Net::Ping->new;
my $have_connection = 0;
if ($p->ping($api_ip_num, 1)) {
$have_connection = 1;
}

SKIP: {
skip 'skipping test that requires connectivity', 2 unless ($have_connection);

# use special key OpenCage makes available for testing
my $api_key = 'd6d0f0065f4348a4bdfe4587ba02714b';

my $geocoder = Geo::Coder::OpenCage->new(
api_key => $api_key,
);

{
my $result;
warning_like
{ $result = $geocoder->reverse_geocode('lat'=> 41.40139, 'lng'=> 2.12870); }
[ qr/429, requesting too quickly/ ],
"got too quickly warning";
is($result, undef, 'correctly returned undef for 429 response');
}
}

done_testing();

0 comments on commit 5f32cb5

Please sign in to comment.