Incorrect search filter: invalid characters - *.p[ml]
API-MikroTik

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

20
21
22
23
24
25
26
27
28
29
30
31
            license =>
                ['http://www.opensource.org/licenses/artistic-license-2.0'],
            repository => {
                type => 'git',
                url  => 'https://github.com/anparker/api-mikrotik.git',
                web  => 'https://github.com/anparker/api-mikrotik',
            },
        },
    },
    PREREQ_PM => {'Mojolicious' => '7.00'},
    test      => {TESTS         => 't/*.t'},
);

t/lib/API/MikroTik/Mockup.pm  view on Meta::CPAN

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
}
 
sub cmd_login {
    my (undef, $attr) = @_;
    my $tag = $attr->{'.tag'};
 
    return _done($tag, {ret => '098f6bcd4621d373cade4e832627b4f6'})
        unless $attr->{name};
 
    return _done($tag)
        if $attr->{name} eq 'test'
        && $attr->{response} eq '00119ce7e093e33497053e73f37a5d3e15';
 
    return ['!fatal', {message => 'cannot log in'}, undef, $tag];
}
 
sub cmd_nocmd {
    return ();
}
 
sub cmd_resp {

t/mikrotik-online.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env perl
 
use strict;
 
use lib './';
 
 
plan skip_all =>
    'On-line tests. Set API_MIKROTIK_ONLINE to "host:user:pass:tls" to run.'
    unless $ENV{API_MIKROTIK_ONLINE};
 
 
my ($h, $u, $p, $tls) = split ':', ($ENV{API_MIKROTIK_ONLINE} || '');
my $a = API::MikroTik->new(
    user     => ($u   // 'admin'),
    password => ($p   // ''),

t/mikrotik-online.t  view on Meta::CPAN

25
26
27
28
29
30
31
32
33
34
35
my $res;
$res = $a->cmd(
    '/interface/print',
    {'.proplist' => '.id,name,type,running'},
);
ok !$a->error, 'no error';
my @keys = sort keys %{$res->[0]};
is_deeply [@keys], [qw(.id name running type)], 'right result';
 
done_testing();

t/mikrotik.t  view on Meta::CPAN

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use Mojo::Util qw(steady_time);
 
# blocking
my $loop   = Mojo::IOLoop->new();
my $mockup = API::MikroTik::Mockup->new()->ioloop($loop);
my $port   = $loop->acceptor($mockup->server)->port;
 
my $api = API::MikroTik->new(
    user     => 'test',
    password => 'tset',
    host     => '127.0.0.1',
    port     => $port,
    tls      => 1,
    ioloop   => $loop,
);
 
# check connection
$api->tls(1);
my $res = $api->cmd('/resp');

t/mikrotik.t  view on Meta::CPAN

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
$ctime = steady_time();
$res   = $api->cmd('/nocmd');
ok((steady_time() - $ctime) < 0.6, 'timeout ok');
$api->timeout(1);
 
# close connection prematurely, next command should succeed
$res = $api->cmd('/close/premature');
ok !$res, 'no result';
is $api->error, 'closed prematurely', 'right error';
 
# also check previous test case on errors
$res = $api->cmd('/resp');
isa_ok $res, 'Mojo::Collection', 'right result type';
is_deeply $res, _gen_result(), 'right result';
 
$res = $api->cmd('/resp', {'.proplist' => 'prop0,prop2'});
is_deeply $res, _gen_result('prop0,prop2'), 'right result';
 
$res = $api->cmd('/resp', {'.proplist' => 'prop0,prop2', count => 3});
is_deeply $res, _gen_result('prop0,prop2', 3), 'right result';

t/mikrotik.t  view on Meta::CPAN

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
$api->cmd('/err' => sub { $err2 = $_[1] . '2' });
 
Mojo::IOLoop->timer(1.3 => sub { Mojo::IOLoop->stop() });
Mojo::IOLoop->start();
 
is_deeply $res, {key => 'nnn'}, 'right result';
is $err'interrupted',   'right error';
is $err1, 'random error1', 'right error';
is $err2, 'random error2', 'right error';
 
done_testing();
 
sub _gen_result {
    my $attr = API::MikroTik::Mockup::_gen_attr(@_);
    return [$attr, $attr];
}

t/pod.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
use Mojo::Base -strict;
 
 
plan skip_all => 'set TEST_POD to enable this test (developer only!)'
  unless $ENV{TEST_POD};
plan skip_all => 'Test::Pod 1.14+ required for this test!'
  unless eval 'use Test::Pod 1.14; 1';
 
all_pod_files_ok();

t/pod_coverage.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
use Mojo::Base -strict;
 
 
plan skip_all => 'set TEST_POD to enable this test (developer only!)'
  unless $ENV{TEST_POD};
plan skip_all => 'Test::Pod::Coverage 1.04+ required for this test!'
  unless eval 'use Test::Pod::Coverage 1.04; 1';
 
# DEPRECATED!
all_pod_coverage_ok({also_private => ['data', 'remaining']});

t/promises.t  view on Meta::CPAN

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
use FindBin;
use lib './';
use lib "$FindBin::Bin/lib";
 
 
plan skip_all => 'Mojolicious v7.54+ required for this test.'
    unless API::MikroTik->PROMISES;
 
my $mockup = API::MikroTik::Mockup->new();
my $port   = Mojo::IOLoop->acceptor($mockup->server)->port;
my $api    = API::MikroTik->new(
    user     => 'test',
    password => 'tset',
    host     => '127.0.0.1',
    port     => $port,
    tls      => 1,
);
 
my $p = $api->cmd_p('/resp');
isa_ok $p, 'Mojo::Promise', 'right result type';
 
# connection errors

t/promises.t  view on Meta::CPAN

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
is $err, 'random error', 'right error';
is_deeply $res, [{message => 'random error', category => 0}],
    'right error attributes';
 
# request
$api->cmd_p('/resp')->then(sub { $res = $_[0] })
    ->finally(sub { Mojo::IOLoop->stop() });
Mojo::IOLoop->start();
is_deeply $res, _gen_result(), 'right result';
 
done_testing();
 
sub _gen_result {
    my $attr = API::MikroTik::Mockup::_gen_attr(@_);
    return [$attr, $attr];
}

t/query.t  view on Meta::CPAN

80
81
82
83
84
85
86
87
88
89
90
$r = build_query([a => [{'=', []}, 2, {}]]);
is_deeply $r, ['?a=2'], 'ignore empty structs';
 
my $err;
$SIG{__WARN__} = sub { $err = $_[0] };
$r = build_query([a => undef, b => [1, undef, 2], c => {'=', undef}]);
ok !$err, 'no warning';
is_deeply $r, ['?a=', '?b=1', '?b=', '?b=2', '?#||', '?c=', '?#||'],
    'right result';
 
done_testing();

t/response.t  view on Meta::CPAN

41
42
43
44
45
46
47
48
49
50
51
$w = $r->parse(\$parts[1]);
is_deeply $w, [], 'right result';
ok $r->sentence->is_incomplete, 'incomplete is set';
$w = $r->parse(\$parts[2]);
is_deeply $w, [($attr) x 2], 'right result';
ok $r->sentence->is_incomplete, 'incomplete is set';
$w = $r->parse(\$parts[3]);
is_deeply $w, [$attr], 'right result';
ok !$r->sentence->is_incomplete, 'incomplete is not set';
 
done_testing();

t/sentence.t  view on Meta::CPAN

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    .= encode_sentence('/cmd/2', {c => 'foo', d => 'bar'}, {e => 'baz'}, 11);
my $words = $s->fetch(\$packed);
is shift @$words, '/cmd/1', 'right command';
is_deeply [sort @$words], ['=a=1', '=b=2'], 'right attributes';
$words = $s->fetch(\$packed);
is shift @$words, '/cmd/2', 'right command';
is_deeply [sort @$words], ['.tag=11', '=c=foo', '=d=bar', '?e=baz'],
    'right attributes';
 
# buffer ends in the middle of a word
$packed = encode_sentence('/one/two/three', {test => 1, another => 2});
substr $packed, 20, 20, '';
$words = $s->fetch(\$packed);
is_deeply $words, ['/one/two/three'], 'right results';
ok $s->is_incomplete, 'incomplete is set';
 
# reset
$s->reset;
ok !$s->is_incomplete, 'incomplete is not longer set';
 
# buffer ends at the end of the word, before an empty closing word

t/sentence.t  view on Meta::CPAN

56
57
58
59
60
61
62
63
64
65
66
is_deeply $words, ['/one/two', '=three=four'], 'right results';
ok $s->is_incomplete, 'incomplete is set';
 
my $err;
$SIG{__WARN__} = sub { $err = $_[0] };
$packed = encode_sentence('/cmd', {argv => undef});
ok !$err, 'no warning';
$words = $s->reset->fetch(\$packed);
is_deeply $words, ['/cmd', '=argv='], 'right results';
 
done_testing();



( run in 0.294 second using v1.01-cache-2.11-cpan-8d75d55dd25 )