Skip to content

Commit

Permalink
Increase command, engine coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jul 25, 2022
1 parent 1579495 commit 8338bba
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/App/Sqitch/Command.pm
Expand Up @@ -240,7 +240,7 @@ sub parse_args {
$seen{$target->name}++;
}

# Iterate over the argsx to look for changes, engines, plans, or targets.
# Iterate over the args to look for changes, engines, plans, or targets.
my %engines = map { $_ => 1 } ENGINES;
for my $arg (@{ $p{args} }) {
if ( !$p{no_changes} && $target && -e $target->plan_file && $target->plan->contains($arg) ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/App/Sqitch/Engine.pm
Expand Up @@ -896,7 +896,7 @@ sub _deploy_all {
push @run => $change;
}
} catch {
if (my $ident = eval { $_->ident }) {
if (my $ident = try { $_->ident }) {
$self->sqitch->vent($_->message) unless $ident eq 'private'
} else {
$self->sqitch->vent($_);
Expand Down
6 changes: 5 additions & 1 deletion t/command.t
Expand Up @@ -4,7 +4,7 @@ use strict;
use warnings;
use 5.010;
use utf8;
use Test::More tests => 195;
use Test::More tests => 198;
#use Test::More 'no_plan';
use Test::NoWarnings;
use List::Util qw(first);
Expand Down Expand Up @@ -407,6 +407,10 @@ ARGS: {
'Single unknown arg raise an error';
is $@->ident, 'whu', 'Unknown error ident should be "whu"';
is $@->message, $msg->('foo'), 'Unknown error message should be correct';
throws_ok { $parsem->( args => ['Changes'] ) } 'App::Sqitch::X',
'Single invavlid fiile arg raise an error';
is $@->ident, 'whu', 'Unknown error ident should be "whu"';
is $@->message, $msg->('Changes'), 'Unknown file error message should be correct';
is_deeply $parsem->( args => ['hey'] ), [['devdb'], ['hey']],
'Single change should be recognized as change';
is_deeply $parsem->( args => ['devdb'] ), [['devdb'], []],
Expand Down
51 changes: 50 additions & 1 deletion t/engine.t
Expand Up @@ -4,7 +4,7 @@ use strict;
use warnings;
use 5.010;
use utf8;
use Test::More tests => 721;
use Test::More tests => 731;
# use Test::More 'no_plan';
use App::Sqitch;
use App::Sqitch::Plan;
Expand Down Expand Up @@ -1679,6 +1679,47 @@ is_deeply +MockOutput->get_vent, [
['ROFL'],
[__x 'Reverting to {change}', change => '@alpha'],
], 'Should notifiy user of error and rollback to @alpha';

# Die with a string rather than an exception.
$plan->position(2);
$engine->start_at('@alpha');
$mock_whu->mock(run_file => sub { die 'Oops' if $_[1]->basename eq 'dr_evil.sql' });
throws_ok { $engine->_deploy_all($plan, $plan->count -1 ) } 'App::Sqitch::X',
'Die in _deploy_all on the last change';
is $@->message, __('Deploy failed'), 'Should once again get final deploy failure message';
is_deeply $engine->seen, [
[log_deploy_change => $changes[3]],
[log_deploy_change => $changes[4]],
[log_deploy_change => $changes[5]],
[log_fail_change => $changes[6]],
[log_revert_change => $changes[5]],
[log_revert_change => $changes[4]],
[log_revert_change => $changes[3]],
], 'Should have deployed to dr_evil and revered down to @alpha';

is_deeply +MockOutput->get_info_literal, [
[' + lolz ..', '.........', ' '],
[' + tacos ..', '........', ' '],
[' + curry ..', '........', ' '],
[' + dr_evil ..', '......', ' '],
[' - curry ..', '........', ' '],
[' - tacos ..', '........', ' '],
[' - lolz ..', '.........', ' '],
], 'Should see changes revert back to @alpha';
is_deeply +MockOutput->get_info, [
[__ 'ok' ],
[__ 'ok' ],
[__ 'ok' ],
[__ 'not ok' ],
[__ 'ok' ],
[__ 'ok' ],
[__ 'ok' ],
], 'Output should reflect deploy successes and failures';
$vented = MockOutput->get_vent;
is @{ $vented }, 2, 'Should have two vented items';
like $vented->[0][0], qr/Oops/, 'First vented should be the error';
is_deeply $vented->[1], [__x 'Reverting to {change}', change => '@alpha'],
'Should notifiy user of rollback to @alpha';
$mock_whu->unmock_all;

##############################################################################
Expand Down Expand Up @@ -2512,6 +2553,14 @@ CHECK_REVERT_DEPEND: {
plan => $plan,
);

# First test with no dependencies.
@requiring = [];
ok $engine->check_revert_dependencies($change),
'Should get no error with no dependencies';
is_deeply $engine->seen, [
[changes_requiring_change => $change ],
], 'It should have check for requiring changes';

# Have revert change fail with requiring changes.
my $req = {
change_id => '23234234',
Expand Down

0 comments on commit 8338bba

Please sign in to comment.