Subject: | "Helpful" DNS servers break t/head_ok.t (with patch) |
DNS servers that return their own advertising host for an unknown host
break t/head_ok.t. I just discovered Qwest doing this to me.
I see there is a check, but the check isn't working. I think the
problem is that a full URL is being passed to gethostbyname(), it will
always fail. It should be just the domain name. Also its an obviously
invalid domain as it contains a trailing dot. Finally, the domain
tested at the top isn't the domain tested at the bottom.
I removed the unnecessary BEGIN blocks and constant, it made working
with the code complicated.
If necessary, I can turn DNS breaking back on to verify.
Subject: | 0001-Fix-test-so-it-actually-checks-for-a-non-existent-do.patch |
From 243346a68e46fea6d0507829343496588ca8f6cb Mon Sep 17 00:00:00 2001
From: Michael G. Schwern <schwern@pobox.com>
Date: Wed, 28 Jul 2010 13:26:08 -0700
Subject: [PATCH] Fix test so it actually checks for a non-existent domain, not a URL.
And use that verified not to exist domain.
Remove complicating BEGIN blocks and constants.
---
t/head_ok.t | 21 ++++++++-------------
1 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/t/head_ok.t b/t/head_ok.t
index c123e70..69bf433 100644
--- a/t/head_ok.t
+++ b/t/head_ok.t
@@ -5,18 +5,13 @@ use warnings;
use Test::More;
use Test::Builder::Tester;
-use constant NONEXISTENT => 'http://blahblablah.xx-nonexistent.';
-BEGIN {
- if ( gethostbyname( NONEXISTENT ) ) {
- plan skip_all => 'Found an A record for the non-existent domain';
- }
-}
+my $NONEXISTENT = 'blahblablah.xx-nonexistent.foo';
-BEGIN {
- plan tests => 11;
- use_ok( 'Test::WWW::Mechanize' );
-}
+plan skip_all => "Found an A record for the non-existent domain $NONEXISTENT"
+ if gethostbyname $NONEXISTENT;
+plan tests => 11;
+require_ok( 'Test::WWW::Mechanize' );
use lib 't';
use TestServer;
@@ -47,14 +42,14 @@ GOOD_HEAD: { # Stop giggling, you!
}
BAD_HEAD: {
- my $badurl = 'http://wango.nonexistent.xx-only-testing/';
+ my $badurl = 'http://$NONEXISTENT/';
$mech->head($badurl);
- ok(!$mech->success, q{sanity check: we can't load NONEXISTENT.html} );
+ ok(!$mech->success, q{sanity check: we can't load $badurl} );
test_out( 'not ok 1 - Try to HEAD bad URL' );
test_fail( +3 );
test_diag( '500' );
- test_diag( q{Can't connect to wango.nonexistent.xx-only-testing:80 (Bad hostname 'wango.nonexistent.xx-only-testing')} );
+ test_diag( q{Can't connect to $NONEXISTENT:80 (Bad hostname '$NONEXISTENT')} );
my $ok = $mech->head_ok( $badurl, 'Try to HEAD bad URL' );
test_test( 'Fails to HEAD nonexistent URI and reports failure' );
--
1.7.2