fix handling of non-existing configuration files and test it
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 15 Aug 2009 13:47:37 +0000 (13:47 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 15 Aug 2009 13:47:37 +0000 (13:47 +0000)
lib/PXElator/client.pm
lib/PXElator/t/client.t

index e07004e..8950cb1 100644 (file)
@@ -11,6 +11,8 @@ use Carp qw/confess/;
 use server;
 use format;
 
+our $debug = $server::debug;
+
 sub mkbasedir {
        my $path = shift;
        $path =~ s{(^.*)/[^/]+$}{$1};
@@ -60,7 +62,7 @@ sub conf {
        } elsif ( -f $path ) {
                $value = read_file $path;
        } else {
-               confess "conf $name";
+               warn "# $name missing $path\n" if $debug;
        }
        return $value;
 }
index f40dea2..6ef054d 100755 (executable)
@@ -4,7 +4,7 @@ use warnings;
 use strict;
 use autodie;
 
-use Test::More tests => 13;
+use Test::More tests => 14;
 use Data::Dump qw/dump/;
 use English;
 
@@ -21,6 +21,8 @@ cmp_ok( client::conf( $host => 'test' ), 'eq', 'default', 'default' );
 ok( client::conf( $host => 'test' => 'value' ), 'conf set' );
 cmp_ok( client::conf( $host => 'test' ), 'eq', 'value', 'value' );
 
+ok( ! client::conf( $host => 'non-existing' ), 'conf non-existing' );
+
 ok( my $ip = client::next_ip( $mac ), 'next_ip' );
 diag $ip;