From c869532d063368ad0fe015eab7603c38e62c03c3 Mon Sep 17 00:00:00 2001 From: Andreas Guldstrand Date: Wed, 31 Aug 2016 00:27:49 +0200 Subject: 30-race-sboconfig.t: add race test for sboconfig --- t/30-race-sboconfig.t | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 t/30-race-sboconfig.t (limited to 't') diff --git a/t/30-race-sboconfig.t b/t/30-race-sboconfig.t new file mode 100755 index 0000000..8b245e2 --- /dev/null +++ b/t/30-race-sboconfig.t @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use Test::Exit; +use FindBin '$RealBin'; +use lib $RealBin; +use Test::Sbotools 'load'; +use Capture::Tiny qw/ capture_merged /; +use File::Temp 'tempdir'; +use Cwd; + +plan tests => 2; + +# 1-2: sbocheck race test... +{ + load('sboconfig'); + + my $file = "/etc/sbotools/sbotools.conf"; + mkdir "/etc/sbotools"; + rename $file, "$file.bak"; + + no warnings 'redefine', 'once'; + local *main::open_fh = sub { return "Unable to open $file.\n", 6; }; + + my $exit; + my $out = capture_merged { $exit = exit_code { main::config_write(1,2); }; }; + + like ($out, qr/\QUnable to open $file./, "sboconfig's config_write() gave correct output"); + is ($exit, 6, "sboconfig's config_write() exited with 6"); + + rename "$file.bak", $file; +} -- cgit v1.2.3