1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
use strict;
use warnings;
use FindBin ();
use lib "$FindBin::Bin/lib";
use Test::More;
use TestServer qw(se_address json new_client);
use Cepis;
is( Cepis::Client->new( base_url => 'http://x/' )->base_url,
'http://x', 'a trailing slash is stripped' );
is( Cepis::Client->new( base_url => 'http://x///' )->base_url,
'http://x', 'and so are several' );
is( Cepis::Client->new->base_url, 'https://cep.is', 'the default base_url' );
is( Cepis::Client::DEFAULT_URL(), 'https://cep.is', 'DEFAULT_URL agrees' );
is( Cepis::Client::MAX_BATCH(), 500, 'MAX_BATCH is the API limit' );
for my $bad (
{ max_attempts => 0 },
{ max_attempts => -1 },
{ timeout => 0 },
{ timeout => -1 },
{ backoff_max => -1 },
)
{
my ($name) = keys %$bad;
my $ok = eval { Cepis::Client->new(%$bad); 1 };
ok( !$ok, "$name = $bad->{$name} is rejected" );
}
my $client = Cepis::Client->new;
like( $client->user_agent, qr{\Acepis-perl/0\.1\.0 }, 'the User-Agent names the library' );
like( $client->user_agent, qr{https://cep\.is}, 'and where to find it' );
is( Cepis::Client->new( user_agent => 'myapp/1.0' )->user_agent,
'myapp/1.0', 'the User-Agent is overridable' );
is( $client->timeout, 10, 'default timeout' );
is( $client->max_attempts, 3, 'default max_attempts' );
is( $client->backoff_base, 0.5, 'default backoff_base' );
is( $client->backoff_max, 8, 'default backoff_max' );
is( $client->total_timeout, undef, 'no total_timeout by default' );
isa_ok( Cepis::default_client(), 'Cepis::Client' );
is( Cepis::default_client(), Cepis::default_client(), 'the default client is built once' );
{
my $server = TestServer->new(
routes => {
'/01001000' => [ 200, json( se_address() ), {} ],
'/health' => [ 200, json( { status => 'ok' } ), {} ],
}
);
my $custom = new_client($server);
is( $custom->lookup('01001000')->uf, 'SP', 'base_url really redirects the client' );
ok( $custom->health->ok, 'for every endpoint' );
$server->stop;
}
done_testing();
|