1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
use strict;
use warnings;
use Test::Fatal;
use Test::More;
use File::Temp qw( tempdir );
use MaxMind::DB::Writer::Tree;
use Net::Works::Network;
my $tempdir = tempdir( CLEANUP => 1 );
# The underlying bug was happening because calling freeze_tree() would call
# finalize_tree() internally. Then when write_tree() was called, it would
# create IP6->4 alias nodes in the tree, but because the tree though it was
# finalized, these new nodes would never get numbered.
{
my $tree = MaxMind::DB::Writer::Tree->new(
ip_version => 6,
record_size => 24,
database_type => 'Test',
languages => ['en'],
description => {
en => 'Test Database',
},
# This bug only manifests when this is true
alias_ipv6_to_ipv4 => 1,
root_data_type => 'utf8_string',
map_key_type_callback => sub { },
);
$tree->insert_network(
Net::Works::Network->new_from_string( string => '::1.64.22.0/120', ),
'foo',
);
$tree->freeze_tree("$tempdir/frozen");
my $output;
open my $fh, '>:raw', \$output or die $!;
is(
exception { $tree->write_tree($fh) },
undef,
'no exception writing tree where an alias overwrote an existing record'
);
close $fh or die $!;
}
done_testing();
__DATA__
|