Skip to content

Commit

Permalink
Add unit tests for check and assert shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Orlov committed Aug 6, 2018
1 parent f4ab0e6 commit 59789e7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ on 'test' => sub {
requires 'Test::Pod';
requires 'Test::Simple';
requires 'Test::Warnings';
requires 'Test::Exception';
requires 'Socket::MsgHdr';
};

Expand Down
25 changes: 25 additions & 0 deletions t/03-testapi.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use Test::Fatal;
use Test::Mock::Time;
use Test::Warnings;
use File::Temp;
use Test::Exception;

BEGIN {
unshift @INC, '..';
Expand Down Expand Up @@ -291,6 +292,30 @@ subtest 'set console tty and other args' => sub {
is($console->{args}->{foo}, 'bar');
};

subtest 'check_assert_shutdown' => sub {
# Test cases, when shutdown is finished before timeout is hit
$mod->mock(
read_json => sub {
return {ret => 1};
});
ok(check_shutdown, 'check_shutdown should return "true" if shutdown finished before timeout is hit');
is(assert_shutdown, undef, 'assert_shutdown should return "undef" if shutdown finished before timeout is hit');
$mod->mock(
read_json => sub {
return {ret => -1};
});
ok(check_shutdown, 'check_shutdown should return "true" if backend does not implement is_shutdown');
is(assert_shutdown, undef, 'assert_shutdown should return "undef" if backend does not implement is_shutdown');
# Test cases, when shutdown is not finished if timeout is hit
$mod->mock(
read_json => sub {
return {ret => 0};
});
is(check_shutdown, 0, 'check_shutdown should return "false" if timeout is hit');
throws_ok { assert_shutdown } qr/Machine didn't shut down!/, 'assert_shutdown should throw exception if timeout is hit';

};

done_testing;

# vim: set sw=4 et:
7 changes: 6 additions & 1 deletion t/data/tests/tests/shutdown.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ sub run {
wait_idle 1;
type_string "sudo su\n";
type_string "poweroff\n";
assert_shutdown;
if (get_var('INTEGRATION_TESTS')) {
assert_shutdown(90);
}
else {
assert_shutdown;
}
}

sub test_flags {
Expand Down

0 comments on commit 59789e7

Please sign in to comment.