return $value;
}
-sub mac {
- my $ip = shift;
- my $mac = client::conf( $ip, 'mac' ) || return '';
- format::mac( $ip, @_ );
-}
-
sub next_ip($) {
my $mac = shift;
mkdir ip_path($ip);
- symlink ip_path($ip), mac_path($mac);
+ my $mac_path = mac_path($mac);
+ unlink $mac_path if -e $mac_path; # XXX audit?
+ symlink ip_path($ip), $mac_path;
write_file ip_path($ip,'mac'), $mac;
return $ip;
use strict;
use autodie;
-use Test::More tests => 9;
+use Test::More tests => 13;
use Data::Dump qw/dump/;
+use English;
use_ok 'client';
my $host = '127.0.0.1';
-my $test_path = "$server::base_dir/conf/$server::ip/ip/$host/test";
-unlink $test_path if -e $test_path;
+my $mac = 'dead00beef';
+
+my $dir = "$server::base_dir/conf/$server::ip";
+system "sudo chown $UID $dir/ip $dir/mac";
ok( client::conf( $host => 'test', default => 'default' ), 'conf default' );
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( my $ip = client::next_ip(), 'next_ip' );
+ok( my $ip = client::next_ip( $mac ), 'next_ip' );
diag $ip;
-diag "cleanup";
-ok( unlink($test_path), "unlink $test_path" );
-$test_path =~ s{/[^/]+$}{};
-ok( rmdir($test_path), "rmdir $test_path" );
+ok( my $ip_from_mac = client::ip_from_mac( $mac ), 'ip_from_mac' );
+diag $ip_from_mac;
+cmp_ok( $ip_from_mac, 'eq', $ip );
-ok( my $ip = client::ip_from_mac( 'AC:DE:48:00:00:00' ), 'ip_from_mac' );
-diag $ip;
+ok( my $mac_from_ip = client::mac_from_ip( $ip ), 'mac_from_ip' );
+diag $mac_from_ip;
+cmp_ok( $mac_from_ip, 'eq', $mac );
-ok( my $mac = client::mac_from_ip( $ip ), 'mac_from_ip' );
-diag $mac;
+diag "cleanup";
+ok( unlink( $_ ), "unlink $_" ) foreach ( glob("$dir/ip/$host/*"), "$dir/mac/$mac" );
+ok( rmdir "$dir/ip/$host", 'rmdir' );