4 |
use strict; |
use strict; |
5 |
use autodie; |
use autodie; |
6 |
|
|
7 |
use Test::More tests => 9; |
use Test::More tests => 13; |
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
|
use English; |
10 |
|
|
11 |
use_ok 'client'; |
use_ok 'client'; |
12 |
|
|
13 |
my $host = '127.0.0.1'; |
my $host = '127.0.0.1'; |
14 |
my $test_path = "$server::base_dir/conf/$server::ip/ip/$host/test"; |
my $mac = 'dead00beef'; |
15 |
unlink $test_path if -e $test_path; |
|
16 |
|
my $dir = "$server::base_dir/conf/$server::ip"; |
17 |
|
system "sudo chown $UID $dir/ip $dir/mac"; |
18 |
|
|
19 |
ok( client::conf( $host => 'test', default => 'default' ), 'conf default' ); |
ok( client::conf( $host => 'test', default => 'default' ), 'conf default' ); |
20 |
cmp_ok( client::conf( $host => 'test' ), 'eq', 'default', 'default' ); |
cmp_ok( client::conf( $host => 'test' ), 'eq', 'default', 'default' ); |
21 |
ok( client::conf( $host => 'test' => 'value' ), 'conf set' ); |
ok( client::conf( $host => 'test' => 'value' ), 'conf set' ); |
22 |
cmp_ok( client::conf( $host => 'test' ), 'eq', 'value', 'value' ); |
cmp_ok( client::conf( $host => 'test' ), 'eq', 'value', 'value' ); |
23 |
|
|
24 |
ok( my $ip = client::next_ip(), 'next_ip' ); |
ok( my $ip = client::next_ip( $mac ), 'next_ip' ); |
25 |
diag $ip; |
diag $ip; |
26 |
|
|
27 |
diag "cleanup"; |
ok( my $ip_from_mac = client::ip_from_mac( $mac ), 'ip_from_mac' ); |
28 |
ok( unlink($test_path), "unlink $test_path" ); |
diag $ip_from_mac; |
29 |
$test_path =~ s{/[^/]+$}{}; |
cmp_ok( $ip_from_mac, 'eq', $ip ); |
30 |
ok( rmdir($test_path), "rmdir $test_path" ); |
|
31 |
|
ok( my $mac_from_ip = client::mac_from_ip( $ip ), 'mac_from_ip' ); |
32 |
|
diag $mac_from_ip; |
33 |
|
cmp_ok( $mac_from_ip, 'eq', $mac ); |
34 |
|
|
35 |
ok( my $ip = client::ip_from_mac( 'AC:DE:48:00:00:00' ), 'ip_from_mac' ); |
diag "cleanup"; |
36 |
diag $ip; |
ok( unlink( $_ ), "unlink $_" ) foreach ( glob("$dir/ip/$host/*"), "$dir/mac/$mac" ); |
37 |
|
ok( rmdir "$dir/ip/$host", 'rmdir' ); |