sub
Dist::Zilla::Plugin::UploadToCPAN::_Uploader::upload_file {
my
(
$self
,
$archive
) =
@_
;
$self
->
log
(
"PAUSE $_ is $self->{$_}"
)
for
qw(user password)
;
$self
->
log
(
"Uploading $archive"
)
if
-f
$archive
;
}
sub
build_tzil {
Builder->from_config(
{
dist_root
=>
'corpus/dist/DZT'
},
{
add_files
=> {
'source/dist.ini'
=> simple_ini(
'GatherDir'
,
@_
),
},
},
);
}
sub
set_responses {
my
(
$zilla
,
$username
,
$pw
) =
@_
;
$zilla
->chrome->set_response_for(
'PAUSE username: '
,
$username
);
$zilla
->chrome->set_response_for(
"PAUSE password for $username: "
,
$pw
);
}
pause_cfg_file
=> File::Spec->devnull);
{
my
$tzil
= build_tzil(
[
UploadToCPAN
=> {
%safety_first
} ],
'FakeRelease'
,
[
'%PAUSE'
=> {
qw(
username user
password password
)
}],
);
$tzil
->release;
my
$msgs
=
$tzil
->log_messages;
ok(
grep
({ /PAUSE user is user/ }
@$msgs
),
"read username"
);
ok(
grep
({ /PAUSE password is password/ }
@$msgs
),
"read password"
);
ok(
grep
({ /Uploading.
*DZT
-Sample/ }
@$msgs
),
"uploaded archive"
);
ok(
grep
({ /fake release happen/i }
@$msgs
),
"releasing continues after upload"
,
);
}
{
my
$tzil
= build_tzil(
[
UploadToCPAN
=> {
%safety_first
} ],
'FakeRelease'
,
);
set_responses(
$tzil
,
qw(user password)
);
$tzil
->release;
my
$msgs
=
$tzil
->log_messages;
ok(
grep
({ /PAUSE user is user/ }
@$msgs
),
"entered username"
);
ok(
grep
({ /PAUSE password is password/ }
@$msgs
),
"entered password"
);
ok(
grep
({ /Uploading.
*DZT
-Sample/ }
@$msgs
),
"uploaded archive manually"
);
ok(
grep
({ /fake release happen/i }
@$msgs
),
"releasing continues after manual upload"
,
);
}
{
my
$tzil
= build_tzil(
'FakeRelease'
,
[
UploadToCPAN
=> {
%safety_first
} ],
);
set_responses(
$tzil
,
''
,
''
);
like( exception {
$tzil
->release },
qr/No username was provided/
,
"release without credentials fails"
);
my
$msgs
=
$tzil
->log_messages;
ok(
grep
({ /No username was provided/}
@$msgs
),
"insist on username"
);
ok(!
grep
({ /Uploading.
*DZT
-Sample/ }
@$msgs
),
"no upload without credentials"
);
ok(
!
grep
({ /fake release happen/i }
@$msgs
),
"no release without credentials"
);
}
{
my
$tzil
= build_tzil(
'FakeRelease'
,
[
UploadToCPAN
=> {
%safety_first
} ],
);
set_responses(
$tzil
,
'user'
,
''
);
like( exception {
$tzil
->release },
qr/No password was provided/
,
"release without password fails"
);
my
$msgs
=
$tzil
->log_messages;
ok(
grep
({ /No password was provided/}
@$msgs
),
"insist on password"
);
ok(!
grep
({ /Uploading.
*DZT
-Sample/ }
@$msgs
),
"no upload without password"
);
ok(
!
grep
({ /fake release happen/i }
@$msgs
),
"no release without password"
);
}
{
my
$tzil
= build_tzil(
'FakeRelease'
,
[
UploadToCPAN
=> {
%safety_first
,
username
=>
'me'
,
password
=>
'ohhai'
,
}
],
);
like( exception {
$tzil
->release },
qr/Couldn't figure out password/
,
"password set in dist.ini is ignored"
);
}