App-ipchgmon

 view release on metacpan or  search on metacpan

t/20-file.t  view on Meta::CPAN

my $invoke = "$^X $RealBin/../bin/$NAME";

# Integration test to ensure a file is created when ipchgmon
# is used from the command line.

# If the directory is not writable, the tests cannot pass,
# so ignore them
plan skip_all => 'Unable to write files' unless -w $RealBin;

my $fqname = $RealBin . '/test.txt';
file_not_exists_ok($fqname, 'File should not exist yet');

my $rtn = qx($invoke --file $fqname --server example.com 2>&1);
file_exists_ok($fqname, 'File should be created if it doesn\'t exist ...');
file_not_empty_ok($fqname, '... and should contain something.');

unlink $fqname or warn "Unable to delete $fqname at end of tests.";

done_testing;

t/22-new-ip.t  view on Meta::CPAN

    # If the directory is not writable, these tests cannot pass,
    # so ignore them
    skip "Unable to write to $RealBin" unless -w $RealBin;
    my $fqname = $RealBin . '/test.txt';
    # Pass the file name as though it were a command line parameter
    $App::ipchgmon::opt_file = $fqname;
    # Pass IPv4 and IPv6 addresses through new_ip
    App::ipchgmon::new_ip('123.123.123.123');
    App::ipchgmon::new_ip('A::1');
    file_exists_ok($fqname, 'New file should be created ...');
    file_not_empty_ok($fqname, '... and should contain something.');

    # Read the entire file. No need for File::Slurp for something so basic
    my $tmpsep = $/;
    open my $fh, '<', $fqname;
    undef $/; # No line separator
    my $contents = <$fh>;
    close $fh;
    $/ = $tmpsep; # Tidy up!
    like $contents, qr(123\.123\.123\.123), 'IPv4 address saved correctly';
    like $contents, qr(A::1),               'IPv6 address saved correctly';



( run in 0.301 second using v1.01-cache-2.11-cpan-4d4bc49f3ae )