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 Jul 21, 2018
1 parent f4ab0e6 commit 0f4e3d6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
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:

0 comments on commit 0f4e3d6

Please sign in to comment.