sbotools2

Maintenance fork of the original sbotools version 2
git clone git://git.server.ky/slackcoder/sbotools2
Log | Files | Refs | README

30-race-sboconfig.t (775B)


      1 #!/usr/bin/env perl
      2 
      3 use strict;
      4 use warnings;
      5 use Test::More;
      6 use Test::Exit;
      7 use FindBin '$RealBin';
      8 use lib $RealBin;
      9 use Test::Sbotools 'load';
     10 use Capture::Tiny qw/ capture_merged /;
     11 use File::Temp 'tempdir';
     12 use Cwd;
     13 
     14 plan tests => 2;
     15 
     16 # 1-2: sbocheck race test...
     17 {
     18 	load('sboconfig');
     19 
     20   my $file = "/etc/sbotools/sbotools.conf";
     21   mkdir "/etc/sbotools";
     22   rename $file, "$file.bak";
     23 
     24   no warnings 'redefine', 'once';
     25   local *main::open_fh = sub { return "Unable to open $file.\n", 6; };
     26 
     27 	my $exit;
     28 	my $out = capture_merged { $exit = exit_code { main::config_write(1,2); }; };
     29 
     30 	like ($out, qr/\QUnable to open $file./, "sboconfig's config_write() gave correct output");
     31 	is ($exit, 6, "sboconfig's config_write() exited with 6");
     32 
     33   rename "$file.bak", $file;
     34 }