--- lib/PXElator/t/client.t 2009/08/11 15:55:26 200 +++ lib/PXElator/t/client.t 2009/09/29 19:28:24 443 @@ -4,30 +4,52 @@ use strict; use autodie; -use Test::More tests => 9; +use Test::More tests => 22; 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 = 'DE:AD:00:00:BE:EF'; + +my $dir = "$server::base_dir/conf"; +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' ); -diag $ip; +ok( client::conf( $host => 'dir/test' => 'in_dir' ), 'conf test/dir' ); +cmp_ok( client::conf( $host => 'dir/test' ), 'eq', 'in_dir', 'value' ); + +ok( ! client::conf( $host => 'non-existing' ), 'conf non-existing' ); -diag "cleanup"; -ok( unlink($test_path), "unlink $test_path" ); -$test_path =~ s{/[^/]+$}{}; -ok( rmdir($test_path), "rmdir $test_path" ); +ok( client::remove( $host ), "remove $host" ); -ok( my $ip = client::ip_from_mac( 'AC:DE:48:00:00:00' ), 'ip_from_mac' ); +ok( my $ip = client::next_ip( $mac ), 'next_ip' ); diag $ip; -ok( my $mac = client::mac_from_ip( $ip ), 'mac_from_ip' ); -diag $mac; +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 $mac_from_ip = client::mac_from_ip( $ip ), 'mac_from_ip' ); +diag $mac_from_ip; +cmp_ok( $mac_from_ip, 'eq', $mac ); + +ok( my $conf = client::all_conf( $ip ), 'all_conf' ); +diag dump $conf; + +ok( my @ips = client::all_ips(), 'all_ips' ); +diag dump @ips; + +ok( my $new_ip = client::change_ip( $ip, $host ), 'change_ip' ); +ok( ! client::change_ip( $new_ip, $new_ip ), 'change_ip without change' ); +ok( my $old_ip = client::change_ip( $new_ip, $ip ), 'change_ip back' ); +cmp_ok( $old_ip, 'eq', $ip, 'ip back' ); + +ok( client::arp_mac_dev(), 'arp_mac_dev' ); + +ok( client::remove( $ip ), "remove $ip" );