Skip to content

Commit

Permalink
closes #4; closes #5; closes #6
Browse files Browse the repository at this point in the history
- added t/05-timeout tests (renders #4 as invalid)
- reduced timeout in t/04-filter, and wrapped in eval (#5)
- added tests for _set_error() (#6)
  • Loading branch information
stevieb9 committed Feb 8, 2016
1 parent ef064c5 commit 6019b04
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 32 deletions.
11 changes: 7 additions & 4 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
Revision history for WWW-FreeProxyListsCom

1.003 xxx
1.003 2016-02-08
- added Test::Perl::Critic tests
- get_list() in t/00-load.t wasn't passing in the type param,
which resulted in the default 'elite' type being used on\
each test iteration (fixes #1)
- get_list() in t/00-load.t wasn't passing in the type param, which
resulted in the default 'elite' type being used on each test
iteration (fixes #1)
- moved xt/ tests to t/
- corrected code that was breaking new critic tests (fixes #2)
- added _url() method which sets/fetches 'url' param for testing
- added t/03-error test
- changed tests that fail in t/02-fetch to properly skip
- added t/04-filter tests
- added t/05-timeout tests (closes #4; as invalid)
- reduced timeout in t/04-filter, and wrapped in eval (closes #5)
- added tests for _set_error() (closes #6)

1.002 2016-02-07
- Adopted by Steve Bertrand (STEVEB) (2016-02-04)
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ t/01-load.t
t/02-fetch.t
t/03-mech_error.t
t/04-filter.t
t/05-timeout.t
t/06-_set_error.t
t/kwalitee.t
t/pod-coverage.t
t/pod.t
2 changes: 1 addition & 1 deletion lib/WWW/FreeProxyListsCom.pm
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ sub get_list {
);

$mech->get($uri)->is_success
or return $self->_set_error($mech,'net');
or return $self->_set_error($mech, 'net');

$page_type eq 'anonymous'
and $page_type = 'anon';
Expand Down
60 changes: 33 additions & 27 deletions t/04-filter.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,47 @@ use Data::Dumper;
use Test::More;
use WWW::FreeProxyListsCom;

my $p = WWW::FreeProxyListsCom->new;
my $p = WWW::FreeProxyListsCom->new(timeout => 10);

my $ca = $p->get_list(type => 'ca');
eval {
my $ca = $p->get_list(type => 'ca');

my $all = $p->filter;
is (@$ca, @$all, "no filter results in entire list");
my $all = $p->filter;
is (@$ca, @$all, "no filter results in entire list");

my $canada = $p->filter(country => 'Canada');
is (@$canada, @$all, "country filter results in proper count");
my $canada = $p->filter(country => 'Canada');
is (@$canada, @$all, "country filter results in proper count");

my $ip = $ca->[0]->{ip};
my $ip_check = @{ $p->filter(ip => $ip) };
is ($ip_check, 1, "IP filter count is ok");
my $ip = $ca->[0]->{ip};
my $ip_check = @{ $p->filter(ip => $ip) };
is ($ip_check, 1, "IP filter count is ok");

my $port_count;
for my $prox (@$ca){
$port_count++ if $prox->{port} eq '3128';
}
is (@{ $p->filter(port => '3128') }, $port_count, "string port filter ok");
my $port_count;
for my $prox (@$ca) {
$port_count++ if $prox->{port} eq '3128';
}
is (@{ $p->filter(port => '3128') }, $port_count, "string port filter ok");

$port_count = 0;
for my $prox (@$ca){
$port_count++ if $prox->{port} == 3128;
}
is (@{ $p->filter(port => 3128) }, $port_count, "numeric port filter ok");
$port_count = 0;
for my $prox (@$ca) {
$port_count++ if $prox->{port} == 3128;
}
is (@{ $p->filter(port => 3128) }, $port_count, "numeric port filter ok");

my $latency = $p->filter(latency => qr/^\d{3}$/);
ok (scalar @$latency < scalar @$ca, "latency filter has less entries than all");
my $latency = $p->filter(latency => qr/^\d{3}$/);
ok (scalar @$latency < scalar @$ca, "latency filter has less entries than all");

my $last_test = $p->filter(last_test => qr/am/);
ok (scalar @$last_test < scalar @$ca, "last_test filter works");
my $last_test = $p->filter(last_test => qr/am/);
ok (scalar @$last_test < scalar @$ca, "last_test filter works");

my $http = $p->filter(is_https => 'false');
my $https = $p->filter(is_https => 'true');
ok (scalar @$http < scalar @$ca, "is_http filter works for false");
ok (scalar @$https < scalar @$ca, "is_http filter works for true");
my $http = $p->filter(is_https => 'false');
my $https = $p->filter(is_https => 'true');
ok (scalar @$http < scalar @$ca, "is_http filter works for false");
ok (scalar @$https < scalar @$ca, "is_http filter works for true");
};

if ($@){
plan skip_all => "test failure due to timeout";
}

done_testing();
33 changes: 33 additions & 0 deletions t/05-timeout.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/perl
use warnings;
use strict;

use Data::Dumper;
use Test::More;
use WWW::FreeProxyListsCom;

{
eval {
my $p = WWW::FreeProxyListsCom->new(timeout => '0.0000001');
my $elite = $p->get_list();
};
if ($@){
like ($@, qr/Error GETing/, "timeout ok");
}
}
{
my $ca;

eval {
my $p = WWW::FreeProxyListsCom->new(timeout => 10);
$ca = $p->get_list(type => 'ca');
};
if ($@){
like ($@, qr/Error Geting/, "timeout broken, but we've skipped");
}
else {
is (ref $ca->[1], 'HASH', "timeout ok, we got success");
}
}

done_testing();
36 changes: 36 additions & 0 deletions t/06-_set_error.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/perl
use warnings;
use strict;

use Test::More;
use WWW::FreeProxyListsCom;


my $p = WWW::FreeProxyListsCom->new(timeout => 10);

eval {
$p->get_list(type => 'ca');
$p->_set_error($p->{mech}, 'net');

};

if ($@){
like ($@, qr/Error GETing/, "timeout skip");
}
else {
like ($p->error, qr/Network error/, "network error ok");
}

eval {
$p->get_list(type => 'ca');
$p->_set_error("error");
};

if ($@){
like ($@, qr/Error GETing/, "timeout skip");
}
else {
is ($p->error, 'error', "string error ok");
}

done_testing();

0 comments on commit 6019b04

Please sign in to comment.