summaryrefslogtreecommitdiffstats
path: root/t/07-config.t
diff options
context:
space:
mode:
authorMurilo Ijanc <[email protected]>2026-07-26 14:40:05 -0300
committerMurilo Ijanc <[email protected]>2026-07-26 14:40:05 -0300
commit0bc578d6d334c7f1ccaf329cd61bb8bce76b7f59 (patch)
tree86f73108f0432fd8330edcaab8b8ae7018322dee /t/07-config.t
downloadperl-6661cb35162c38099b86f248b938f5e4d4d11515.tar.gz
Initial importv0.1.0
Diffstat (limited to 't/07-config.t')
-rw-r--r--t/07-config.t63
1 files changed, 63 insertions, 0 deletions
diff --git a/t/07-config.t b/t/07-config.t
new file mode 100644
index 0000000..5c6f19b
--- /dev/null
+++ b/t/07-config.t
@@ -0,0 +1,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();