Artifactory-Client

 view release on metacpan or  search on metacpan

t/01_unit.t  view on Meta::CPAN


# it became silly to do this in every subtest
no strict 'refs';
no warnings 'redefine';

my $artifactory = 'http://example.com';
my $port        = 7777;
my $repository  = 'repository';

my %mock_responses = (
    http_404 => bless( { '_rc' => 404, '_headers' => bless( {}, 'HTTP::Headers' ) }, 'HTTP::Response' ),
    http_200 => bless( { '_rc' => 200,   '_content' => '{ "foo" : "bar" }' }, 'HTTP::Response' ),
    http_201 => bless( { '_rc' => 201 }, 'HTTP::Response' ),
    http_202 => bless( { '_rc' => 202 }, 'HTTP::Response' ),
    http_204 => bless( { '_rc' => 204 }, 'HTTP::Response' ),
);

subtest 'check if ua is LWP::UserAgent', sub {
    my $client = setup();
    isa_ok( $client->ua, 'LWP::UserAgent' );

t/01_unit.t  view on Meta::CPAN

};

subtest 'set_item_properties on non-existing artifact', sub {
    my $client     = setup();
    my $properties = {
        one => [1],
        two => [2],
    };

    local *{'LWP::UserAgent::put'} = sub {
        return $mock_responses{http_404};
    };
    my $resp = $client->set_item_properties( path => '/unique_path', properties => $properties );
    is( $resp->code, 404, 'got 404 for attempting to set props on non-existent artifact' );
};

subtest 'deploy artifact by checksum', sub {
    my $client = setup();
    my $path   = '/unique_path';
    my $sha1   = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';    # sha-1 of 0 byte file

    local *{'LWP::UserAgent::request'} = sub {
        return bless(
            {

t/01_unit.t  view on Meta::CPAN

            },
            'HTTP::Response'
        );
    };

    my $resp = $client->deploy_artifact_by_checksum( path => $path, sha1 => $sha1 );
    is( $resp->request()->header('x-checksum-deploy'), 'true', 'x-checksum-deploy set' );
    is( $resp->request()->header('x-checksum-sha1'),   $sha1,  'x-checksum-sha1 set' );

    local *{'LWP::UserAgent::request'} = sub {
        return $mock_responses{http_404};
    };

    my $resp2 = $client->deploy_artifact_by_checksum( path => $path );    # no sha-1 on purpose
    is( $resp2->code, 404, 'got 404 since no sha1 was supplied' );
};

subtest 'item properties', sub {
    my $client     = setup();
    my $properties = {
        this => [ 'here', 'there' ],
        that => ['one'],
    };

    local *{'LWP::UserAgent::get'} = sub {



( run in 1.686 second using v1.01-cache-2.11-cpan-39bf76dae61 )