#!perl
local
$ENV
{PERL_CPANM_HOME} = tempdir->stringify();
local
$ENV
{no_proxy} =
"localhost"
;
plan
skip_all
=>
"Need cpanm $PINTO_MINIMUM_CPANM_VERSION or newer"
unless
has_cpanm(
$PINTO_MINIMUM_CPANM_VERSION
);
my
$htpasswd
= make_htpasswd_file(
qw(my_login my_password)
);
my
@auth
= (
qw(--auth backend=Passwd --auth)
,
"path=$htpasswd"
);
my
$t
= Pinto::Server::Tester->new(
pintod_opts
=> \
@auth
)->start_server;
plan
skip_all
=>
"Can't open connection to $t"
unless
$t
->can_connect;
$t
->populate(
'JOHN/DistA-1 = PkgA~1 & PkgB~1; PkgC~1'
);
$t
->populate(
'PAUL/DistB-1 = PkgB~1 & PkgD~2'
);
$t
->populate(
'MARK/DistC-1 = PkgC~1'
);
$t
->populate(
'MARK/DistC-2 = PkgC~2; PkgD~2'
);
subtest
'Remote install succeeds with valid credentials'
=>
sub
{
my
%creds
= (
username
=>
'my_login'
,
password
=>
'my_password'
);
my
$remote
= Pinto::Remote->new(
root
=>
$t
->server_url,
%creds
);
my
$sandbox
= File::Temp->newdir;
my
$p5_dir
= dir(
$sandbox
,
qw(lib perl5)
);
my
%cpanm_opts
= (
cpanm_options
=> {
q =>
undef
,
L
=>
$sandbox
->dirname } );
my
$result
;
capture_stderr {
$result
=
$remote
->run(
Install
=> (
targets
=> [
'PkgA'
],
%cpanm_opts
) );
};
is
$result
->was_successful, 1;
file_exists_ok(
$p5_dir
->file(
'PkgA.pm'
) );
file_exists_ok(
$p5_dir
->file(
'PkgB.pm'
) );
file_exists_ok(
$p5_dir
->file(
'PkgC.pm'
) );
file_exists_ok(
$p5_dir
->file(
'PkgD.pm'
) );
};
subtest
'Remote install fails with invalid credentials'
=>
sub
{
my
%creds
= (
username
=>
'my_login'
,
password
=>
'bogus'
);
my
$remote
= Pinto::Remote->new(
root
=>
$t
->server_url,
%creds
);
my
$sandbox
= File::Temp->newdir;
my
$p5_dir
= dir(
$sandbox
,
qw(lib perl5)
);
my
%cpanm_opts
= (
cpanm_options
=> {
q =>
undef
,
L
=>
$sandbox
->dirname } );
my
$result
;
capture_stderr {
$result
=
$remote
->run(
Install
=> (
targets
=> [
'PkgA'
],
%cpanm_opts
) );
};
is
$result
->was_successful, 0;
like
$result
,
qr/Installation failed/
;
};
subtest
'Remote install fails with no credentials'
=>
sub
{
diag
"You will see an error message here. Do not be alarmed."
;
my
%creds
= ();
my
$remote
= Pinto::Remote->new(
root
=>
$t
->server_url,
%creds
);
my
$sandbox
= File::Temp->newdir;
my
$p5_dir
= dir(
$sandbox
,
qw(lib perl5)
);
my
%cpanm_opts
= (
cpanm_options
=> {
q =>
undef
,
L
=>
$sandbox
->dirname } );
my
$result
;
capture_stderr {
$result
=
$remote
->run(
Install
=> (
targets
=> [
'PkgA'
],
%cpanm_opts
) );
};
is
$result
->was_successful, 0;
like
$result
,
qr/Installation failed/
;
};
done_testing;