File: unit.t

package info (click to toggle)
libgitlab-api-v4-perl 0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,500 kB
  • sloc: perl: 5,960; sh: 838; python: 63; makefile: 12
file content (56 lines) | stat: -rwxr-xr-x 1,403 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
#!/usr/bin/env perl
use strictures 2;

use Test2::V0;

use GitLab::API::v4::Mock;

subtest users => sub{
    my @users = ();
    my $next_id = 1;

    my $api = GitLab::API::v4::Mock->new();

    my @expected;
    is( $api->users(), \@expected, 'users is empty' );

    $api->create_user({});
    push @expected, {id=>1};
    is( $api->users(), \@expected, 'one user created' );

    $api->create_user({});
    push @expected, {id=>2};
    $api->create_user({});
    push @expected, {id=>3};
    is( $api->users(), \@expected, 'two more users created' );

    $api->edit_user( 3, {name=>'foo'});
    $expected[2]->{name} = 'foo';
    is( $api->users(), \@expected, 'user was updated' );

    $api->delete_user( 2 );
    splice @expected, 1, 1;
    is( $api->users(), \@expected, 'user was deleted' );
};

subtest reqres => sub{
    my $api = GitLab::API::v4::Mock->new();

    is( $api->rest_client->http_tiny_request(), undef, 'no request' );
    is( $api->rest_client->http_tiny_response(), undef, 'no response' );

    $api->users();

    is(
        $api->rest_client->http_tiny_request(),
        [ 'GET', 'https://example.com/api/v4/users', {headers=>{}} ],
        'recorded request arrayref looks great',
    );
    is(
        $api->rest_client->http_tiny_response(),
        { success=>1, status=>200, content=>'[]' },
        'recorded response hashref looks great',
    );
};

done_testing;