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