App-Sqitch
view release on metacpan or search on metacpan
is_deeply +MockOutput->get_info_literal, [[
' - oops ..', '.', ' '
]], 'Output should reflect revert start';
is_deeply +MockOutput->get_info, [[__ 'not ok']],
'Output should acknowldge failure';
is_deeply +MockOutput->get_vent, [], 'Should have vented nothing';
$record_work = 0;
##############################################################################
# Test earliest_change() and latest_change().
chdir 't';
my $plan_file = file qw(sql sqitch.plan);
my $sqitch_old = $sqitch; # Hang on to this because $change does not retain it.
$config->update(
'core.top_dir' => 'sql',
'core.plan_file' => $plan_file->stringify,
);
$sqitch = App::Sqitch->new(config => $config);
$target = App::Sqitch::Target->new( sqitch => $sqitch );
$change = App::Sqitch::Plan::Change->new( name => 'lolz', plan => $target->plan );
ok $engine = App::Sqitch::Engine::whu->new( sqitch => $sqitch, target => $target ),
'Engine with sqitch with plan file';
$plan = $target->plan;
my @changes = $plan->changes;
$latest_change_id = $changes[0]->id;
is $engine->latest_change, $changes[0], 'Should get proper change from latest_change()';
is_deeply $engine->seen, [[ latest_change_id => undef ]],
'Latest change ID should have been called with no arg';
$latest_change_id = $changes[2]->id;
is $engine->latest_change(2), $changes[2],
'Should again get proper change from latest_change()';
is_deeply $engine->seen, [[ latest_change_id => 2 ]],
'Latest change ID should have been called with offset arg';
$latest_change_id = undef;
$earliest_change_id = $changes[0]->id;
is $engine->earliest_change, $changes[0], 'Should get proper change from earliest_change()';
is_deeply $engine->seen, [[ earliest_change_id => undef ]],
'Earliest change ID should have been called with no arg';
$earliest_change_id = $changes[2]->id;
is $engine->earliest_change(4), $changes[2],
'Should again get proper change from earliest_change()';
is_deeply $engine->seen, [[ earliest_change_id => 4 ]],
'Earliest change ID should have been called with offset arg';
$earliest_change_id = undef;
##############################################################################
# Test _sync_plan()
can_ok $CLASS, '_sync_plan';
$engine->seen;
is $plan->position, -1, 'Plan should start at position -1';
is $engine->start_at, undef, 'start_at should be undef';
ok $engine->_sync_plan, 'Sync the plan';
is $plan->position, -1, 'Plan should still be at position -1';
is $engine->start_at, undef, 'start_at should still be undef';
$plan->position(4);
is_deeply $engine->seen, [['current_state', undef]],
'Should not have updated IDs or hashes';
ok $engine->_sync_plan, 'Sync the plan again';
is $plan->position, -1, 'Plan should again be at position -1';
is $engine->start_at, undef, 'start_at should again be undef';
is_deeply $engine->seen, [['current_state', undef]],
'Still should not have updated IDs or hashes';
# Have latest_item return a tag.
$latest_change_id = $changes[2]->id;
ok $engine->_sync_plan, 'Sync the plan to a tag';
is $plan->position, 2, 'Plan should now be at position 2';
is $engine->start_at, 'widgets@beta', 'start_at should now be widgets@beta';
is_deeply $engine->seen, [
['current_state', undef],
['log_new_tags' => $plan->change_at(2)],
], 'Should have updated IDs';
# Have current_state return a script hash.
$script_hash = '550aeeab2ae39cba45840888b12a70820a2d6f83';
ok $engine->_sync_plan, 'Sync the plan with a random script hash';
is $plan->position, 2, 'Plan should now be at position 1';
is $engine->start_at, 'widgets@beta', 'start_at should now be widgets@beta';
is_deeply $engine->seen, [
['current_state', undef],
['log_new_tags' => $plan->change_at(2)],
], 'Should have updated IDs but not hashes';
# Have current_state return the last deployed ID as script_hash.
$script_hash = $latest_change_id;
ok $engine->_sync_plan, 'Sync the plan with a random script hash';
is $plan->position, 2, 'Plan should now be at position 1';
is $engine->start_at, 'widgets@beta', 'start_at should now be widgets@beta';
is_deeply $engine->seen, [
['current_state', undef],
['_update_script_hashes'],
['log_new_tags' => $plan->change_at(2)],
], 'Should have updated IDs and hashes';
# Return no change ID, now.
$script_hash = $latest_change_id = $changes[1]->id;
ok $engine->_sync_plan, 'Sync the plan';
is $plan->position, 1, 'Plan should be at position 1';
is $engine->start_at, 'users@alpha', 'start_at should be users@alpha';
is_deeply $engine->seen, [
['current_state', undef],
['_update_script_hashes'],
['log_new_tags' => $plan->change_at(1)],
], 'Should have updated hashes but not IDs';
# Have current_state return no script hash.
my $mock_whu = Test::MockModule->new('App::Sqitch::Engine::whu');
my $state = {change_id => $latest_change_id};
$mock_whu->mock(current_state => $state);
ok $engine->_sync_plan, 'Sync the plan with no script hash';
$mock_whu->unmock('current_state');
is $plan->position, 1, 'Plan should now be at position 1';
is $engine->start_at, 'users@alpha', 'start_at should still be users@alpha';
is_deeply $engine->seen, [
'upgrade_registry',
['_update_script_hashes'],
['log_new_tags' => $plan->change_at(1)],
], 'Should have ugpraded the registry';
is $state->{script_hash}, $latest_change_id,
'The script hash should have been set to the change ID';
# Have _no_registry return true.
$mock_engine->mock(_no_registry => 1);
ok $engine->_sync_plan, 'Sync the plan with no registry';
is $plan->position, -1, 'Plan should start at position -1';
$mock_engine->unmock('_no_registry');
##############################################################################
# Test deploy.
can_ok $CLASS, 'deploy';
$script_hash = undef;
$latest_change_id = undef;
$plan->reset;
$engine->seen;
@changes = $plan->changes;
# Mock the deploy methods to log which were called.
my $deploy_meth;
for my $meth (qw(_deploy_all _deploy_by_tag _deploy_by_change)) {
my $orig = $CLASS->can($meth);
$mock_engine->mock($meth => sub {
$deploy_meth = $meth;
$orig->(@_);
});
}
# Mock locking and dependency checking to add their calls to the seen stuff.
$mock_engine->mock( check_deploy_dependencies => sub {
shift->mock_check_deploy(@_);
});
$mock_engine->mock( check_revert_dependencies => sub {
shift->mock_check_revert(@_);
});
$mock_engine->mock(lock_destination => sub {
shift->mock_lock(@_);
});
ok $engine->deploy('@alpha'), 'Deploy to @alpha';
is $plan->position, 1, 'Plan should be at position 1';
is_deeply $engine->seen, [
[lock_destination => []],
[current_state => undef],
'initialized',
'initialize',
( run in 3.368 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )