initial import of DBIx-Class-InflateColumn-IP 0.02000 from CPAN
[dbsrgits/DBIx-Class-InflateColumn-IP.git] / t / 01-ip.t
1 #!perl -T
2 use lib qw(t/lib);
3 use DBICTest;
4 use Test::More tests => 10;
5 use NetAddr::IP;
6
7 my $schema = DBICTest->init_schema();
8
9 my $host_rs = $schema->resultset('Host');
10
11 my $localhost = $host_rs->find('localhost');
12
13 isa_ok($localhost->address, 'NetAddr::IP', 'numeric address inflated to right class');
14 is($localhost->address, '127.0.0.1/32', 'numeric address correctly inflated');
15
16 TODO: {
17     local $TODO = "DBIx::Class doesn't support find by object yet";
18
19     $localhost = $host_rs->find(NetAddr::IP->new('127.0.0.1'), { key => 'address' });
20
21     ok($localhost, 'find by object returned a row');
22 }
23
24 SKIP: {
25     skip 'no object to check' => 1 unless $localhost;
26
27     is($localhost->hostname, 'localhost', 'find by object returned the right row');
28 }
29
30 my $ip = NetAddr::IP->new('192.168.0.1');
31 my $host = $host_rs->create({ hostname => 'foo', address => $ip });
32
33 isa_ok($host, 'DBICTest::Schema::Host', 'create with object');
34 is($host->get_column('address'), $ip->numeric, 'numeric address correctly deflated');
35
36 my $net_rs = $schema->resultset('Network');
37
38 my $localnet = $net_rs->find('localnet');
39
40 isa_ok($localnet->address, 'NetAddr::IP', 'CIDR address inflated to right class');
41 is($localnet->address, '127.0.0.0/8', 'CIDR address correctly inflated');
42
43 my $net_ip = NetAddr::IP->new('192.168.0.42/24');
44 my $net = $net_rs->create({ netname => 'foo', address => $net_ip });
45
46 isa_ok($net, 'DBICTest::Schema::Network', 'create with object');
47 is($net->get_column('address'), '192.168.0.42/24', 'CIDR address correctly deflated');