diff options
author | Guillaume Rousse <guillomovitch@mandriva.org> | 2010-01-25 20:33:08 +0000 |
---|---|---|
committer | Guillaume Rousse <guillomovitch@mandriva.org> | 2010-01-25 20:33:08 +0000 |
commit | 62dd233fb558c3f651c4b73ba69c30e00f23eb2c (patch) | |
tree | 548acc6cd32de524af857c9c6d4843f9fdd1d188 /t | |
parent | 0e4dfcf5d8df4346e0932f50a4db4f3e0c894a90 (diff) | |
download | rpm-helper-62dd233fb558c3f651c4b73ba69c30e00f23eb2c.tar rpm-helper-62dd233fb558c3f651c4b73ba69c30e00f23eb2c.tar.gz rpm-helper-62dd233fb558c3f651c4b73ba69c30e00f23eb2c.tar.bz2 rpm-helper-62dd233fb558c3f651c4b73ba69c30e00f23eb2c.tar.xz rpm-helper-62dd233fb558c3f651c4b73ba69c30e00f23eb2c.zip |
initial import
Diffstat (limited to 't')
-rwxr-xr-x | t/add-syslog.t | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/t/add-syslog.t b/t/add-syslog.t new file mode 100755 index 0000000..638040e --- /dev/null +++ b/t/add-syslog.t @@ -0,0 +1,108 @@ +#!/usr/bin/perl +# $Id: gprintify 257533 2009-05-23 12:45:15Z guillomovitch $ + +use strict; +use warnings; +use Test::More; +use Digest::MD5; +use FindBin qw/$Bin/; +use File::Temp; +use lib "$Bin/../lib"; + +my @selector_tests = ( + [ [ qw/local1 debug emerg/ ], 'local1.*' , 'debug -> emerg' ], + [ [ qw/local1 info emerg/ ], 'local1.info' , 'info -> emerg' ], + [ [ qw/local1 debug alert/ ], 'local1.=debug;local1.=info;local1.=notice;local1.=warning;local1.=err;local1.=crit;local1.=alert' , 'debug -> alert' ], + [ [ qw/local1 info alert/ ], 'local1.=info;local1.=notice;local1.=warning;local1.=err;local1.=crit;local1.=alert' , 'info -> alert' ], +); + +plan tests => 5 + scalar @selector_tests; + +# test loading +ok(require("add-syslog"), "loading file OK"); + +# test string function +foreach my $test (@selector_tests) { + is(get_selector(@{$test->[0]}), $test->[1], $test->[2]); +} + +# test service configuration file modification +my $file; +$file = setup(<<EOF); +SYSLOGD_OPTIONS= +EOF + +add_new_source('/tmp/log', $file); + +is( + get_syslog_option($file), + '"-a /tmp/log"', + 'new source, without prior option' +); +unlink($file) unless $ENV{TEST_DEBUG}; + +$file = setup(<<EOF); +SYSLOGD_OPTIONS=-x +EOF + +add_new_source('/tmp/log', $file); + +is( + get_syslog_option($file), + '"-x -a /tmp/log"', + 'new source, with prior unquoted option' +); +unlink($file) unless $ENV{TEST_DEBUG}; + +$file = setup(<<EOF); +SYSLOGD_OPTIONS="-a /dev/log" +EOF + +add_new_source('/tmp/log', $file); + +is( + get_syslog_option($file), + '"-a /dev/log -a /tmp/log"', + 'new source, with prior quoted option' +); +unlink($file) unless $ENV{TEST_DEBUG}; + +$file = setup(<<EOF); +SYSLOGD_OPTIONS="-a /tmp/log" +EOF + +add_new_source('/tmp/log', $file); + +is( + get_syslog_option($file), + '"-a /tmp/log"', + 'new source, already defined' +); +unlink($file) unless $ENV{TEST_DEBUG}; + +sub setup { + my ($content) = @_; + + my $out = File::Temp->new(UNLINK => 0); + print $out $content; + close $out; + + return $out->filename(); +} + +sub get_syslog_option { + my ($file) = @_; + + my $options; + open(my $in, '<', $file) or die "can't read $file: $!"; + while (my $line = <$in>) { + chomp $line; + next unless $line =~ /^SYSLOGD_OPTIONS=(.+)/; + $options = $1; + last; + } + close($in); + + return $options; +} + |