diff options
author | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-08-29 19:58:44 +0200 |
---|---|---|
committer | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-08-29 19:58:44 +0200 |
commit | ac39479af1cbfa50ef54850cbfc8e4171703d7bf (patch) | |
tree | 22828b2b8bd64d20a0b44bcd52d4050caff1d2c4 /t/22-race.t | |
parent | d2136f1f38da8496be8bb205859a1d93d98bf9ad (diff) | |
download | sbotools2-ac39479af1cbfa50ef54850cbfc8e4171703d7bf.tar.xz |
22-race.t: rewrite race test for read_config
Diffstat (limited to 't/22-race.t')
-rwxr-xr-x | t/22-race.t | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/t/22-race.t b/t/22-race.t index 7de17fd..335ef7c 100755 --- 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; +} |