diff options
author | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-05-26 00:26:09 +0200 |
---|---|---|
committer | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-05-26 00:26:09 +0200 |
commit | 3204f1b97fb828a7db0b133ca54cd74ea699cb62 (patch) | |
tree | 271df1b01cdc7102535cb6967308b195ee395078 | |
parent | ae19b6fd513b9caa7fd12740588035d5223d6eea (diff) | |
download | sbotools2-3204f1b97fb828a7db0b133ca54cd74ea699cb62.tar.xz |
22-race.t: add test for exit branch in read_config
-rwxr-xr-x | t/22-race.t | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/t/22-race.t b/t/22-race.t index 07b9b74..7fbe081 100755 --- a/t/22-race.t +++ b/t/22-race.t @@ -10,7 +10,7 @@ use SBO::Lib qw/ open_fh /; use Capture::Tiny qw/ capture_merged /; use File::Temp 'tempdir'; -plan tests => 1; +plan tests => 2; sub emulate_race { my ($file, $caller) = @_; @@ -31,3 +31,18 @@ sub emulate_race { my ($fh, $exit) = open_fh $file, '<'; is ($exit, 6, 'open_fh returned exit value 6'); } + +# 2: emulate race in open_fh called by read_config +{ + my $conf_file = "/etc/sbotools/sbotools.conf"; + system('mkdir', '-p', '/etc/sbotools'); + system('mv', $conf_file, "$conf_file.bak"); + system('touch', $conf_file); + + emulate_race($conf_file, 'open_fh'); + my $out = capture_merged { SBO::Lib::read_config(); }; + + is ($out, "Unable to open $conf_file.\n", 'read_config output correct'); + + system('mv', "$conf_file.bak", $conf_file) if -e "$conf_file.bak"; +} |