I rewrote it. I thought I had everything together, used the same SQL queries, but I wanted to be sure it kicked out the same output.
So, I wrote tests using Perl's Test::Most and
cmp_deeply()
.A few weeks ago, I knew Perl testing existed but I didn't know much about it. Now it's practical.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use feature qw'say state' ; | |
use subs qw'uniq' ; | |
use Data::Dumper ; | |
use JSON ; | |
use LWP::UserAgent ; | |
use Test::Most ; | |
my $agent = LWP::UserAgent->new() ; | |
$agent->credentials( | |
# AS IF I'd GIVE YOU THIS | |
); | |
my $server = 'https://myserver.test/apis' ; | |
my @endpoints = qw{ | |
first | |
second | |
third | |
fourt | |
} ; | |
my $comp ; | |
for my $endpoint ( @endpoints ) { | |
for my $api ( qw{ test_api newest_api } ) { | |
my $url = join '/' , | |
$server , | |
$api , | |
$endpoint ; | |
my $response = $agent->get( $url ) ; | |
$comp->{ $endpoint }->{ $api } = decode_json( $response->content() ) ; | |
} | |
} | |
for my $endpoint ( sort keys %$comp ) { | |
my $data = $comp->{ $endpoint } ; | |
cmp_deeply( | |
$data->{ test_api } , | |
$data->{ newest_api } , | |
"-- $endpoint is the same" | |
) ; | |
} | |
done_testing() ; |
No comments:
Post a Comment