File: _get.t

package info (click to toggle)
libmetacpan-client-perl 2.033000-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 552 kB
  • sloc: perl: 2,564; makefile: 6
file content (66 lines) | stat: -rw-r--r-- 1,400 bytes parent folder | download | duplicates (4)
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
#!perl

use strict;
use warnings;
use Test::More tests => 13;
use Test::Fatal;

use lib '.';
use t::lib::Functions;

{
    no warnings qw<redefine once>;

    *MetaCPAN::Client::Author::new_from_request = sub {
        my ( $self, $res ) = @_;
        ::isa_ok( $self, 'MetaCPAN::Client::Author' );
        ::is_deeply( $res, { hello => 'world' }, 'Correct response' );

        return 'ok';
    };

    my $count = 0;
    *MetaCPAN::Client::fetch = sub {
        my ( $self, $path ) = @_;
        ::isa_ok( $self, 'MetaCPAN::Client' );
        ::is( $path, 'author/myarg', 'Correct path' );

        $count++ == 0
            and return;

        return { hello => 'world' };
    };
}

my $mc = mcpan();
can_ok( $mc, '_get' );

like(
    exception { $mc->_get() },
    qr/^_get takes type and search string as parameters/,
    'Failed with no params',
);

like(
    exception { $mc->_get('wah') },
    qr/^_get takes type and search string as parameters/,
    'Failed with one param',
);

like(
    exception { $mc->_get('wah', 'wah', 'wah') },
    qr/^_get takes type and search string as parameters/,
    'Failed with more than two params',
);

# call fetch and fail
like(
    exception { $mc->_get( 'author', 'myarg' ) },
    qr/^Failed to fetch Author \(myarg\)/,
    'Correct failure',
);

# call fetch and succeed
my $res = $mc->_get( 'author', 'myarg' );
is( $res, 'ok', 'Correct result' );