-
-
Notifications
You must be signed in to change notification settings - Fork 340
Expand file tree
/
Copy pathstatus.t
More file actions
50 lines (36 loc) · 1.25 KB
/
Copy pathstatus.t
File metadata and controls
50 lines (36 loc) · 1.25 KB
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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::MockModule;
use lib './lib';
BEGIN {
use_ok('Nipe::Component::Utils::Status');
}
my $http_mock = Test::MockModule -> new('HTTP::Tiny');
subtest 'reports tor when IsTor is true' => sub {
plan tests => 2;
$http_mock -> mock('get', sub {
return { status => 200, content => '{"IsTor":true,"IP":"185.220.101.1"}' };
});
my $output = Nipe::Component::Utils::Status -> new();
ok(index($output, 'Status: true') >= 0, 'status is true');
ok(index($output, '185.220.101.1') >= 0, 'ip is shown');
};
subtest 'reports not tor when IsTor is false' => sub {
plan tests => 1;
$http_mock -> mock('get', sub {
return { status => 200, content => '{"IsTor":false,"IP":"8.8.8.8"}' };
});
my $output = Nipe::Component::Utils::Status -> new();
ok(index($output, 'Status: false') >= 0, 'status is false');
};
subtest 'reports an error when the request fails' => sub {
plan tests => 1;
$http_mock -> mock('get', sub {
return { status => 599, content => q{} };
});
my $output = Nipe::Component::Utils::Status -> new();
ok(index($output, 'not possible to establish a connection') >= 0, 'error branch');
};
done_testing();