Astro-ADS
view release on metacpan or search on metacpan
t/useragent.t view on Meta::CPAN
like(
warnings { $result = $search->query() }, # DEBUG = 0
[qr/HTTP Error: $error_message/], # my error message
#warnings { $result = $search->query() },
#[
#qr{^GET /v1/search/query.+Authorization: Bearer BAD_TOKEN}s, # DEBUG request
#qr/HTTP Error: $expected_error/,
#],
'Caught dev token error'
) or warn "\n#### Is \$Astro::ADS::DEBUG set to the expected value? ####\n\n";
is $result, object {
prop isa => 'Astro::ADS::Result';
field error => $expected_error;
field docs => [];
end();
}, 'Result contains the error message';
like(
warning { $result->rows() },
qr/^Empty Result object: $error_message/, # my error message
'Sensible warning when acting on a Result with an error'
);
};
subtest 'Token construction' => sub {
local $ENV{ADS_DEV_KEY} = undef;
local $ENV{HOME} = '/homeless';
my %options = ( q => 'star', fl => 'bibcode' );
my $ads = Astro::ADS->new( %options );
like(
dies { $ads->token },
qr/^You need to provide an API token/, # my error message
'Warning of no token'
);
$ENV{ADS_DEV_KEY} = "xxxxxxxxxxxxxxxxxxxxxxxxxx\n";
$ads = Astro::ADS->new( %options );
like(
dies { $ads->token },
qr/Value ".*" did not pass type constraint/,
'Invalid token provided'
);
my @chars = ('a' .. 'z', 'A' .. 'Z', 0 .. 9);
my $new_token = join "", map { @chars[rand(@chars)] } 1 .. 40;
$ENV{ADS_DEV_KEY} = $new_token;
$ads = Astro::ADS->new( %options );
is $ads->token, $new_token, '40 char key is valid';
};
=pod Can't seem to engineer a timeout
subtest 'Connection timeout' => sub {
$ua->connect_timeout(1);
my $search = Astro::ADS::Search->new( q => 'dark energy', sort => 'citation_count desc', rows => 100, ua => $ua);
$search->fl('ack,aff,aff_id,alternate_bibcode,alternate_title,arxiv_class,author,author_count,author_norm,bibcode,bibgroup,bibstem,citation,citation_count,cite_read_boost,classic_factor,comment,copyright,data,database,date,doctype,doi,eid,ent...
my $result = $search->query();
$DB::single = 1;
like $result->error, qr/Timeout/;
};
=cut
done_testing();
( run in 0.876 second using v1.01-cache-2.11-cpan-39bf76dae61 )