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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
# -*- cperl -*-
use strict;
use warnings;
use lib 't';
use Test::More;
require "test-functions.pl";
if (not can_svn()) {
plan skip_all => 'Cannot find or use svn commands.';
}
elsif (not eval {require JIRA::REST}) {
plan skip_all => 'Need JIRA::REST';
}
else {
plan tests => 16;
}
my $t = reset_repo();
set_hook(<<'EOS');
use SVN::Hooks::CheckJira;
EOS
my $wc = catfile($t, 'wc');
my $file = catfile($wc, 'file');
work_ok('prepare', <<"EOS");
echo line >$file
svn add -q --no-auto-props $file
svn ci -m"prepare" --force-log $wc
EOS
sub work {
my ($msg) = @_;
<<"EOS";
echo line >>$file
svn ci -m"$msg" --force-log $wc
EOS
}
set_conf(<<'EOS');
CHECK_JIRA_CONFIG();
EOS
work_nok('config sans args', 'CHECK_JIRA_CONFIG: requires three, four, or five arguments', work(''));
set_conf(<<'EOS');
CHECK_JIRA_CONFIG('http://jira.atlassian.com/', 'user', 'pass', 'asdf');
EOS
work_nok('invalid fourth arg', 'CHECK_JIRA_CONFIG: fourth argument must be a Regexp', work(''));
set_conf(<<'EOS');
CHECK_JIRA();
EOS
work_nok('accept invalid first arg', 'CHECK_JIRA: first arg must be a qr/Regexp/ or the string \'default\'.', work(''));
set_conf(<<'EOS');
CHECK_JIRA(default => 'invalid');
EOS
work_nok('accept invalid second arg', 'CHECK_JIRA: second argument must be a HASH-ref.', work(''));
set_conf(<<'EOS');
CHECK_JIRA(default => {invalid => 1});
EOS
work_nok('invalid option', 'CHECK_JIRA: unknown option \'invalid\'.', work(''));
set_conf(<<'EOS');
CHECK_JIRA(default => {projects => 1});
EOS
work_nok('invalid projects arg', 'CHECK_JIRA: projects\'s value must be a string matching', work(''));
set_conf(<<'EOS');
CHECK_JIRA(default => {require => undef});
EOS
work_nok('undefined arg', 'CHECK_JIRA: undefined require\'s value', work(''));
set_conf(<<'EOS');
CHECK_JIRA(default => {check_one => 1});
EOS
work_nok('invalid code arg', 'CHECK_JIRA: check_one\'s value must be a CODE-ref', work(''));
set_conf(<<'EOS');
CHECK_JIRA(qr/./ => {});
EOS
work_nok('not configured', 'CHECK_JIRA: plugin not configured. Please, use the CHECK_JIRA_CONFIG directive', work(''));
set_conf(<<'EOS');
CHECK_JIRA_DISABLE;
CHECK_JIRA(qr/./);
EOS
work_ok('disabled', work('no issue'));
################################################
# From now on the checks need a JIRA connection.
SKIP: {
skip 'online checks are disabled', 5 unless -e 't/online.enabled';
set_conf(<<'EOS');
CHECK_JIRA_CONFIG('http://no.way.to.get.there', 'user', 'pass');
CHECK_JIRA(qr/./);
EOS
work_nok('no server', 'Bad hostname', work('[TST-1] no server'));
my $config = <<'EOS';
CHECK_JIRA_CONFIG('https://jira.atlassian.com/', 'gustavo+jiraclient@gnustavo.com', 'W3PvT&9q0d^HLG0n', qr/^\[([^\]]+)\]/);
EOS
set_conf($config . <<'EOS');
CHECK_JIRA(qr/asdf/);
EOS
work_ok('no need to accept', work('ok'));
set_conf($config . <<'EOS');
sub fix_for {
my ($version) = @_;
return sub {
my ($jira, $issue, $svnlook) = @_;
die "CHECK_JIRA: missing SVN::Look object" unless ref $svnlook eq 'SVN::Look';
foreach my $fv (@{$issue->{fields}{fixVersion}}) {
return if $version eq $fv->{name};
}
die "CHECK_JIRA: issue $issue->{key} not scheduled for version $version.\n";
}
}
CHECK_JIRA(qr/./, {check_one => fix_for('A version')});
EOS
work_nok('no keys', 'CHECK_JIRA: you must cite at least one JIRA issue key in the commit message', work('no keys'));
work_nok('not valid', 'CHECK_JIRA: issue ZYX-1 is not valid:', work('[ZYX-1]'));
work_nok('check_one', 'CHECK_JIRA: issue TST-55263 not scheduled for version future-version.', work('[TST-55263]'));
}
|