File: 10-core.t

package info (click to toggle)
librt-client-rest-perl 1%3A0.56-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 568 kB
  • sloc: perl: 4,205; makefile: 9
file content (81 lines) | stat: -rw-r--r-- 1,754 bytes parent folder | download | duplicates (3)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!perl
# vim:ft=perl:

use strict;
use warnings;

use Test::More tests => 28;
use Test::Exception;

use constant METHODS => (
    'new', 'server', 'show', 'edit', 'login',
    'create', 'comment', 'correspond', 'merge_tickets', 'link_tickets',
    'unlink_tickets', 'search', 'get_attachment_ids', 'get_attachment',
    'get_transaction_ids', 'get_transaction', 'take', 'untake', 'steal',
    'timeout', 'basic_auth_cb',
);

use RT::Client::REST;

my $rt;

lives_ok {
    $rt = RT::Client::REST->new;
} 'RT::Client::REST instance created';

for my $method (METHODS) {
    can_ok($rt, $method);
}

throws_ok {
    $rt->login;
} 'RT::Client::REST::InvalidParameterValueException',
    "requires 'username' and 'password' parameters";

throws_ok {
    $rt->basic_auth_cb(1);
} 'RT::Client::REST::InvalidParameterValueException';

throws_ok {
    $rt->basic_auth_cb({});
} 'RT::Client::REST::InvalidParameterValueException';

lives_ok {
    $rt->basic_auth_cb(sub {});
};

{
    package BadLogger;
    sub new { bless \my $logger }
    for my $method (qw(debug me elmo)) {
        no strict 'refs';
        *$method = sub {
            my $self = shift;
            Test::More::diag("$method: @_\n");
        };
    }
}

throws_ok {
    RT::Client::REST->new(logger => BadLogger->new);
} 'RT::Client::REST::InvalidParameterValueException',
    'bad logger results in exception being thrown';

{
    package GoodLogger;
    sub new { bless \my $logger }
    for my $method (qw(debug info warn error)) {
        no strict 'refs';
        *$method = sub {
            my $self = shift;
            Test::More::diag("$method: @_\n");
        };
    }
}

lives_ok {
    RT::Client::REST->new(logger => GoodLogger->new);
} 'good logger, no exception thrown';

1;