sbotools2

Maintenance fork of the original sbotools version 2
Log | Files | Refs | README

commit ac39479af1cbfa50ef54850cbfc8e4171703d7bf
parent d2136f1f38da8496be8bb205859a1d93d98bf9ad
Author: Andreas Guldstrand <andreas.guldstrand@gmail.com>
Date:   Mon, 29 Aug 2016 19:58:44 +0200

22-race.t: rewrite race test for read_config

Diffstat:
Mt/22-race.t | 22+++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/t/22-race.t b/t/22-race.t @@ -11,7 +11,7 @@ use Capture::Tiny qw/ capture_merged /; use File::Temp 'tempdir'; use Cwd; -plan tests => 7; +plan tests => 8; sub emulate_race { my ($file, $caller) = @_; @@ -100,3 +100,23 @@ GIT system('rm', '-rf', $repo); system('mv', "$repo.bak", $repo); } + +# 8: emulate race in read_config +{ + my $conf_file = "/etc/sbotools/sbotools.conf"; + + mkdir "/etc/sbotools"; + rename $conf_file, "$conf_file.bak"; + system touch => $conf_file; + + no warnings 'redefine'; + + local *SBO::Lib::Util::open_read = sub { return undef, 1 }; + + my $out = capture_merged { SBO::Lib::Util::read_config(); }; + + is ($out, "Unable to open $conf_file.\n", "read_config() output correct"); + + unlink $conf_file; + rename "$conf_file.bak", $conf_file; +}